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
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('deletes milestone and redirects to overview page', (done) => {
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.onSubmit()
|
2018-12-13 13:39:08 +05:30
|
|
|
.then(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(redirectTo).toHaveBeenCalledWith(responseURL);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', {
|
|
|
|
milestoneUrl: props.milestoneUrl,
|
|
|
|
successful: true,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('displays error if deleting milestone failed', (done) => {
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.onSubmit()
|
2021-03-08 18:12:59 +05:30
|
|
|
.catch((error) => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(error).toBe(dummyError);
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(redirectTo).not.toHaveBeenCalled();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', {
|
|
|
|
milestoneUrl: props.milestoneUrl,
|
|
|
|
successful: false,
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|