diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-06 09:08:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-06 09:08:13 +0000 |
commit | 8e94dad32b10edebf79285c083176c2b7005ef64 (patch) | |
tree | 3bb66395f2962063ca0d20f98b35ac852d801c7e /spec/frontend/vue_shared | |
parent | ab128cc125f9db0c3a1bd48845f90c3d61ef42c9 (diff) | |
download | gitlab-ce-8e94dad32b10edebf79285c083176c2b7005ef64.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared')
-rw-r--r-- | spec/frontend/vue_shared/components/confirm_modal_spec.js | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/spec/frontend/vue_shared/components/confirm_modal_spec.js b/spec/frontend/vue_shared/components/confirm_modal_spec.js index 722380d3383..d3dea73e4a6 100644 --- a/spec/frontend/vue_shared/components/confirm_modal_spec.js +++ b/spec/frontend/vue_shared/components/confirm_modal_spec.js @@ -3,6 +3,8 @@ import { GlModal } from '@gitlab/ui'; import { TEST_HOST } from 'helpers/test_constants'; import ConfirmModal from '~/vue_shared/components/confirm_modal.vue'; +jest.mock('~/lib/utils/csrf', () => ({ token: 'test-csrf-token' })); + describe('vue_shared/components/confirm_modal', () => { const testModalProps = { path: `${TEST_HOST}/1`, @@ -39,45 +41,61 @@ describe('vue_shared/components/confirm_modal', () => { }); const findModal = () => wrapper.find(GlModal); + const findForm = () => wrapper.find('form'); + const findFormData = () => + findForm() + .findAll('input') + .wrappers.map(x => ({ name: x.attributes('name'), value: x.attributes('value') })); describe('template', () => { - beforeEach(() => { - createComponent(); - }); + describe('when showModal is false', () => { + beforeEach(() => { + createComponent(); + }); - it('calls openModal on mount', () => { - expect(actionSpies.openModal).toHaveBeenCalled(); + it('does not render GlModal', () => { + expect(findModal().exists()).toBeFalsy(); + }); }); - it('renders GlModal', () => { - expect(findModal().exists()).toBeTruthy(); + describe('when showModal is true', () => { + beforeEach(() => { + createComponent({ showModal: true }); + }); + + it('renders GlModal', () => { + expect(findModal().exists()).toBeTruthy(); + expect(findModal().attributes()).toEqual( + expect.objectContaining({ + modalid: testModalProps.modalAttributes.modalId, + oktitle: testModalProps.modalAttributes.okTitle, + okvariant: testModalProps.modalAttributes.okVariant, + }), + ); + }); }); }); describe('methods', () => { beforeEach(() => { - createComponent(); + createComponent({ showModal: true }); }); - describe('submitModal', () => { - beforeEach(() => { - wrapper.vm.$refs.form.requestSubmit = jest.fn(); - }); - - it('calls requestSubmit', () => { - wrapper.vm.submitModal(); - expect(wrapper.vm.$refs.form.requestSubmit).toHaveBeenCalled(); - }); + it('does not submit form', () => { + expect(findForm().element.submit).not.toHaveBeenCalled(); }); - describe('dismiss', () => { - it('removes gl-modal', () => { - expect(findModal().exists()).toBeTruthy(); - wrapper.vm.dismiss(); + describe('when modal submitted', () => { + beforeEach(() => { + findModal().vm.$emit('primary'); + }); - return wrapper.vm.$nextTick(() => { - expect(findModal().exists()).toBeFalsy(); - }); + it('submits form', () => { + expect(findFormData()).toEqual([ + { name: '_method', value: testModalProps.method }, + { name: 'authenticity_token', value: 'test-csrf-token' }, + ]); + expect(findForm().element.submit).toHaveBeenCalled(); }); }); }); |