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.

105 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { shallowMount } from '@vue/test-utils';
import { GlModal, GlSprintf } from '@gitlab/ui';
import AxiosMockAdapter from 'axios-mock-adapter';
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2022-11-25 23:54:43 +05:30
import { stubComponent } from 'helpers/stub_component';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
2022-11-25 23:54:43 +05:30
import PromoteLabelModal from '~/labels/components/promote_label_modal.vue';
2022-01-26 12:08:38 +05:30
import eventHub from '~/labels/event_hub';
2018-03-27 19:54:05 +05:30
describe('Promote label modal', () => {
2022-11-25 23:54:43 +05:30
let wrapper;
let axiosMock;
2018-03-27 19:54:05 +05:30
const labelMockData = {
labelTitle: 'Documentation',
2022-11-25 23:54:43 +05:30
labelColor: 'rgb(92, 184, 92)',
labelTextColor: 'rgb(255, 255, 255)',
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
};
2022-11-25 23:54:43 +05:30
const createComponent = () => {
wrapper = shallowMount(PromoteLabelModal, {
propsData: labelMockData,
stubs: {
GlSprintf,
GlModal: stubComponent(GlModal, {
template: `<div><slot name="modal-title"></slot><slot></slot></div>`,
}),
},
2018-03-27 19:54:05 +05:30
});
2022-11-25 23:54:43 +05:30
};
2018-03-27 19:54:05 +05:30
2022-11-25 23:54:43 +05:30
beforeEach(() => {
axiosMock = new AxiosMockAdapter(axios);
createComponent();
});
2018-03-27 19:54:05 +05:30
2022-11-25 23:54:43 +05:30
afterEach(() => {
axiosMock.reset();
wrapper.destroy();
});
describe('Modal title and description', () => {
2018-03-27 19:54:05 +05:30
it('contains the proper description', () => {
2022-11-25 23:54:43 +05:30
expect(wrapper.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', () => {
2022-11-25 23:54:43 +05:30
const label = wrapper.find('.modal-title-with-label .label');
expect(label.element.style.backgroundColor).toBe(labelMockData.labelColor);
expect(label.element.style.color).toBe(labelMockData.labelTextColor);
expect(label.text()).toBe(labelMockData.labelTitle);
2018-03-27 19:54:05 +05:30
});
});
describe('When requesting a label promotion', () => {
beforeEach(() => {
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2018-03-27 19:54:05 +05:30
});
2022-11-25 23:54:43 +05:30
it('redirects when a label is promoted', async () => {
2020-07-28 23:09:34 +05:30
const responseURL = `${TEST_HOST}/dummy/endpoint`;
2023-04-23 21:23:45 +05:30
axiosMock.onPost(labelMockData.url).reply(HTTP_STATUS_OK, { url: responseURL });
2018-03-27 19:54:05 +05:30
2022-11-25 23:54:43 +05:30
wrapper.findComponent(GlModal).vm.$emit('primary');
expect(eventHub.$emit).toHaveBeenCalledWith(
'promoteLabelModal.requestStarted',
labelMockData.url,
);
await axios.waitForAll();
expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', {
labelUrl: labelMockData.url,
successful: true,
2022-06-21 17:19:12 +05:30
});
2018-03-27 19:54:05 +05:30
});
2022-11-25 23:54:43 +05:30
it('displays an error if promoting a label failed', async () => {
2018-03-27 19:54:05 +05:30
const dummyError = new Error('promoting label failed');
2023-04-23 21:23:45 +05:30
dummyError.response = { status: HTTP_STATUS_INTERNAL_SERVER_ERROR };
axiosMock
.onPost(labelMockData.url)
.reply(HTTP_STATUS_INTERNAL_SERVER_ERROR, { error: dummyError });
2022-06-21 17:19:12 +05:30
2022-11-25 23:54:43 +05:30
wrapper.findComponent(GlModal).vm.$emit('primary');
2022-06-21 17:19:12 +05:30
2022-11-25 23:54:43 +05:30
await axios.waitForAll();
2018-03-27 19:54:05 +05:30
2022-11-25 23:54:43 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', {
labelUrl: labelMockData.url,
successful: false,
2022-06-21 17:19:12 +05:30
});
2018-03-27 19:54:05 +05:30
});
});
});