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

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

102 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +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';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2021-03-11 19:13:27 +05:30
import { redirectTo } from '~/lib/utils/url_utility';
2022-01-26 12:08:38 +05:30
import deleteMilestoneModal from '~/milestones/components/delete_milestone_modal.vue';
import eventHub from '~/milestones/event_hub';
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
redirectTo: jest.fn(),
}));
2018-03-17 18:26:18 +05:30
describe('delete_milestone_modal.vue', () => {
const Component = Vue.extend(deleteMilestoneModal);
const props = {
issueCount: 1,
mergeRequestCount: 2,
milestoneId: 3,
milestoneTitle: 'my milestone title',
2020-07-28 23:09:34 +05:30
milestoneUrl: `${TEST_HOST}/delete_milestone_modal.vue/milestone`,
2018-03-17 18:26:18 +05:30
};
let vm;
afterEach(() => {
vm.$destroy();
});
describe('onSubmit', () => {
beforeEach(() => {
vm = mountComponent(Component, props);
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
});
2022-06-21 17:19:12 +05:30
it('deletes milestone and redirects to overview page', async () => {
2020-07-28 23:09:34 +05:30
const responseURL = `${TEST_HOST}/delete_milestone_modal.vue/milestoneOverview`;
2021-03-08 18:12:59 +05:30
jest.spyOn(axios, 'delete').mockImplementation((url) => {
2018-03-17 18:26:18 +05:30
expect(url).toBe(props.milestoneUrl);
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
'deleteMilestoneModal.requestStarted',
props.milestoneUrl,
);
2020-05-24 23:13:21 +05:30
eventHub.$emit.mockReset();
2018-03-17 18:26:18 +05:30
return Promise.resolve({
request: {
responseURL,
},
});
});
2022-06-21 17:19:12 +05:30
await vm.onSubmit();
expect(redirectTo).toHaveBeenCalledWith(responseURL);
expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', {
milestoneUrl: props.milestoneUrl,
successful: true,
});
2018-03-17 18:26:18 +05:30
});
2022-06-21 17:19:12 +05:30
it('displays error if deleting milestone failed', async () => {
2018-03-17 18:26:18 +05:30
const dummyError = new Error('deleting milestone failed');
dummyError.response = { status: 418 };
2021-03-08 18:12:59 +05:30
jest.spyOn(axios, 'delete').mockImplementation((url) => {
2018-03-17 18:26:18 +05:30
expect(url).toBe(props.milestoneUrl);
2018-12-13 13:39:08 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
'deleteMilestoneModal.requestStarted',
props.milestoneUrl,
);
2020-05-24 23:13:21 +05:30
eventHub.$emit.mockReset();
2018-03-17 18:26:18 +05:30
return Promise.reject(dummyError);
});
2022-06-21 17:19:12 +05:30
await expect(vm.onSubmit()).rejects.toEqual(dummyError);
expect(redirectTo).not.toHaveBeenCalled();
expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', {
milestoneUrl: props.milestoneUrl,
successful: false,
});
2018-03-17 18:26:18 +05:30
});
});
describe('text', () => {
it('contains the issue and milestone count', () => {
vm = mountComponent(Component, props);
const value = vm.text;
expect(value).toContain('remove it from 1 issue and 2 merge requests');
});
it('contains neither issue nor milestone count', () => {
2018-12-13 13:39:08 +05:30
vm = mountComponent(Component, {
...props,
2018-03-17 18:26:18 +05:30
issueCount: 0,
mergeRequestCount: 0,
});
const value = vm.text;
expect(value).toContain('is not currently used');
});
});
});