diff options
Diffstat (limited to 'spec/frontend/pages/admin/jobs/index/components/stop_jobs_modal_spec.js')
-rw-r--r-- | spec/frontend/pages/admin/jobs/index/components/stop_jobs_modal_spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/frontend/pages/admin/jobs/index/components/stop_jobs_modal_spec.js b/spec/frontend/pages/admin/jobs/index/components/stop_jobs_modal_spec.js new file mode 100644 index 00000000000..fe17c03389c --- /dev/null +++ b/spec/frontend/pages/admin/jobs/index/components/stop_jobs_modal_spec.js @@ -0,0 +1,64 @@ +import Vue from 'vue'; +import { redirectTo } from '~/lib/utils/url_utility'; +import mountComponent from 'helpers/vue_mount_component_helper'; +import axios from '~/lib/utils/axios_utils'; +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: `${gl.TEST_HOST}/stop_jobs_modal.vue/stopAll`, + }; + let vm; + + afterEach(() => { + vm.$destroy(); + }); + + beforeEach(() => { + const Component = Vue.extend(stopJobsModal); + vm = mountComponent(Component, props); + }); + + describe('onSubmit', () => { + it('stops jobs and redirects to overview page', done => { + const responseURL = `${gl.TEST_HOST}/stop_jobs_modal.vue/jobs`; + jest.spyOn(axios, 'post').mockImplementation(url => { + expect(url).toBe(props.url); + return Promise.resolve({ + request: { + responseURL, + }, + }); + }); + + vm.onSubmit() + .then(() => { + expect(redirectTo).toHaveBeenCalledWith(responseURL); + }) + .then(done) + .catch(done.fail); + }); + + it('displays error if stopping jobs failed', done => { + const dummyError = new Error('stopping jobs failed'); + jest.spyOn(axios, 'post').mockImplementation(url => { + expect(url).toBe(props.url); + return Promise.reject(dummyError); + }); + + vm.onSubmit() + .then(done.fail) + .catch(error => { + expect(error).toBe(dummyError); + expect(redirectTo).not.toHaveBeenCalled(); + }) + .then(done) + .catch(done.fail); + }); + }); +}); |