2021-10-22 12:09:12 +00:00
|
|
|
import { GlBadge, GlLink, GlIcon, GlDropdown } from '@gitlab/ui';
|
2021-01-19 12:10:46 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-02-14 18:09:20 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-01-19 12:10:46 +00:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-01-21 18:09:11 +00:00
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2021-09-29 12:11:22 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-05-13 00:10:23 +00:00
|
|
|
import { securityReportMergeRequestDownloadPathsQueryResponse } from 'jest/vue_shared/security_reports/mock_data';
|
2021-10-26 18:09:19 +00:00
|
|
|
import api from '~/api';
|
2019-12-05 18:07:51 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { setFaviconOverlay } from '~/lib/utils/favicon';
|
2017-05-26 15:47:34 +00:00
|
|
|
import notify from '~/lib/utils/notify';
|
2020-03-02 18:07:42 +00:00
|
|
|
import SmartInterval from '~/smart_interval';
|
2021-09-29 15:11:47 +00:00
|
|
|
import {
|
|
|
|
registerExtension,
|
|
|
|
registeredExtensions,
|
|
|
|
} from '~/vue_merge_request_widget/components/extensions';
|
2019-12-05 12:07:43 +00:00
|
|
|
import { SUCCESS } from '~/vue_merge_request_widget/components/deployment/constants';
|
2021-02-14 18:09:20 +00:00
|
|
|
import eventHub from '~/vue_merge_request_widget/event_hub';
|
|
|
|
import MrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
|
|
|
|
import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
|
2021-08-02 15:08:56 +00:00
|
|
|
import securityReportMergeRequestDownloadPathsQuery from '~/vue_shared/security_reports/graphql/queries/security_report_merge_request_download_paths.query.graphql';
|
2021-02-01 15:08:56 +00:00
|
|
|
import { faviconDataUrl, overlayDataUrl } from '../lib/utils/mock_data';
|
|
|
|
import mockData from './mock_data';
|
2021-09-29 12:11:22 +00:00
|
|
|
import testExtension from './test_extension';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-10-26 18:09:19 +00:00
|
|
|
jest.mock('~/api.js');
|
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
jest.mock('~/smart_interval');
|
|
|
|
|
2021-01-08 09:10:50 +00:00
|
|
|
jest.mock('~/lib/utils/favicon');
|
|
|
|
|
2021-01-21 18:09:11 +00:00
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
describe('MrWidgetOptions', () => {
|
|
|
|
let wrapper;
|
2019-12-05 18:07:51 +00:00
|
|
|
let mock;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-05-27 12:10:56 +00:00
|
|
|
const COLLABORATION_MESSAGE = 'Members who can merge are allowed to add commits';
|
2018-12-27 13:58:40 +00:00
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
beforeEach(() => {
|
2019-12-05 18:07:51 +00:00
|
|
|
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 }]);
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 13:49:05 +00:00
|
|
|
afterEach(() => {
|
2019-12-05 18:07:51 +00:00
|
|
|
mock.restore();
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2020-02-27 21:09:17 +00:00
|
|
|
|
2019-12-05 18:07:51 +00:00
|
|
|
gl.mrWidgetData = {};
|
|
|
|
gon.features = {};
|
2018-09-25 13:49:05 +00:00
|
|
|
});
|
|
|
|
|
2021-01-21 18:09:11 +00:00
|
|
|
const createComponent = (mrData = mockData, options = {}) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
2020-02-27 21:09:17 +00:00
|
|
|
}
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper = mount(MrWidgetOptions, {
|
|
|
|
propsData: {
|
|
|
|
mrData: { ...mrData },
|
|
|
|
},
|
2021-01-21 18:09:11 +00:00
|
|
|
...options,
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2020-03-02 18:07:42 +00:00
|
|
|
|
|
|
|
return axios.waitForAll();
|
2020-02-27 21:09:17 +00:00
|
|
|
};
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
const findSuggestPipeline = () => wrapper.find('[data-testid="mr-suggest-pipeline"]');
|
|
|
|
const findSuggestPipelineButton = () => findSuggestPipeline().find('button');
|
|
|
|
const findSecurityMrWidget = () => wrapper.find('[data-testid="security-mr-widget"]');
|
2020-08-04 09:09:45 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('default', () => {
|
|
|
|
beforeEach(() => {
|
2021-02-01 15:08:56 +00:00
|
|
|
jest.spyOn(document, 'dispatchEvent');
|
2020-03-02 18:07:42 +00:00
|
|
|
return createComponent();
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('data', () => {
|
|
|
|
it('should instantiate Store and Service', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.mr).toBeDefined();
|
|
|
|
expect(wrapper.vm.service).toBeDefined();
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('computed', () => {
|
|
|
|
describe('componentName', () => {
|
2021-08-17 18:10:35 +00:00
|
|
|
it.each`
|
|
|
|
state | componentName
|
|
|
|
${'merged'} | ${'mr-widget-merged'}
|
|
|
|
${'conflicts'} | ${'mr-widget-conflicts'}
|
|
|
|
${'shaMismatch'} | ${'sha-mismatch'}
|
|
|
|
`('should translate $state into $componentName', ({ state, componentName }) => {
|
|
|
|
wrapper.vm.mr.state = state;
|
|
|
|
|
|
|
|
expect(wrapper.vm.componentName).toEqual(componentName);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('shouldRenderPipelines', () => {
|
|
|
|
it('should return true when hasCI is true', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.hasCI = true;
|
2020-02-17 15:09:01 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderPipelines).toBeTruthy();
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return false when hasCI is false', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.hasCI = false;
|
2020-02-17 15:09:01 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderPipelines).toBeFalsy();
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2020-02-17 15:09:01 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('shouldRenderRelatedLinks', () => {
|
|
|
|
it('should return false for the initial data', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderRelatedLinks).toBeFalsy();
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return true if there is relatedLinks in MR', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
Vue.set(wrapper.vm.mr, 'relatedLinks', {});
|
2020-02-17 15:09:01 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderRelatedLinks).toBeTruthy();
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('shouldRenderSourceBranchRemovalStatus', () => {
|
2020-02-17 15:09:01 +00:00
|
|
|
beforeEach(() => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = 'readyToMerge';
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return true when cannot remove source branch and branch will be removed', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
2020-02-27 21:09:17 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(true);
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return false when can remove source branch and branch will be removed', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = true;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
2020-02-17 15:09:01 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
|
2020-02-17 15:09:01 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return false when cannot remove source branch and branch will not be removed', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = false;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return false when in merged state', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
|
|
|
wrapper.vm.mr.state = 'merged';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should return false when in nothing to merge state', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
|
|
|
wrapper.vm.mr.state = 'nothingToMerge';
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.shouldRenderSourceBranchRemovalStatus).toEqual(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-08 13:33:59 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('shouldRenderCollaborationStatus', () => {
|
|
|
|
describe('when collaboration is allowed', () => {
|
|
|
|
beforeEach(() => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.allowCollaboration = true;
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when merge request is opened', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.isOpen = true;
|
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should render collaboration status', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.text()).toContain(COLLABORATION_MESSAGE);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when merge request is not opened', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.isOpen = false;
|
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should not render collaboration status', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.text()).not.toContain(COLLABORATION_MESSAGE);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when collaboration is not allowed', () => {
|
|
|
|
beforeEach(() => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.allowCollaboration = false;
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when merge request is opened', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.isOpen = true;
|
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-12-25 20:41:32 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should not render collaboration status', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.text()).not.toContain(COLLABORATION_MESSAGE);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-12-25 20:41:32 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('showMergePipelineForkWarning', () => {
|
|
|
|
describe('when the source project and target project are the same', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
|
|
|
|
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
|
|
|
|
Vue.set(wrapper.vm.mr, 'targetProjectId', 1);
|
|
|
|
nextTick(done);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should be false', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(false);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when merge pipelines are not enabled', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', false);
|
|
|
|
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
|
|
|
|
Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
|
|
|
|
nextTick(done);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should be false', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(false);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when merge pipelines are enabled _and_ the source project and target project are different', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
|
|
|
|
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
|
|
|
|
Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
|
|
|
|
nextTick(done);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should be true', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.showMergePipelineForkWarning).toEqual(true);
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-12-09 03:09:24 +00:00
|
|
|
|
|
|
|
describe('formattedHumanAccess', () => {
|
|
|
|
it('when user is a tool admin but not a member of project', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.humanAccess = null;
|
2020-12-09 03:09:24 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.formattedHumanAccess).toEqual('');
|
2020-12-09 03:09:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('when user a member of the project', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.humanAccess = 'Owner';
|
2020-12-09 03:09:24 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.formattedHumanAccess).toEqual('owner');
|
2020-12-09 03:09:24 +00:00
|
|
|
});
|
|
|
|
});
|
2018-12-25 20:41:32 +00:00
|
|
|
});
|
2019-04-15 13:25:48 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('methods', () => {
|
|
|
|
describe('checkStatus', () => {
|
2020-03-10 09:08:10 +00:00
|
|
|
let cb;
|
|
|
|
let isCbExecuted;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-19 18:11:04 +00:00
|
|
|
jest.spyOn(wrapper.vm.service, 'checkStatus').mockResolvedValue({ data: mockData });
|
2021-01-19 12:10:46 +00:00
|
|
|
jest.spyOn(wrapper.vm.mr, 'setData').mockImplementation(() => {});
|
|
|
|
jest.spyOn(wrapper.vm, 'handleNotification').mockImplementation(() => {});
|
2019-04-15 13:25:48 +00:00
|
|
|
|
2020-03-10 09:08:10 +00:00
|
|
|
isCbExecuted = false;
|
|
|
|
cb = () => {
|
2020-02-27 21:09:17 +00:00
|
|
|
isCbExecuted = true;
|
|
|
|
};
|
2020-03-10 09:08:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should tell service to check status if document is visible', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.checkStatus(cb);
|
2019-04-15 13:25:48 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
return nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.service.checkStatus).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.mr.setData).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.handleNotification).toHaveBeenCalledWith(mockData);
|
2020-02-27 21:09:17 +00:00
|
|
|
expect(isCbExecuted).toBeTruthy();
|
|
|
|
});
|
2019-04-15 13:25:48 +00:00
|
|
|
});
|
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('initPolling', () => {
|
|
|
|
it('should call SmartInterval', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.initPolling();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(SmartInterval).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
2021-01-19 12:10:46 +00:00
|
|
|
callback: wrapper.vm.checkStatus,
|
2020-03-02 18:07:42 +00:00
|
|
|
}),
|
|
|
|
);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('initDeploymentsPolling', () => {
|
|
|
|
it('should call SmartInterval', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.initDeploymentsPolling();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(SmartInterval).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
2021-01-19 12:10:46 +00:00
|
|
|
callback: wrapper.vm.fetchPreMergeDeployments,
|
2020-03-02 18:07:42 +00:00
|
|
|
}),
|
|
|
|
);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('fetchDeployments', () => {
|
|
|
|
it('should fetch deployments', () => {
|
2020-03-02 18:07:42 +00:00
|
|
|
jest
|
2021-01-19 12:10:46 +00:00
|
|
|
.spyOn(wrapper.vm.service, 'fetchDeployments')
|
2021-01-19 18:11:04 +00:00
|
|
|
.mockResolvedValue({ data: [{ id: 1, status: SUCCESS }] });
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.fetchPreMergeDeployments();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
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-02-27 21:09:17 +00:00
|
|
|
});
|
2018-03-09 16:35:31 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('fetchActionsContent', () => {
|
|
|
|
it('should fetch content of Cherry Pick and Revert modals', () => {
|
2020-03-02 18:07:42 +00:00
|
|
|
jest
|
2021-01-19 12:10:46 +00:00
|
|
|
.spyOn(wrapper.vm.service, 'fetchMergeActionsContent')
|
2021-01-19 18:11:04 +00:00
|
|
|
.mockResolvedValue({ data: 'hello world' });
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.fetchActionsContent();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
return nextTick().then(() => {
|
|
|
|
expect(wrapper.vm.service.fetchMergeActionsContent).toHaveBeenCalled();
|
2020-02-27 21:09:17 +00:00
|
|
|
expect(document.body.textContent).toContain('hello world');
|
2021-02-01 15:08:56 +00:00
|
|
|
expect(document.dispatchEvent).toHaveBeenCalledWith(
|
|
|
|
new CustomEvent('merged:UpdateActions'),
|
|
|
|
);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('bindEventHubListeners', () => {
|
2020-03-02 18:07:42 +00:00
|
|
|
it.each`
|
|
|
|
event | method | methodArgs
|
2020-12-23 21:10:24 +00:00
|
|
|
${'MRWidgetUpdateRequested'} | ${'checkStatus'} | ${(x) => [x]}
|
|
|
|
${'MRWidgetRebaseSuccess'} | ${'checkStatus'} | ${(x) => [x, true]}
|
2020-03-02 18:07:42 +00:00
|
|
|
${'FetchActionsContent'} | ${'fetchActionsContent'} | ${() => []}
|
|
|
|
${'EnablePolling'} | ${'resumePolling'} | ${() => []}
|
|
|
|
${'DisablePolling'} | ${'stopPolling'} | ${() => []}
|
|
|
|
`('should bind to $event', ({ event, method, methodArgs }) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
jest.spyOn(wrapper.vm, method).mockImplementation();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
const eventArg = {};
|
|
|
|
eventHub.$emit(event, eventArg);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm[method]).toHaveBeenCalledWith(...methodArgs(eventArg));
|
2020-03-02 18:07:42 +00:00
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
it('should bind to SetBranchRemoveFlag', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.mr.isRemovingSourceBranch).toBe(false);
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
eventHub.$emit('SetBranchRemoveFlag', [true]);
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.mr.isRemovingSourceBranch).toBe(true);
|
2020-03-02 18:07:42 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
it('should bind to FailedToMerge', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = '';
|
|
|
|
wrapper.vm.mr.mergeError = '';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
const mergeError = 'Something bad happened!';
|
|
|
|
eventHub.$emit('FailedToMerge', mergeError);
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.mr.state).toBe('failedToMerge');
|
|
|
|
expect(wrapper.vm.mr.mergeError).toBe(mergeError);
|
2020-03-02 18:07:42 +00:00
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
it('should bind to UpdateWidgetData', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
jest.spyOn(wrapper.vm.mr, 'setData').mockImplementation();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
const data = { ...mockData };
|
|
|
|
eventHub.$emit('UpdateWidgetData', data);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.mr.setData).toHaveBeenCalledWith(data);
|
2019-12-05 18:07:51 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('setFavicon', () => {
|
|
|
|
let faviconElement;
|
2017-09-06 16:14:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
const favicon = document.createElement('link');
|
|
|
|
favicon.setAttribute('id', 'favicon');
|
|
|
|
favicon.setAttribute('data-original-href', faviconDataUrl);
|
|
|
|
document.body.appendChild(favicon);
|
2017-09-06 16:14:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
faviconElement = document.getElementById('favicon');
|
|
|
|
});
|
2017-09-06 16:14:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
afterEach(() => {
|
|
|
|
document.body.removeChild(document.getElementById('favicon'));
|
|
|
|
});
|
2017-09-06 16:14:34 +00:00
|
|
|
|
2021-01-08 09:10:50 +00:00
|
|
|
it('should call setFavicon method', async () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.ciStatusFaviconPath = overlayDataUrl;
|
2021-01-08 09:10:50 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
await wrapper.vm.setFaviconHelper();
|
2021-01-08 09:10:50 +00:00
|
|
|
|
|
|
|
expect(setFaviconOverlay).toHaveBeenCalledWith(overlayDataUrl);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it('should not call setFavicon when there is no ciStatusFaviconPath', (done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.ciStatusFaviconPath = null;
|
|
|
|
wrapper.vm
|
|
|
|
.setFaviconHelper()
|
2020-02-27 21:09:17 +00:00
|
|
|
.then(() => {
|
|
|
|
expect(faviconElement.getAttribute('href')).toEqual(null);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('handleNotification', () => {
|
|
|
|
const data = {
|
|
|
|
ci_status: 'running',
|
|
|
|
title: 'title',
|
|
|
|
pipeline: { details: { status: { label: 'running-label' } } },
|
|
|
|
};
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
beforeEach(() => {
|
2020-03-02 18:07:42 +00:00
|
|
|
jest.spyOn(notify, 'notifyMe').mockImplementation(() => {});
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.ciStatus = 'failed';
|
|
|
|
wrapper.vm.mr.gitlabLogo = 'logo.png';
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should call notifyMe', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.handleNotification(data);
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
expect(notify.notifyMe).toHaveBeenCalledWith(
|
|
|
|
'Pipeline running-label',
|
|
|
|
'Pipeline running-label for "title"',
|
|
|
|
'logo.png',
|
|
|
|
);
|
|
|
|
});
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should not call notifyMe if the status has not changed', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.ciStatus = data.ci_status;
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.handleNotification(data);
|
2018-02-12 07:20:52 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
expect(notify.notifyMe).not.toHaveBeenCalled();
|
2018-02-12 07:20:52 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('should not notify if no pipeline provided', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.handleNotification({
|
2020-02-27 21:09:17 +00:00
|
|
|
...data,
|
|
|
|
pipeline: undefined,
|
|
|
|
});
|
2017-05-26 15:47:34 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
expect(notify.notifyMe).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2019-12-05 18:07:51 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('resumePolling', () => {
|
2020-03-02 18:07:42 +00:00
|
|
|
it('should call stopTimer on pollingInterval', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
jest.spyOn(wrapper.vm.pollingInterval, 'resume').mockImplementation(() => {});
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.resumePolling();
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.pollingInterval.resume).toHaveBeenCalled();
|
2020-03-02 18:07:42 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('stopPolling', () => {
|
2020-03-02 18:07:42 +00:00
|
|
|
it('should call stopTimer on pollingInterval', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
jest.spyOn(wrapper.vm.pollingInterval, 'stopTimer').mockImplementation(() => {});
|
2019-12-05 18:07:51 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.stopPolling();
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.vm.pollingInterval.stopTimer).toHaveBeenCalled();
|
2020-03-02 18:07:42 +00:00
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('rendering relatedLinks', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
...mockData,
|
|
|
|
issues_links: {
|
|
|
|
closing: `
|
|
|
|
<a class="close-related-link" href="#">
|
|
|
|
Close
|
|
|
|
</a>
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return nextTick();
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-12-19 17:50:38 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('renders if there are relatedLinks', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.close-related-link').exists()).toBe(true);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2017-12-19 17:50:38 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it('does not render if state is nothingToMerge', (done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = stateKey.nothingToMerge;
|
|
|
|
nextTick(() => {
|
|
|
|
expect(wrapper.find('.close-related-link').exists()).toBe(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
done();
|
|
|
|
});
|
2017-12-19 17:50:38 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('rendering source branch removal status', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
it('renders when user cannot remove branch and branch should be removed', (done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
|
|
|
wrapper.vm.mr.state = 'readyToMerge';
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(() => {
|
|
|
|
const tooltip = wrapper.find('[data-testid="question-o-icon"]');
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2021-06-09 15:10:05 +00:00
|
|
|
expect(wrapper.text()).toContain('The source branch will be deleted');
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(tooltip.attributes('title')).toBe(
|
2020-02-27 21:09:17 +00:00
|
|
|
'A user with write access to the source branch selected this option',
|
|
|
|
);
|
2018-03-08 13:33:59 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
done();
|
|
|
|
});
|
2018-03-08 13:33:59 +00:00
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it('does not render in merged state', (done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.canRemoveSourceBranch = false;
|
|
|
|
wrapper.vm.mr.shouldRemoveSourceBranch = true;
|
|
|
|
wrapper.vm.mr.state = 'merged';
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('The source branch has been deleted');
|
2021-06-09 15:10:05 +00:00
|
|
|
expect(wrapper.text()).not.toContain('The source branch will be deleted');
|
2018-03-12 12:08:47 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
done();
|
|
|
|
});
|
2018-03-12 12:08:47 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-09 16:35:31 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('rendering deployments', () => {
|
|
|
|
const changes = [
|
|
|
|
{
|
|
|
|
path: 'index.html',
|
2021-04-22 12:09:49 +00:00
|
|
|
external_url: 'http://root-main-patch-91341.volatile-watch.surge.sh/index.html',
|
2020-02-27 21:09:17 +00:00
|
|
|
},
|
2018-10-22 08:31:24 +00:00
|
|
|
{
|
2020-02-27 21:09:17 +00:00
|
|
|
path: 'imgs/gallery.html',
|
2021-04-22 12:09:49 +00:00
|
|
|
external_url: 'http://root-main-patch-91341.volatile-watch.surge.sh/imgs/gallery.html',
|
2018-10-22 08:31:24 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-27 21:09:17 +00:00
|
|
|
path: 'about/',
|
2021-04-22 12:09:49 +00:00
|
|
|
external_url: 'http://root-main-patch-91341.volatile-watch.surge.sh/about/',
|
2018-10-22 08:31:24 +00:00
|
|
|
},
|
2020-02-27 21:09:17 +00:00
|
|
|
];
|
|
|
|
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,
|
|
|
|
};
|
2018-03-09 16:35:31 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.deployments.push(
|
2020-02-27 21:09:17 +00:00
|
|
|
{
|
|
|
|
...deploymentMockData,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...deploymentMockData,
|
|
|
|
id: deploymentMockData.id + 1,
|
|
|
|
},
|
|
|
|
);
|
2018-03-09 16:35:31 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders multiple deployments', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.findAll('.deploy-heading').length).toBe(2);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-10-22 08:31:24 +00:00
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('renders dropdpown with multiple file changes', () => {
|
|
|
|
expect(
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.find('.js-mr-wigdet-deployment-dropdown').findAll('.js-filtered-dropdown-result')
|
|
|
|
.length,
|
2020-02-27 21:09:17 +00:00
|
|
|
).toEqual(changes.length);
|
|
|
|
});
|
2018-10-22 08:31:24 +00:00
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2020-07-17 03:09:14 +00:00
|
|
|
describe('code quality widget', () => {
|
|
|
|
it('renders the component', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-codequality-widget').exists()).toBe(true);
|
2020-07-17 03:09:14 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('pipeline for target branch after merge', () => {
|
|
|
|
describe('with information for target branch pipeline', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = 'merged';
|
|
|
|
wrapper.vm.mr.mergePipeline = {
|
2020-02-27 21:09:17 +00:00
|
|
|
id: 127,
|
|
|
|
user: {
|
2018-10-29 11:34:41 +00:00
|
|
|
id: 1,
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
state: 'active',
|
|
|
|
avatar_url: null,
|
|
|
|
web_url: 'http://localhost:3000/root',
|
|
|
|
status_tooltip_html: null,
|
|
|
|
path: '/root',
|
|
|
|
},
|
2020-02-27 21:09:17 +00:00
|
|
|
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: {
|
2021-04-22 12:09:49 +00:00
|
|
|
name: 'main',
|
|
|
|
path: '/root/ci-web-terminal/commits/main',
|
2020-02-27 21:09:17 +00:00
|
|
|
tag: false,
|
|
|
|
branch: true,
|
|
|
|
},
|
|
|
|
commit: {
|
|
|
|
id: 'aa1939133d373c94879becb79d91828a892ee319',
|
|
|
|
short_id: 'aa193913',
|
2021-04-22 12:09:49 +00:00
|
|
|
title: "Merge branch 'main-test' into 'main'",
|
2020-02-27 21:09:17 +00:00
|
|
|
created_at: '2018-10-22T11:41:33.000Z',
|
|
|
|
parent_ids: [
|
|
|
|
'4622f4dd792468993003caf2e3be978798cbe096',
|
|
|
|
'76598df914cdfe87132d0c3c40f80db9fa9396a4',
|
|
|
|
],
|
|
|
|
message:
|
2021-04-22 12:09:49 +00:00
|
|
|
"Merge branch 'main-test' into 'main'\n\nUpdate .gitlab-ci.yml\n\nSee merge request root/ci-web-terminal!1",
|
2020-02-27 21:09:17 +00:00
|
|
|
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-01-19 12:10:46 +00:00
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders pipeline block', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(true);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with post merge deployments', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.postMergeDeployments = [
|
2020-02-27 21:09:17 +00:00
|
|
|
{
|
|
|
|
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',
|
2021-04-22 12:09:49 +00:00
|
|
|
external_url: 'http://root-main-patch-91341.volatile-watch.surge.sh/index.html',
|
2020-02-27 21:09:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'imgs/gallery.html',
|
|
|
|
external_url:
|
2021-04-22 12:09:49 +00:00
|
|
|
'http://root-main-patch-91341.volatile-watch.surge.sh/imgs/gallery.html',
|
2020-02-27 21:09:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'about/',
|
2021-04-22 12:09:49 +00:00
|
|
|
external_url: 'http://root-main-patch-91341.volatile-watch.surge.sh/about/',
|
2020-02-27 21:09:17 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
status: 'success',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders post deployment information', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-post-deployment').exists()).toBe(true);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('without information for target branch pipeline', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = 'merged';
|
2020-02-27 21:09:17 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(done);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render pipeline block', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
describe('when state is not merged', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
beforeEach((done) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.state = 'archived';
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
nextTick(done);
|
2018-10-29 11:34:41 +00:00
|
|
|
});
|
|
|
|
|
2020-02-27 21:09:17 +00:00
|
|
|
it('does not render pipeline block', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-post-merge-pipeline').exists()).toBe(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render post deployment information', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(wrapper.find('.js-post-deployment').exists()).toBe(false);
|
2018-10-29 11:34:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-04 09:09:45 +00:00
|
|
|
it('should not suggest pipelines when feature flag is not present', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(findSuggestPipeline().exists()).toBe(false);
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2020-10-12 21:08:56 +00:00
|
|
|
describe('security widget', () => {
|
|
|
|
describe.each`
|
2021-02-02 12:10:15 +00:00
|
|
|
context | hasPipeline | shouldRender
|
|
|
|
${'there is a pipeline'} | ${true} | ${true}
|
|
|
|
${'no pipeline'} | ${false} | ${false}
|
|
|
|
`('given $context', ({ hasPipeline, shouldRender }) => {
|
2020-10-12 21:08:56 +00:00
|
|
|
beforeEach(() => {
|
2021-01-21 18:09:11 +00:00
|
|
|
const mrData = {
|
2020-10-12 21:08:56 +00:00
|
|
|
...mockData,
|
2021-01-21 18:09:11 +00:00
|
|
|
...(hasPipeline ? {} : { pipeline: null }),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Override top-level mocked requests, which always use a fresh copy of
|
|
|
|
// mockData, which always includes the full pipeline object.
|
|
|
|
mock.onGet(mockData.merge_request_widget_path).reply(() => [200, mrData]);
|
|
|
|
mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, mrData]);
|
|
|
|
|
|
|
|
return createComponent(mrData, {
|
|
|
|
apolloProvider: createMockApollo([
|
|
|
|
[
|
2021-05-13 00:10:23 +00:00
|
|
|
securityReportMergeRequestDownloadPathsQuery,
|
|
|
|
async () => ({ data: securityReportMergeRequestDownloadPathsQueryResponse }),
|
2021-01-21 18:09:11 +00:00
|
|
|
],
|
|
|
|
]),
|
2020-10-12 21:08:56 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-21 18:09:11 +00:00
|
|
|
it(shouldRender ? 'renders' : 'does not render', () => {
|
|
|
|
expect(findSecurityMrWidget().exists()).toBe(shouldRender);
|
|
|
|
});
|
2020-10-12 21:08:56 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-20 00:09:06 +00:00
|
|
|
describe('suggestPipeline', () => {
|
2020-02-27 21:09:17 +00:00
|
|
|
beforeEach(() => {
|
2020-08-04 09:09:45 +00:00
|
|
|
mock.onAny().reply(200);
|
2020-09-30 21:10:09 +00:00
|
|
|
});
|
2020-03-02 18:07:42 +00:00
|
|
|
|
2020-10-27 06:08:27 +00:00
|
|
|
describe('given feature flag is enabled', () => {
|
2020-09-30 21:10:09 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
2020-08-04 09:09:45 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
wrapper.vm.mr.hasCI = false;
|
2020-09-30 21:10:09 +00:00
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2020-09-30 21:10:09 +00:00
|
|
|
it('should suggest pipelines when none exist', () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(findSuggestPipeline().exists()).toBe(true);
|
2020-09-30 21:10:09 +00:00
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2020-09-30 21:10:09 +00:00
|
|
|
it.each([
|
|
|
|
{ isDismissedSuggestPipeline: true },
|
|
|
|
{ mergeRequestAddCiConfigPath: null },
|
|
|
|
{ hasCI: true },
|
2020-12-23 21:10:24 +00:00
|
|
|
])('with %s, should not suggest pipeline', async (obj) => {
|
2021-01-19 12:10:46 +00:00
|
|
|
Object.assign(wrapper.vm.mr, obj);
|
2020-08-04 09:09:45 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
await nextTick();
|
2018-10-29 11:34:41 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(findSuggestPipeline().exists()).toBe(false);
|
2020-09-30 21:10:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow dismiss of the suggest pipeline message', async () => {
|
2021-01-19 12:10:46 +00:00
|
|
|
await findSuggestPipelineButton().trigger('click');
|
2020-09-30 21:10:09 +00:00
|
|
|
|
2021-01-19 12:10:46 +00:00
|
|
|
expect(findSuggestPipeline().exists()).toBe(false);
|
2020-09-30 21:10:09 +00:00
|
|
|
});
|
2020-02-27 21:09:17 +00:00
|
|
|
});
|
2018-10-29 11:34:41 +00:00
|
|
|
});
|
2021-09-29 12:11:22 +00:00
|
|
|
|
|
|
|
describe('mock extension', () => {
|
|
|
|
beforeEach(() => {
|
2021-09-29 15:11:47 +00:00
|
|
|
registerExtension(testExtension);
|
|
|
|
|
2021-09-29 12:11:22 +00:00
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2021-09-29 15:11:47 +00:00
|
|
|
afterEach(() => {
|
|
|
|
registeredExtensions.extensions = [];
|
|
|
|
});
|
2021-09-29 12:11:22 +00:00
|
|
|
|
2021-09-29 15:11:47 +00:00
|
|
|
it('renders collapsed data', async () => {
|
2021-09-29 12:11:22 +00:00
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Test extension summary count: 1');
|
|
|
|
});
|
|
|
|
|
2021-10-26 18:09:19 +00:00
|
|
|
it('triggers trackRedisHllUserEvent API call', async () => {
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find('[data-testid="widget-extension"] [data-testid="toggle-button"]')
|
|
|
|
.trigger('click');
|
|
|
|
|
|
|
|
await Vue.nextTick();
|
|
|
|
|
|
|
|
expect(api.trackRedisHllUserEvent).toHaveBeenCalledWith('test_expand_event');
|
|
|
|
});
|
|
|
|
|
2021-09-29 12:11:22 +00:00
|
|
|
it('renders full data', async () => {
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
wrapper
|
|
|
|
.find('[data-testid="widget-extension"] [data-testid="toggle-button"]')
|
|
|
|
.trigger('click');
|
|
|
|
|
|
|
|
await Vue.nextTick();
|
|
|
|
|
2021-10-22 12:09:12 +00:00
|
|
|
expect(
|
|
|
|
wrapper.find('[data-testid="widget-extension-top-level"]').find(GlDropdown).exists(),
|
|
|
|
).toBe(false);
|
|
|
|
|
2021-09-29 12:11:22 +00:00
|
|
|
const collapsedSection = wrapper.find('[data-testid="widget-extension-collapsed-section"]');
|
|
|
|
expect(collapsedSection.exists()).toBe(true);
|
|
|
|
expect(collapsedSection.text()).toContain('Hello world');
|
|
|
|
|
|
|
|
// Renders icon in the row
|
|
|
|
expect(collapsedSection.find(GlIcon).exists()).toBe(true);
|
2021-09-30 12:12:36 +00:00
|
|
|
expect(collapsedSection.find(GlIcon).props('name')).toBe('status-failed');
|
2021-09-29 12:11:22 +00:00
|
|
|
|
|
|
|
// Renders badge in the row
|
|
|
|
expect(collapsedSection.find(GlBadge).exists()).toBe(true);
|
|
|
|
expect(collapsedSection.find(GlBadge).text()).toBe('Closed');
|
|
|
|
|
|
|
|
// Renders a link in the row
|
|
|
|
expect(collapsedSection.find(GlLink).exists()).toBe(true);
|
|
|
|
expect(collapsedSection.find(GlLink).text()).toBe('GitLab.com');
|
|
|
|
});
|
|
|
|
});
|
2017-05-09 04:15:34 +00:00
|
|
|
});
|