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 Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; 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 axios from '~/lib/utils/axios_utils';
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue'; import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
import eventHub from '~/vue_merge_request_widget/event_hub'; import eventHub from '~/vue_merge_request_widget/event_hub';
...@@ -25,6 +26,7 @@ describe('mrWidgetOptions', () => { ...@@ -25,6 +26,7 @@ describe('mrWidgetOptions', () => {
const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch'; const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch';
beforeEach(() => { beforeEach(() => {
jasmine.clock().install();
// Prevent component mounting // Prevent component mounting
delete mrWidgetOptions.el; delete mrWidgetOptions.el;
...@@ -36,18 +38,34 @@ describe('mrWidgetOptions', () => { ...@@ -36,18 +38,34 @@ describe('mrWidgetOptions', () => {
mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]); mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]);
MrWidgetOptions = Vue.extend(mrWidgetOptions); MrWidgetOptions = Vue.extend(mrWidgetOptions);
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); jasmine.clock().uninstall();
mock.restore(); mock.restore();
vm.$destroy();
vm = null;
gl.mrWidgetData = {}; gl.mrWidgetData = {};
gon.features = {}; gon.features = {};
}); });
const createComponent = () => {
if (vm) {
vm.$destroy();
}
vm = mountComponent(MrWidgetOptions, {
mrData: { ...mockData },
});
};
describe('default', () => {
beforeEach(() => {
createComponent();
});
describe('data', () => { describe('data', () => {
it('should instantiate Store and Service', () => { it('should instantiate Store and Service', () => {
expect(vm.mr).toBeDefined(); expect(vm.mr).toBeDefined();
...@@ -94,61 +112,6 @@ describe('mrWidgetOptions', () => { ...@@ -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', () => { describe('shouldRenderRelatedLinks', () => {
it('should return false for the initial data', () => { it('should return false for the initial data', () => {
expect(vm.shouldRenderRelatedLinks).toBeFalsy(); expect(vm.shouldRenderRelatedLinks).toBeFalsy();
...@@ -295,7 +258,7 @@ describe('mrWidgetOptions', () => { ...@@ -295,7 +258,7 @@ describe('mrWidgetOptions', () => {
describe('methods', () => { describe('methods', () => {
describe('checkStatus', () => { 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.service, 'checkStatus').and.returnValue(returnPromise(mockData));
spyOn(vm.mr, 'setData'); spyOn(vm.mr, 'setData');
spyOn(vm, 'handleNotification'); spyOn(vm, 'handleNotification');
...@@ -307,20 +270,18 @@ describe('mrWidgetOptions', () => { ...@@ -307,20 +270,18 @@ describe('mrWidgetOptions', () => {
vm.checkStatus(cb); vm.checkStatus(cb);
setTimeout(() => { return vm.$nextTick().then(() => {
expect(vm.service.checkStatus).toHaveBeenCalled(); expect(vm.service.checkStatus).toHaveBeenCalled();
expect(vm.mr.setData).toHaveBeenCalled(); expect(vm.mr.setData).toHaveBeenCalled();
expect(vm.handleNotification).toHaveBeenCalledWith(mockData); expect(vm.handleNotification).toHaveBeenCalledWith(mockData);
expect(isCbExecuted).toBeTruthy(); expect(isCbExecuted).toBeTruthy();
done(); });
}, 333);
}); });
}); });
describe('initPolling', () => { describe('initPolling', () => {
it('should call SmartInterval', () => { it('should call SmartInterval', () => {
spyOn(vm, 'checkStatus').and.returnValue(Promise.resolve()); spyOn(vm, 'checkStatus').and.returnValue(Promise.resolve());
jasmine.clock().install();
vm.initPolling(); vm.initPolling();
expect(vm.checkStatus).not.toHaveBeenCalled(); expect(vm.checkStatus).not.toHaveBeenCalled();
...@@ -329,8 +290,6 @@ describe('mrWidgetOptions', () => { ...@@ -329,8 +290,6 @@ describe('mrWidgetOptions', () => {
expect(vm.pollingInterval).toBeDefined(); expect(vm.pollingInterval).toBeDefined();
expect(vm.checkStatus).toHaveBeenCalled(); expect(vm.checkStatus).toHaveBeenCalled();
jasmine.clock().uninstall();
}); });
}); });
...@@ -345,38 +304,38 @@ describe('mrWidgetOptions', () => { ...@@ -345,38 +304,38 @@ describe('mrWidgetOptions', () => {
}); });
describe('fetchDeployments', () => { describe('fetchDeployments', () => {
it('should fetch deployments', done => { it('should fetch deployments', () => {
spyOn(vm.service, 'fetchDeployments').and.returnValue( spyOn(vm.service, 'fetchDeployments').and.returnValue(
returnPromise([{ id: 1, status: SUCCESS }]), returnPromise([{ id: 1, status: SUCCESS }]),
); );
vm.fetchPreMergeDeployments(); vm.fetchPreMergeDeployments();
setTimeout(() => { return vm.$nextTick().then(() => {
expect(vm.service.fetchDeployments).toHaveBeenCalled(); expect(vm.service.fetchDeployments).toHaveBeenCalled();
expect(vm.mr.deployments.length).toEqual(1); expect(vm.mr.deployments.length).toEqual(1);
expect(vm.mr.deployments[0].id).toBe(1); expect(vm.mr.deployments[0].id).toBe(1);
done();
}); });
}); });
}); });
describe('fetchActionsContent', () => { describe('fetchActionsContent', () => {
it('should fetch content of Cherry Pick and Revert modals', done => { it('should fetch content of Cherry Pick and Revert modals', () => {
spyOn(vm.service, 'fetchMergeActionsContent').and.returnValue(returnPromise('hello world')); spyOn(vm.service, 'fetchMergeActionsContent').and.returnValue(
returnPromise('hello world'),
);
vm.fetchActionsContent(); vm.fetchActionsContent();
setTimeout(() => { return vm.$nextTick().then(() => {
expect(vm.service.fetchMergeActionsContent).toHaveBeenCalled(); expect(vm.service.fetchMergeActionsContent).toHaveBeenCalled();
expect(document.body.textContent).toContain('hello world'); expect(document.body.textContent).toContain('hello world');
done(); });
}, 333);
}); });
}); });
describe('bindEventHubListeners', () => { describe('bindEventHubListeners', () => {
it('should bind eventHub listeners', done => { it('should bind eventHub listeners', () => {
spyOn(vm, 'checkStatus').and.returnValue(() => {}); spyOn(vm, 'checkStatus').and.returnValue(() => {});
spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData)); spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData));
spyOn(vm, 'fetchActionsContent'); spyOn(vm, 'fetchActionsContent');
...@@ -385,7 +344,7 @@ describe('mrWidgetOptions', () => { ...@@ -385,7 +344,7 @@ describe('mrWidgetOptions', () => {
spyOn(vm, 'stopPolling'); spyOn(vm, 'stopPolling');
spyOn(eventHub, '$on').and.callThrough(); spyOn(eventHub, '$on').and.callThrough();
setTimeout(() => { return waitForPromises().then(() => {
eventHub.$emit('SetBranchRemoveFlag', ['flag']); eventHub.$emit('SetBranchRemoveFlag', ['flag']);
expect(vm.mr.isRemovingSourceBranch).toEqual('flag'); expect(vm.mr.isRemovingSourceBranch).toEqual('flag');
...@@ -428,8 +387,6 @@ describe('mrWidgetOptions', () => { ...@@ -428,8 +387,6 @@ describe('mrWidgetOptions', () => {
listenersWithServiceRequest.FetchActionsContent(); listenersWithServiceRequest.FetchActionsContent();
expect(vm.fetchActionsContent).toHaveBeenCalled(); expect(vm.fetchActionsContent).toHaveBeenCalled();
done();
}); });
}); });
}); });
...@@ -521,31 +478,25 @@ describe('mrWidgetOptions', () => { ...@@ -521,31 +478,25 @@ describe('mrWidgetOptions', () => {
}); });
describe('resumePolling', () => { describe('resumePolling', () => {
it('should call stopTimer on pollingInterval', done => { it('should call stopTimer on pollingInterval', () =>
setTimeout(() => { waitForPromises().then(() => {
spyOn(vm.pollingInterval, 'resume'); spyOn(vm.pollingInterval, 'resume');
vm.resumePolling(); vm.resumePolling();
expect(vm.pollingInterval.resume).toHaveBeenCalled(); expect(vm.pollingInterval.resume).toHaveBeenCalled();
}));
done();
});
});
}); });
describe('stopPolling', () => { describe('stopPolling', () => {
it('should call stopTimer on pollingInterval', done => { it('should call stopTimer on pollingInterval', () =>
setTimeout(() => { waitForPromises().then(() => {
spyOn(vm.pollingInterval, 'stopTimer'); spyOn(vm.pollingInterval, 'stopTimer');
vm.stopPolling(); vm.stopPolling();
expect(vm.pollingInterval.stopTimer).toHaveBeenCalled(); expect(vm.pollingInterval.stopTimer).toHaveBeenCalled();
}));
done();
});
});
}); });
}); });
...@@ -799,7 +750,8 @@ describe('mrWidgetOptions', () => { ...@@ -799,7 +750,8 @@ describe('mrWidgetOptions', () => {
changes: [ changes: [
{ {
path: 'index.html', 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', path: 'imgs/gallery.html',
...@@ -852,4 +804,39 @@ describe('mrWidgetOptions', () => { ...@@ -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