debian-mirror-gitlab/spec/frontend/labels/components/promote_label_modal_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import Vue from 'vue';
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2021-03-11 19:13:27 +05:30
import mountComponent from 'helpers/vue_mount_component_helper';
import axios from '~/lib/utils/axios_utils';
2022-01-26 12:08:38 +05:30
import promoteLabelModal from '~/labels/components/promote_label_modal.vue';
import eventHub from '~/labels/event_hub';
2018-03-27 19:54:05 +05:30
describe('Promote label modal', () => {
let vm;
const Component = Vue.extend(promoteLabelModal);
const labelMockData = {
labelTitle: 'Documentation',
labelColor: '#5cb85c',
labelTextColor: '#ffffff',
2020-07-28 23:09:34 +05:30
url: `${TEST_HOST}/dummy/promote/labels`,
2018-05-01 15:08:00 +05:30
groupName: 'group',
2018-03-27 19:54:05 +05:30
};
describe('Modal title and description', () => {
beforeEach(() => {
vm = mountComponent(Component, labelMockData);
});
afterEach(() => {
vm.$destroy();
});
it('contains the proper description', () => {
2018-12-13 13:39:08 +05:30
expect(vm.text).toContain(
2019-09-30 21:07:59 +05:30
`Promoting ${labelMockData.labelTitle} will make it available for all projects inside ${labelMockData.groupName}`,
2018-12-13 13:39:08 +05:30
);
2018-03-27 19:54:05 +05:30
});
it('contains a label span with the color', () => {
2021-01-29 00:20:46 +05:30
expect(vm.labelColor).not.toBe(null);
expect(vm.labelColor).toBe(labelMockData.labelColor);
expect(vm.labelTitle).toBe(labelMockData.labelTitle);
2018-03-27 19:54:05 +05:30
});
});
describe('When requesting a label promotion', () => {
beforeEach(() => {
vm = mountComponent(Component, {
...labelMockData,
});
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2018-03-27 19:54:05 +05:30
});
afterEach(() => {
vm.$destroy();
});
2022-06-21 17:19:12 +05:30
it('redirects when a label is promoted', () => {
2020-07-28 23:09:34 +05:30
const responseURL = `${TEST_HOST}/dummy/endpoint`;
2021-03-08 18:12:59 +05:30
jest.spyOn(axios, 'post').mockImplementation((url) => {
2018-03-27 19:54:05 +05:30
expect(url).toBe(labelMockData.url);
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
'promoteLabelModal.requestStarted',
labelMockData.url,
);
2018-03-27 19:54:05 +05:30
return Promise.resolve({
request: {
responseURL,
},
});
});
2022-06-21 17:19:12 +05:30
return vm.onSubmit().then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', {
labelUrl: labelMockData.url,
successful: true,
});
});
2018-03-27 19:54:05 +05:30
});
2022-06-21 17:19:12 +05:30
it('displays an error if promoting a label failed', () => {
2018-03-27 19:54:05 +05:30
const dummyError = new Error('promoting label failed');
dummyError.response = { status: 500 };
2022-06-21 17:19:12 +05:30
2021-03-08 18:12:59 +05:30
jest.spyOn(axios, 'post').mockImplementation((url) => {
2018-03-27 19:54:05 +05:30
expect(url).toBe(labelMockData.url);
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
'promoteLabelModal.requestStarted',
labelMockData.url,
);
2022-06-21 17:19:12 +05:30
2018-03-27 19:54:05 +05:30
return Promise.reject(dummyError);
});
2022-06-21 17:19:12 +05:30
return vm.onSubmit().catch((error) => {
expect(error).toBe(dummyError);
expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', {
labelUrl: labelMockData.url,
successful: false,
});
});
2018-03-27 19:54:05 +05:30
});
});
});