1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import Vue, { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils';
import { redirectTo } from '~/lib/utils/url_utility';
import StopJobsModal from '~/pages/admin/jobs/index/components/stop_jobs_modal.vue';
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
redirectTo: jest.fn(),
}));
describe('stop_jobs_modal.vue', () => {
const props = {
url: `${TEST_HOST}/stop_jobs_modal.vue/stopAll`,
};
let wrapper;
beforeEach(() => {
wrapper = mount(StopJobsModal, { propsData: props });
});
afterEach(() => {
wrapper.destroy();
});
describe('on submit', () => {
it('stops jobs and redirects to overview page', async () => {
const responseURL = `${TEST_HOST}/stop_jobs_modal.vue/jobs`;
// TODO: We can't use axios-mock-adapter because our current version
// does not support responseURL
//
// see https://gitlab.com/gitlab-org/gitlab/-/issues/375308 for details
jest.spyOn(axios, 'post').mockImplementation((url) => {
expect(url).toBe(props.url);
return Promise.resolve({
request: {
responseURL,
},
});
});
wrapper.findComponent(GlModal).vm.$emit('primary');
await nextTick();
expect(redirectTo).toHaveBeenCalledWith(responseURL);
});
it('displays error if stopping jobs failed', async () => {
Vue.config.errorHandler = () => {}; // silencing thrown error
const dummyError = new Error('stopping jobs failed');
// TODO: We can't use axios-mock-adapter because our current version
// does not support responseURL
//
// see https://gitlab.com/gitlab-org/gitlab/-/issues/375308 for details
jest.spyOn(axios, 'post').mockImplementation((url) => {
expect(url).toBe(props.url);
return Promise.reject(dummyError);
});
wrapper.findComponent(GlModal).vm.$emit('primary');
await nextTick();
expect(redirectTo).not.toHaveBeenCalled();
});
});
});
|