debian-mirror-gitlab/spec/frontend/milestones/components/promote_milestone_modal_spec.js

110 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import { GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { setHTMLFixture } from 'helpers/fixtures';
2021-03-11 19:13:27 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2021-03-08 18:12:59 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2021-09-04 01:27:46 +05:30
import createFlash from '~/flash';
2018-03-27 19:54:05 +05:30
import axios from '~/lib/utils/axios_utils';
2021-03-08 18:12:59 +05:30
import * as urlUtils from '~/lib/utils/url_utility';
2022-01-26 12:08:38 +05:30
import PromoteMilestoneModal from '~/milestones/components/promote_milestone_modal.vue';
2021-03-08 18:12:59 +05:30
jest.mock('~/lib/utils/url_utility');
jest.mock('~/flash');
2018-03-27 19:54:05 +05:30
describe('Promote milestone modal', () => {
2021-03-08 18:12:59 +05:30
let wrapper;
2018-03-27 19:54:05 +05:30
const milestoneMockData = {
milestoneTitle: 'v1.0',
2020-07-28 23:09:34 +05:30
url: `${TEST_HOST}/dummy/promote/milestones`,
2018-05-01 15:08:00 +05:30
groupName: 'group',
2018-03-27 19:54:05 +05:30
};
2021-03-08 18:12:59 +05:30
const promoteButton = () => document.querySelector('.js-promote-project-milestone-button');
beforeEach(() => {
setHTMLFixture(`<button
class="js-promote-project-milestone-button"
data-group-name="${milestoneMockData.groupName}"
data-milestone-title="${milestoneMockData.milestoneTitle}"
data-url="${milestoneMockData.url}">
Promote
</button>`);
wrapper = shallowMount(PromoteMilestoneModal);
});
afterEach(() => {
wrapper.destroy();
});
describe('Modal opener button', () => {
it('button gets disabled when the modal opens', () => {
expect(promoteButton().disabled).toBe(false);
promoteButton().click();
expect(promoteButton().disabled).toBe(true);
});
it('button gets enabled when the modal closes', () => {
promoteButton().click();
wrapper.findComponent(GlModal).vm.$emit('hide');
expect(promoteButton().disabled).toBe(false);
2018-03-27 19:54:05 +05:30
});
2021-03-08 18:12:59 +05:30
});
2018-03-27 19:54:05 +05:30
2021-03-08 18:12:59 +05:30
describe('Modal title and description', () => {
beforeEach(() => {
promoteButton().click();
2018-03-27 19:54:05 +05:30
});
it('contains the proper description', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.text).toContain(
2019-09-30 21:07:59 +05:30
`Promoting ${milestoneMockData.milestoneTitle} will make it available for all projects inside ${milestoneMockData.groupName}.`,
2018-12-13 13:39:08 +05:30
);
2018-03-27 19:54:05 +05:30
});
it('contains the correct title', () => {
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.title).toBe('Promote v1.0 to group milestone?');
2018-03-27 19:54:05 +05:30
});
});
describe('When requesting a milestone promotion', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
promoteButton().click();
2018-03-27 19:54:05 +05:30
});
2021-03-08 18:12:59 +05:30
it('redirects when a milestone is promoted', async () => {
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(milestoneMockData.url);
return Promise.resolve({
2021-03-08 18:12:59 +05:30
data: {
url: responseURL,
2018-03-27 19:54:05 +05:30
},
});
});
2021-03-08 18:12:59 +05:30
wrapper.findComponent(GlModal).vm.$emit('primary');
await waitForPromises();
expect(urlUtils.visitUrl).toHaveBeenCalledWith(responseURL);
2018-03-27 19:54:05 +05:30
});
2021-03-08 18:12:59 +05:30
it('displays an error if promoting a milestone failed', async () => {
2018-03-27 19:54:05 +05:30
const dummyError = new Error('promoting milestone failed');
dummyError.response = { status: 500 };
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(milestoneMockData.url);
return Promise.reject(dummyError);
});
2021-03-08 18:12:59 +05:30
wrapper.findComponent(GlModal).vm.$emit('primary');
await waitForPromises();
2021-09-04 01:27:46 +05:30
expect(createFlash).toHaveBeenCalledWith({ message: dummyError });
2018-03-27 19:54:05 +05:30
});
});
});