debian-mirror-gitlab/spec/frontend/vue_mr_widget/mr_widget_options_spec.js

894 lines
30 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2020-04-08 14:13:33 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-01-03 14:25:43 +05:30
import Api from '~/api';
2020-04-08 14:13:33 +05:30
import axios from '~/lib/utils/axios_utils';
2021-03-08 18:12:59 +05:30
import MrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
2020-04-08 14:13:33 +05:30
import eventHub from '~/vue_merge_request_widget/event_hub';
import notify from '~/lib/utils/notify';
import SmartInterval from '~/smart_interval';
2021-03-08 18:12:59 +05:30
import { setFaviconOverlay } from '~/lib/utils/favicon';
2020-04-08 14:13:33 +05:30
import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
import mockData from './mock_data';
import { faviconDataUrl, overlayDataUrl } from '../lib/utils/mock_data';
import { SUCCESS } from '~/vue_merge_request_widget/components/deployment/constants';
jest.mock('~/smart_interval');
2021-03-08 18:12:59 +05:30
jest.mock('~/lib/utils/favicon');
const returnPromise = (data) =>
new Promise((resolve) => {
2020-04-08 14:13:33 +05:30
resolve({
data,
});
});
2021-03-08 18:12:59 +05:30
describe('MrWidgetOptions', () => {
let wrapper;
2020-04-08 14:13:33 +05:30
let mock;
const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch';
beforeEach(() => {
gl.mrWidgetData = { ...mockData };
gon.features = { asyncMrWidget: true };
mock = new MockAdapter(axios);
mock.onGet(mockData.merge_request_widget_path).reply(() => [200, { ...mockData }]);
mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]);
});
afterEach(() => {
mock.restore();
2021-03-08 18:12:59 +05:30
wrapper.destroy();
wrapper = null;
2020-04-08 14:13:33 +05:30
gl.mrWidgetData = {};
gon.features = {};
});
2021-01-03 14:25:43 +05:30
const createComponent = (mrData = mockData) => {
2021-03-08 18:12:59 +05:30
if (wrapper) {
wrapper.destroy();
2020-04-08 14:13:33 +05:30
}
2021-03-08 18:12:59 +05:30
wrapper = mount(MrWidgetOptions, {
propsData: {
mrData: { ...mrData },
},
2020-04-08 14:13:33 +05:30
});
return axios.waitForAll();
};
2021-03-08 18:12:59 +05:30
const findSuggestPipeline = () => wrapper.find('[data-testid="mr-suggest-pipeline"]');
const findSuggestPipelineButton = () => findSuggestPipeline().find('button');
const findSecurityMrWidget = () => wrapper.find('[data-testid="security-mr-widget"]');
2020-10-24 23:57:45 +05:30
2020-04-08 14:13:33 +05:30
describe('default', () => {
beforeEach(() => {
return createComponent();
});
describe('data', () => {
it('should instantiate Store and Service', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.mr).toBeDefined();
expect(wrapper.vm.service).toBeDefined();
2020-04-08 14:13:33 +05:30
});
});
describe('computed', () => {
describe('componentName', () => {
it('should return merged component', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.componentName).toEqual('mr-widget-merged');
2020-04-08 14:13:33 +05:30
});
it('should return conflicts component', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.state = 'conflicts';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.componentName).toEqual('mr-widget-conflicts');
2020-04-08 14:13:33 +05:30
});
});
describe('shouldRenderMergeHelp', () => {
it('should return false for the initial merged state', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderMergeHelp).toBeFalsy();
2020-04-08 14:13:33 +05:30
});
it('should return true for a state which requires help widget', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.state = 'conflicts';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderMergeHelp).toBeTruthy();
2020-04-08 14:13:33 +05:30
});
});
describe('shouldRenderPipelines', () => {
it('should return true when hasCI is true', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.hasCI = true;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderPipelines).toBeTruthy();
2020-04-08 14:13:33 +05:30
});
it('should return false when hasCI is false', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.hasCI = false;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderPipelines).toBeFalsy();
2020-04-08 14:13:33 +05:30
});
});
describe('shouldRenderRelatedLinks', () => {
it('should return false for the initial data', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderRelatedLinks).toBeFalsy();
2020-04-08 14:13:33 +05:30
});
it('should return true if there is relatedLinks in MR', () => {
2021-03-08 18:12:59 +05:30
Vue.set(wrapper.vm.mr, 'relatedLinks', {});
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderRelatedLinks).toBeTruthy();
2020-04-08 14:13:33 +05:30
});
});
describe('shouldRenderSourceBranchRemovalStatus', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.state = 'readyToMerge';
2020-04-08 14:13:33 +05:30
});
it('should return true when cannot remove source branch and branch will be removed', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(true);
2020-04-08 14:13:33 +05:30
});
it('should return false when can remove source branch and branch will be removed', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.canRemoveSourceBranch = true;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
2020-04-08 14:13:33 +05:30
});
it('should return false when cannot remove source branch and branch will not be removed', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = false;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
2020-04-08 14:13:33 +05:30
});
it('should return false when in merged state', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'merged';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
2020-04-08 14:13:33 +05:30
});
it('should return false when in nothing to merge state', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'nothingToMerge';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
2020-04-08 14:13:33 +05:30
});
});
describe('shouldRenderCollaborationStatus', () => {
describe('when collaboration is allowed', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.allowCollaboration = true;
2020-04-08 14:13:33 +05:30
});
describe('when merge request is opened', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.isOpen = true;
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should render collaboration status', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.text()).toContain(COLLABORATION_MESSAGE);
2020-04-08 14:13:33 +05:30
});
});
describe('when merge request is not opened', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.isOpen = false;
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should not render collaboration status', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.text()).not.toContain(COLLABORATION_MESSAGE);
2020-04-08 14:13:33 +05:30
});
});
});
describe('when collaboration is not allowed', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.allowCollaboration = false;
2020-04-08 14:13:33 +05:30
});
describe('when merge request is opened', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.isOpen = true;
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should not render collaboration status', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.text()).not.toContain(COLLABORATION_MESSAGE);
2020-04-08 14:13:33 +05:30
});
});
});
});
describe('showMergePipelineForkWarning', () => {
describe('when the source project and target project are the same', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 1);
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should be false', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(false);
2020-04-08 14:13:33 +05:30
});
});
describe('when merge pipelines are not enabled', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', false);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should be false', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(false);
2020-04-08 14:13:33 +05:30
});
});
describe('when merge pipelines are enabled _and_ the source project and target project are different', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('should be true', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(true);
2020-04-08 14:13:33 +05:30
});
});
});
2021-01-29 00:20:46 +05:30
describe('formattedHumanAccess', () => {
it('when user is a tool admin but not a member of project', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.humanAccess = null;
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.formattedHumanAccess).toEqual('');
2021-01-29 00:20:46 +05:30
});
it('when user a member of the project', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.humanAccess = 'Owner';
2021-01-29 00:20:46 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.formattedHumanAccess).toEqual('owner');
2021-01-29 00:20:46 +05:30
});
});
2020-04-08 14:13:33 +05:30
});
describe('methods', () => {
describe('checkStatus', () => {
let cb;
let isCbExecuted;
beforeEach(() => {
2021-03-08 18:12:59 +05:30
jest.spyOn(wrapper.vm.service, 'checkStatus').mockReturnValue(returnPromise(mockData));
jest.spyOn(wrapper.vm.mr, 'setData').mockImplementation(() => {});
jest.spyOn(wrapper.vm, 'handleNotification').mockImplementation(() => {});
2020-04-08 14:13:33 +05:30
isCbExecuted = false;
cb = () => {
isCbExecuted = true;
};
});
it('should tell service to check status if document is visible', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.checkStatus(cb);
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
return nextTick().then(() => {
expect(wrapper.vm.service.checkStatus).toHaveBeenCalled();
expect(wrapper.vm.mr.setData).toHaveBeenCalled();
expect(wrapper.vm.handleNotification).toHaveBeenCalledWith(mockData);
2020-04-08 14:13:33 +05:30
expect(isCbExecuted).toBeTruthy();
});
});
});
describe('initPolling', () => {
it('should call SmartInterval', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.initPolling();
2020-04-08 14:13:33 +05:30
expect(SmartInterval).toHaveBeenCalledWith(
expect.objectContaining({
2021-03-08 18:12:59 +05:30
callback: wrapper.vm.checkStatus,
2020-04-08 14:13:33 +05:30
}),
);
});
});
describe('initDeploymentsPolling', () => {
it('should call SmartInterval', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.initDeploymentsPolling();
2020-04-08 14:13:33 +05:30
expect(SmartInterval).toHaveBeenCalledWith(
expect.objectContaining({
2021-03-08 18:12:59 +05:30
callback: wrapper.vm.fetchPreMergeDeployments,
2020-04-08 14:13:33 +05:30
}),
);
});
});
describe('fetchDeployments', () => {
it('should fetch deployments', () => {
jest
2021-03-08 18:12:59 +05:30
.spyOn(wrapper.vm.service, 'fetchDeployments')
2020-04-08 14:13:33 +05:30
.mockReturnValue(returnPromise([{ id: 1, status: SUCCESS }]));
2021-03-08 18:12:59 +05:30
wrapper.vm.fetchPreMergeDeployments();
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
return nextTick().then(() => {
expect(wrapper.vm.service.fetchDeployments).toHaveBeenCalled();
expect(wrapper.vm.mr.deployments.length).toEqual(1);
expect(wrapper.vm.mr.deployments[0].id).toBe(1);
2020-04-08 14:13:33 +05:30
});
});
});
describe('fetchActionsContent', () => {
it('should fetch content of Cherry Pick and Revert modals', () => {
jest
2021-03-08 18:12:59 +05:30
.spyOn(wrapper.vm.service, 'fetchMergeActionsContent')
2020-04-08 14:13:33 +05:30
.mockReturnValue(returnPromise('hello world'));
2021-03-08 18:12:59 +05:30
wrapper.vm.fetchActionsContent();
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
return nextTick().then(() => {
expect(wrapper.vm.service.fetchMergeActionsContent).toHaveBeenCalled();
2020-04-08 14:13:33 +05:30
expect(document.body.textContent).toContain('hello world');
});
});
});
describe('bindEventHubListeners', () => {
it.each`
event | method | methodArgs
2021-03-08 18:12:59 +05:30
${'MRWidgetUpdateRequested'} | ${'checkStatus'} | ${(x) => [x]}
${'MRWidgetRebaseSuccess'} | ${'checkStatus'} | ${(x) => [x, true]}
2020-04-08 14:13:33 +05:30
${'FetchActionsContent'} | ${'fetchActionsContent'} | ${() => []}
${'EnablePolling'} | ${'resumePolling'} | ${() => []}
${'DisablePolling'} | ${'stopPolling'} | ${() => []}
`('should bind to $event', ({ event, method, methodArgs }) => {
2021-03-08 18:12:59 +05:30
jest.spyOn(wrapper.vm, method).mockImplementation();
2020-04-08 14:13:33 +05:30
const eventArg = {};
eventHub.$emit(event, eventArg);
2021-03-08 18:12:59 +05:30
expect(wrapper.vm[method]).toHaveBeenCalledWith(...methodArgs(eventArg));
2020-04-08 14:13:33 +05:30
});
it('should bind to SetBranchRemoveFlag', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.mr.isRemovingSourceBranch).toBe(false);
2020-04-08 14:13:33 +05:30
eventHub.$emit('SetBranchRemoveFlag', [true]);
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.mr.isRemovingSourceBranch).toBe(true);
2020-04-08 14:13:33 +05:30
});
it('should bind to FailedToMerge', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.state = '';
wrapper.vm.mr.mergeError = '';
2020-04-08 14:13:33 +05:30
const mergeError = 'Something bad happened!';
eventHub.$emit('FailedToMerge', mergeError);
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.mr.state).toBe('failedToMerge');
expect(wrapper.vm.mr.mergeError).toBe(mergeError);
2020-04-08 14:13:33 +05:30
});
it('should bind to UpdateWidgetData', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(wrapper.vm.mr, 'setData').mockImplementation();
2020-04-08 14:13:33 +05:30
const data = { ...mockData };
eventHub.$emit('UpdateWidgetData', data);
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.mr.setData).toHaveBeenCalledWith(data);
2020-04-08 14:13:33 +05:30
});
});
describe('setFavicon', () => {
let faviconElement;
beforeEach(() => {
const favicon = document.createElement('link');
favicon.setAttribute('id', 'favicon');
favicon.setAttribute('data-original-href', faviconDataUrl);
document.body.appendChild(favicon);
faviconElement = document.getElementById('favicon');
});
afterEach(() => {
document.body.removeChild(document.getElementById('favicon'));
});
2021-03-08 18:12:59 +05:30
it('should call setFavicon method', async () => {
wrapper.vm.mr.ciStatusFaviconPath = overlayDataUrl;
await wrapper.vm.setFaviconHelper();
expect(setFaviconOverlay).toHaveBeenCalledWith(overlayDataUrl);
2020-04-08 14:13:33 +05:30
});
2021-03-08 18:12:59 +05:30
it('should not call setFavicon when there is no ciStatusFaviconPath', (done) => {
wrapper.vm.mr.ciStatusFaviconPath = null;
wrapper.vm
.setFaviconHelper()
2020-04-08 14:13:33 +05:30
.then(() => {
expect(faviconElement.getAttribute('href')).toEqual(null);
done();
})
.catch(done.fail);
});
});
describe('handleNotification', () => {
const data = {
ci_status: 'running',
title: 'title',
pipeline: { details: { status: { label: 'running-label' } } },
};
beforeEach(() => {
jest.spyOn(notify, 'notifyMe').mockImplementation(() => {});
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.ciStatus = 'failed';
wrapper.vm.mr.gitlabLogo = 'logo.png';
2020-04-08 14:13:33 +05:30
});
it('should call notifyMe', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.handleNotification(data);
2020-04-08 14:13:33 +05:30
expect(notify.notifyMe).toHaveBeenCalledWith(
'Pipeline running-label',
'Pipeline running-label for "title"',
'logo.png',
);
});
it('should not call notifyMe if the status has not changed', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.ciStatus = data.ci_status;
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
wrapper.vm.handleNotification(data);
2020-04-08 14:13:33 +05:30
expect(notify.notifyMe).not.toHaveBeenCalled();
});
it('should not notify if no pipeline provided', () => {
2021-03-08 18:12:59 +05:30
wrapper.vm.handleNotification({
2020-04-08 14:13:33 +05:30
...data,
pipeline: undefined,
});
expect(notify.notifyMe).not.toHaveBeenCalled();
});
});
describe('resumePolling', () => {
it('should call stopTimer on pollingInterval', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(wrapper.vm.pollingInterval, 'resume').mockImplementation(() => {});
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
wrapper.vm.resumePolling();
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.pollingInterval.resume).toHaveBeenCalled();
2020-04-08 14:13:33 +05:30
});
});
describe('stopPolling', () => {
it('should call stopTimer on pollingInterval', () => {
2021-03-08 18:12:59 +05:30
jest.spyOn(wrapper.vm.pollingInterval, 'stopTimer').mockImplementation(() => {});
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
wrapper.vm.stopPolling();
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.pollingInterval.stopTimer).toHaveBeenCalled();
2020-04-08 14:13:33 +05:30
});
});
});
describe('rendering relatedLinks', () => {
2021-03-08 18:12:59 +05:30
beforeEach(() => {
createComponent({
...mockData,
issues_links: {
closing: `
<a class="close-related-link" href="#">
Close
</a>
`,
},
});
return nextTick();
2020-04-08 14:13:33 +05:30
});
it('renders if there are relatedLinks', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.close-related-link').exists()).toBe(true);
2020-04-08 14:13:33 +05:30
});
2021-03-08 18:12:59 +05:30
it('does not render if state is nothingToMerge', (done) => {
wrapper.vm.mr.state = stateKey.nothingToMerge;
nextTick(() => {
expect(wrapper.find('.close-related-link').exists()).toBe(false);
2020-04-08 14:13:33 +05:30
done();
});
});
});
describe('rendering source branch removal status', () => {
2021-03-08 18:12:59 +05:30
it('renders when user cannot remove branch and branch should be removed', (done) => {
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'readyToMerge';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
nextTick(() => {
const tooltip = wrapper.find('[data-testid="question-o-icon"]');
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.text()).toContain('Deletes source branch');
expect(tooltip.attributes('title')).toBe(
2020-04-08 14:13:33 +05:30
'A user with write access to the source branch selected this option',
);
done();
});
});
2021-03-08 18:12:59 +05:30
it('does not render in merged state', (done) => {
wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'merged';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
nextTick(() => {
expect(wrapper.text()).toContain('The source branch has been deleted');
expect(wrapper.text()).not.toContain('Deletes source branch');
2020-04-08 14:13:33 +05:30
done();
});
});
});
describe('rendering deployments', () => {
const changes = [
{
path: 'index.html',
external_url: 'http://root-master-patch-91341.volatile-watch.surge.sh/index.html',
},
{
path: 'imgs/gallery.html',
external_url: 'http://root-master-patch-91341.volatile-watch.surge.sh/imgs/gallery.html',
},
{
path: 'about/',
external_url: 'http://root-master-patch-91341.volatile-watch.surge.sh/about/',
},
];
const deploymentMockData = {
id: 15,
name: 'review/diplo',
url: '/root/acets-review-apps/environments/15',
stop_url: '/root/acets-review-apps/environments/15/stop',
metrics_url: '/root/acets-review-apps/environments/15/deployments/1/metrics',
metrics_monitoring_url: '/root/acets-review-apps/environments/15/metrics',
external_url: 'http://diplo.',
external_url_formatted: 'diplo.',
deployed_at: '2017-03-22T22:44:42.258Z',
deployed_at_formatted: 'Mar 22, 2017 10:44pm',
changes,
status: SUCCESS,
};
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.deployments.push(
2020-04-08 14:13:33 +05:30
{
...deploymentMockData,
},
{
...deploymentMockData,
id: deploymentMockData.id + 1,
},
);
2021-03-08 18:12:59 +05:30
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('renders multiple deployments', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.findAll('.deploy-heading').length).toBe(2);
2020-04-08 14:13:33 +05:30
});
it('renders dropdpown with multiple file changes', () => {
expect(
2021-03-08 18:12:59 +05:30
wrapper.find('.js-mr-wigdet-deployment-dropdown').findAll('.js-filtered-dropdown-result')
.length,
2020-04-08 14:13:33 +05:30
).toEqual(changes.length);
});
});
2020-07-28 23:09:34 +05:30
describe('code quality widget', () => {
it('renders the component', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-codequality-widget').exists()).toBe(true);
2020-07-28 23:09:34 +05:30
});
});
2020-04-08 14:13:33 +05:30
describe('pipeline for target branch after merge', () => {
describe('with information for target branch pipeline', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.state = 'merged';
wrapper.vm.mr.mergePipeline = {
2020-04-08 14:13:33 +05:30
id: 127,
user: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url: null,
web_url: 'http://localhost:3000/root',
status_tooltip_html: null,
path: '/root',
},
active: true,
coverage: null,
source: 'push',
created_at: '2018-10-22T11:41:35.186Z',
updated_at: '2018-10-22T11:41:35.433Z',
path: '/root/ci-web-terminal/pipelines/127',
flags: {
latest: true,
stuck: true,
auto_devops: false,
yaml_errors: false,
retryable: false,
cancelable: true,
failure_reason: false,
},
details: {
status: {
icon: 'status_pending',
text: 'pending',
label: 'pending',
group: 'pending',
tooltip: 'pending',
has_details: true,
details_path: '/root/ci-web-terminal/pipelines/127',
illustration: null,
favicon:
'/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png',
},
duration: null,
finished_at: null,
stages: [
{
name: 'test',
title: 'test: pending',
status: {
icon: 'status_pending',
text: 'pending',
label: 'pending',
group: 'pending',
tooltip: 'pending',
has_details: true,
details_path: '/root/ci-web-terminal/pipelines/127#test',
illustration: null,
favicon:
'/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png',
},
path: '/root/ci-web-terminal/pipelines/127#test',
dropdown_path: '/root/ci-web-terminal/pipelines/127/stage.json?stage=test',
},
],
artifacts: [],
manual_actions: [],
scheduled_actions: [],
},
ref: {
name: 'master',
path: '/root/ci-web-terminal/commits/master',
tag: false,
branch: true,
},
commit: {
id: 'aa1939133d373c94879becb79d91828a892ee319',
short_id: 'aa193913',
title: "Merge branch 'master-test' into 'master'",
created_at: '2018-10-22T11:41:33.000Z',
parent_ids: [
'4622f4dd792468993003caf2e3be978798cbe096',
'76598df914cdfe87132d0c3c40f80db9fa9396a4',
],
message:
"Merge branch 'master-test' into 'master'\n\nUpdate .gitlab-ci.yml\n\nSee merge request root/ci-web-terminal!1",
author_name: 'Administrator',
author_email: 'admin@example.com',
authored_date: '2018-10-22T11:41:33.000Z',
committer_name: 'Administrator',
committer_email: 'admin@example.com',
committed_date: '2018-10-22T11:41:33.000Z',
author: {
id: 1,
name: 'Administrator',
username: 'root',
state: 'active',
avatar_url: null,
web_url: 'http://localhost:3000/root',
status_tooltip_html: null,
path: '/root',
},
author_gravatar_url: null,
commit_url:
'http://localhost:3000/root/ci-web-terminal/commit/aa1939133d373c94879becb79d91828a892ee319',
commit_path: '/root/ci-web-terminal/commit/aa1939133d373c94879becb79d91828a892ee319',
},
cancel_path: '/root/ci-web-terminal/pipelines/127/cancel',
};
2021-03-08 18:12:59 +05:30
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('renders pipeline block', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(true);
2020-04-08 14:13:33 +05:30
});
describe('with post merge deployments', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.postMergeDeployments = [
2020-04-08 14:13:33 +05:30
{
id: 15,
name: 'review/diplo',
url: '/root/acets-review-apps/environments/15',
stop_url: '/root/acets-review-apps/environments/15/stop',
metrics_url: '/root/acets-review-apps/environments/15/deployments/1/metrics',
metrics_monitoring_url: '/root/acets-review-apps/environments/15/metrics',
external_url: 'http://diplo.',
external_url_formatted: 'diplo.',
deployed_at: '2017-03-22T22:44:42.258Z',
deployed_at_formatted: 'Mar 22, 2017 10:44pm',
changes: [
{
path: 'index.html',
external_url:
'http://root-master-patch-91341.volatile-watch.surge.sh/index.html',
},
{
path: 'imgs/gallery.html',
external_url:
'http://root-master-patch-91341.volatile-watch.surge.sh/imgs/gallery.html',
},
{
path: 'about/',
external_url: 'http://root-master-patch-91341.volatile-watch.surge.sh/about/',
},
],
status: 'success',
},
];
2021-03-08 18:12:59 +05:30
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('renders post deployment information', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-post-deployment').exists()).toBe(true);
2020-04-08 14:13:33 +05:30
});
});
});
describe('without information for target branch pipeline', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.state = 'merged';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('does not render pipeline block', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(false);
2020-04-08 14:13:33 +05:30
});
});
describe('when state is not merged', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
wrapper.vm.mr.state = 'archived';
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
nextTick(done);
2020-04-08 14:13:33 +05:30
});
it('does not render pipeline block', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(false);
2020-04-08 14:13:33 +05:30
});
it('does not render post deployment information', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.js-post-deployment').exists()).toBe(false);
2020-04-08 14:13:33 +05:30
});
});
});
2020-10-24 23:57:45 +05:30
it('should not suggest pipelines when feature flag is not present', () => {
2021-03-08 18:12:59 +05:30
expect(findSuggestPipeline().exists()).toBe(false);
2020-04-08 14:13:33 +05:30
});
});
2021-01-03 14:25:43 +05:30
describe('security widget', () => {
describe.each`
context | hasPipeline | reportType | isFlagEnabled | shouldRender
${'security report and flag enabled'} | ${true} | ${'sast'} | ${true} | ${true}
${'security report and flag disabled'} | ${true} | ${'sast'} | ${false} | ${false}
${'no security report and flag enabled'} | ${true} | ${'foo'} | ${true} | ${false}
${'no pipeline and flag enabled'} | ${false} | ${'sast'} | ${true} | ${false}
`('given $context', ({ hasPipeline, reportType, isFlagEnabled, shouldRender }) => {
beforeEach(() => {
gon.features.coreSecurityMrWidget = isFlagEnabled;
if (hasPipeline) {
jest.spyOn(Api, 'pipelineJobs').mockResolvedValue({
data: [{ artifacts: [{ file_type: reportType }] }],
});
}
return createComponent({
...mockData,
...(hasPipeline ? {} : { pipeline: undefined }),
});
});
if (shouldRender) {
it('renders', () => {
2021-03-08 18:12:59 +05:30
expect(findSecurityMrWidget().exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
} else {
it('does not render', () => {
2021-03-08 18:12:59 +05:30
expect(findSecurityMrWidget().exists()).toBe(false);
2021-01-03 14:25:43 +05:30
});
}
});
});
2021-02-22 17:27:13 +05:30
describe('suggestPipeline', () => {
2020-04-08 14:13:33 +05:30
beforeEach(() => {
2020-10-24 23:57:45 +05:30
mock.onAny().reply(200);
2021-01-03 14:25:43 +05:30
});
2020-04-08 14:13:33 +05:30
2021-01-29 00:20:46 +05:30
describe('given feature flag is enabled', () => {
2021-01-03 14:25:43 +05:30
beforeEach(() => {
createComponent();
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
wrapper.vm.mr.hasCI = false;
2021-01-03 14:25:43 +05:30
});
2020-04-08 14:13:33 +05:30
2021-01-03 14:25:43 +05:30
it('should suggest pipelines when none exist', () => {
2021-03-08 18:12:59 +05:30
expect(findSuggestPipeline().exists()).toBe(true);
2021-01-03 14:25:43 +05:30
});
2020-04-08 14:13:33 +05:30
2021-01-03 14:25:43 +05:30
it.each([
{ isDismissedSuggestPipeline: true },
{ mergeRequestAddCiConfigPath: null },
{ hasCI: true },
2021-03-08 18:12:59 +05:30
])('with %s, should not suggest pipeline', async (obj) => {
Object.assign(wrapper.vm.mr, obj);
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
await nextTick();
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
expect(findSuggestPipeline().exists()).toBe(false);
2021-01-03 14:25:43 +05:30
});
it('should allow dismiss of the suggest pipeline message', async () => {
2021-03-08 18:12:59 +05:30
await findSuggestPipelineButton().trigger('click');
2021-01-03 14:25:43 +05:30
2021-03-08 18:12:59 +05:30
expect(findSuggestPipeline().exists()).toBe(false);
2021-01-03 14:25:43 +05:30
});
2020-04-08 14:13:33 +05:30
});
});
});