2018-03-27 19:54:05 +05:30
|
|
|
import Vue from 'vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-03-27 19:54:05 +05:30
|
|
|
import promoteMilestoneModal from '~/pages/milestones/shared/components/promote_milestone_modal.vue';
|
|
|
|
import eventHub from '~/pages/milestones/shared/event_hub';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
|
|
|
|
describe('Promote milestone modal', () => {
|
|
|
|
let vm;
|
|
|
|
const Component = Vue.extend(promoteMilestoneModal);
|
|
|
|
const milestoneMockData = {
|
|
|
|
milestoneTitle: 'v1.0',
|
|
|
|
url: `${gl.TEST_HOST}/dummy/promote/milestones`,
|
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, milestoneMockData);
|
|
|
|
});
|
|
|
|
|
|
|
|
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 ${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', () => {
|
|
|
|
expect(vm.title).toEqual('Promote v1.0 to group milestone?');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When requesting a milestone promotion', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(Component, {
|
|
|
|
...milestoneMockData,
|
|
|
|
});
|
|
|
|
spyOn(eventHub, '$emit');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('redirects when a milestone is promoted', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const responseURL = `${gl.TEST_HOST}/dummy/endpoint`;
|
2018-12-13 13:39:08 +05:30
|
|
|
spyOn(axios, 'post').and.callFake(url => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(url).toBe(milestoneMockData.url);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(
|
|
|
|
'promoteMilestoneModal.requestStarted',
|
|
|
|
milestoneMockData.url,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
return Promise.resolve({
|
|
|
|
request: {
|
|
|
|
responseURL,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.onSubmit()
|
|
|
|
.then(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('promoteMilestoneModal.requestFinished', {
|
|
|
|
milestoneUrl: milestoneMockData.url,
|
|
|
|
successful: true,
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('displays an error if promoting a milestone failed', done => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const dummyError = new Error('promoting milestone failed');
|
|
|
|
dummyError.response = { status: 500 };
|
2018-12-13 13:39:08 +05:30
|
|
|
spyOn(axios, 'post').and.callFake(url => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(url).toBe(milestoneMockData.url);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith(
|
|
|
|
'promoteMilestoneModal.requestStarted',
|
|
|
|
milestoneMockData.url,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
return Promise.reject(dummyError);
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.onSubmit()
|
2018-12-13 13:39:08 +05:30
|
|
|
.catch(error => {
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(error).toBe(dummyError);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('promoteMilestoneModal.requestFinished', {
|
|
|
|
milestoneUrl: milestoneMockData.url,
|
|
|
|
successful: false,
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|