Commit 46861810 authored by Phil Hughes's avatar Phil Hughes

Merge branch '207376-clean-mr-widget-options-spec' into 'master'

Clean mr_widget_options_spec from zombies

See merge request gitlab-org/gitlab!26059
parents c118dd50 a1c68dae
import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import waitForPromises from 'spec/helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
......@@ -25,6 +26,7 @@ describe('mrWidgetOptions', () => {
const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch';
beforeEach(() => {
jasmine.clock().install();
// Prevent component mounting
delete mrWidgetOptions.el;
......@@ -36,18 +38,34 @@ describe('mrWidgetOptions', () => {
mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]);
MrWidgetOptions = Vue.extend(mrWidgetOptions);
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
});
afterEach(() => {
vm.$destroy();
jasmine.clock().uninstall();
mock.restore();
vm.$destroy();
vm = null;
gl.mrWidgetData = {};
gon.features = {};
});
const createComponent = () => {
if (vm) {
vm.$destroy();
}
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
};
describe('default', () => {
beforeEach(() => {
createComponent();
});
describe('data', () => {
it('should instantiate Store and Service', () => {
expect(vm.mr).toBeDefined();
......@@ -94,61 +112,6 @@ describe('mrWidgetOptions', () => {
});
});
describe('shouldSuggestPipelines', () => {
describe('given suggestPipeline feature flag is enabled', () => {
beforeEach(() => {
gon.features = { suggestPipeline: true };
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
});
afterEach(() => {
gon.features = {};
});
it('should suggest pipelines when none exist', () => {
vm.mr.mergeRequestAddCiConfigPath = 'some/path';
vm.mr.hasCI = false;
expect(vm.shouldSuggestPipelines).toBeTruthy();
});
it('should not suggest pipelines when they exist', () => {
vm.mr.mergeRequestAddCiConfigPath = null;
vm.mr.hasCI = false;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
it('should not suggest pipelines hasCI is true', () => {
vm.mr.mergeRequestAddCiConfigPath = 'some/path';
vm.mr.hasCI = true;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
});
describe('given suggestPipeline feature flag is not enabled', () => {
beforeEach(() => {
gon.features = { suggestPipeline: false };
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
});
afterEach(() => {
gon.features = {};
});
it('should not suggest pipelines', () => {
vm.mr.mergeRequestAddCiConfigPath = null;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
});
});
describe('shouldRenderRelatedLinks', () => {
it('should return false for the initial data', () => {
expect(vm.shouldRenderRelatedLinks).toBeFalsy();
......@@ -295,7 +258,7 @@ describe('mrWidgetOptions', () => {
describe('methods', () => {
describe('checkStatus', () => {
it('should tell service to check status', done => {
it('should tell service to check status', () => {
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
spyOn(vm.mr, 'setData');
spyOn(vm, 'handleNotification');
......@@ -307,20 +270,18 @@ describe('mrWidgetOptions', () => {
vm.checkStatus(cb);
setTimeout(() => {
return vm.$nextTick().then(() => {
expect(vm.service.checkStatus).toHaveBeenCalled();
expect(vm.mr.setData).toHaveBeenCalled();
expect(vm.handleNotification).toHaveBeenCalledWith(mockData);
expect(isCbExecuted).toBeTruthy();
done();
}, 333);
});
});
});
describe('initPolling', () => {
it('should call SmartInterval', () => {
spyOn(vm, 'checkStatus').and.returnValue(Promise.resolve());
jasmine.clock().install();
vm.initPolling();
expect(vm.checkStatus).not.toHaveBeenCalled();
......@@ -329,8 +290,6 @@ describe('mrWidgetOptions', () => {
expect(vm.pollingInterval).toBeDefined();
expect(vm.checkStatus).toHaveBeenCalled();
jasmine.clock().uninstall();
});
});
......@@ -345,38 +304,38 @@ describe('mrWidgetOptions', () => {
});
describe('fetchDeployments', () => {
it('should fetch deployments', done => {
it('should fetch deployments', () => {
spyOn(vm.service, 'fetchDeployments').and.returnValue(
returnPromise([{ id: 1, status: SUCCESS }]),
);
vm.fetchPreMergeDeployments();
setTimeout(() => {
return vm.$nextTick().then(() => {
expect(vm.service.fetchDeployments).toHaveBeenCalled();
expect(vm.mr.deployments.length).toEqual(1);
expect(vm.mr.deployments[0].id).toBe(1);
done();
});
});
});
describe('fetchActionsContent', () => {
it('should fetch content of Cherry Pick and Revert modals', done => {
spyOn(vm.service, 'fetchMergeActionsContent').and.returnValue(returnPromise('hello world'));
it('should fetch content of Cherry Pick and Revert modals', () => {
spyOn(vm.service, 'fetchMergeActionsContent').and.returnValue(
returnPromise('hello world'),
);
vm.fetchActionsContent();
setTimeout(() => {
return vm.$nextTick().then(() => {
expect(vm.service.fetchMergeActionsContent).toHaveBeenCalled();
expect(document.body.textContent).toContain('hello world');
done();
}, 333);
});
});
});
describe('bindEventHubListeners', () => {
it('should bind eventHub listeners', done => {
it('should bind eventHub listeners', () => {
spyOn(vm, 'checkStatus').and.returnValue(() => {});
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
spyOn(vm, 'fetchActionsContent');
......@@ -385,7 +344,7 @@ describe('mrWidgetOptions', () => {
spyOn(vm, 'stopPolling');
spyOn(eventHub, '$on').and.callThrough();
setTimeout(() => {
return waitForPromises().then(() => {
eventHub.$emit('SetBranchRemoveFlag', ['flag']);
expect(vm.mr.isRemovingSourceBranch).toEqual('flag');
......@@ -428,8 +387,6 @@ describe('mrWidgetOptions', () => {
listenersWithServiceRequest.FetchActionsContent();
expect(vm.fetchActionsContent).toHaveBeenCalled();
done();
});
});
});
......@@ -521,31 +478,25 @@ describe('mrWidgetOptions', () => {
});
describe('resumePolling', () => {
it('should call stopTimer on pollingInterval', done => {
setTimeout(() => {
it('should call stopTimer on pollingInterval', () =>
waitForPromises().then(() => {
spyOn(vm.pollingInterval, 'resume');
vm.resumePolling();
expect(vm.pollingInterval.resume).toHaveBeenCalled();
done();
});
});
}));
});
describe('stopPolling', () => {
it('should call stopTimer on pollingInterval', done => {
setTimeout(() => {
it('should call stopTimer on pollingInterval', () =>
waitForPromises().then(() => {
spyOn(vm.pollingInterval, 'stopTimer');
vm.stopPolling();
expect(vm.pollingInterval.stopTimer).toHaveBeenCalled();
done();
});
});
}));
});
});
......@@ -799,7 +750,8 @@ describe('mrWidgetOptions', () => {
changes: [
{
path: 'index.html',
external_url: 'http://root-master-patch-91341.volatile-watch.surge.sh/index.html',
external_url:
'http://root-master-patch-91341.volatile-watch.surge.sh/index.html',
},
{
path: 'imgs/gallery.html',
......@@ -852,4 +804,39 @@ describe('mrWidgetOptions', () => {
});
});
});
it('should not suggest pipelines', () => {
vm.mr.mergeRequestAddCiConfigPath = null;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
});
describe('given suggestPipeline feature flag is enabled', () => {
beforeEach(() => {
gon.features = { suggestPipeline: true };
createComponent();
});
it('should suggest pipelines when none exist', () => {
vm.mr.mergeRequestAddCiConfigPath = 'some/path';
vm.mr.hasCI = false;
expect(vm.shouldSuggestPipelines).toBeTruthy();
});
it('should not suggest pipelines when they exist', () => {
vm.mr.mergeRequestAddCiConfigPath = null;
vm.mr.hasCI = false;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
it('should not suggest pipelines hasCI is true', () => {
vm.mr.mergeRequestAddCiConfigPath = 'some/path';
vm.mr.hasCI = true;
expect(vm.shouldSuggestPipelines).toBeFalsy();
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment