From f7dae0cdcb70ecb71c1d65f099e9d96b27a4548c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 25 Feb 2020 12:08:48 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../vue_shared/components/confirm_modal_spec.js | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 spec/frontend/vue_shared/components/confirm_modal_spec.js (limited to 'spec/frontend/vue_shared') diff --git a/spec/frontend/vue_shared/components/confirm_modal_spec.js b/spec/frontend/vue_shared/components/confirm_modal_spec.js new file mode 100644 index 00000000000..722380d3383 --- /dev/null +++ b/spec/frontend/vue_shared/components/confirm_modal_spec.js @@ -0,0 +1,84 @@ +import { shallowMount } from '@vue/test-utils'; +import { GlModal } from '@gitlab/ui'; +import { TEST_HOST } from 'helpers/test_constants'; +import ConfirmModal from '~/vue_shared/components/confirm_modal.vue'; + +describe('vue_shared/components/confirm_modal', () => { + const testModalProps = { + path: `${TEST_HOST}/1`, + method: 'delete', + modalAttributes: { + modalId: 'test-confirm-modal', + title: 'Are you sure?', + message: 'This will remove item 1', + okVariant: 'danger', + okTitle: 'Remove item', + }, + }; + + const actionSpies = { + openModal: jest.fn(), + }; + + let wrapper; + + const createComponent = (props = {}) => { + wrapper = shallowMount(ConfirmModal, { + propsData: { + ...testModalProps, + ...props, + }, + methods: { + ...actionSpies, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + const findModal = () => wrapper.find(GlModal); + + describe('template', () => { + beforeEach(() => { + createComponent(); + }); + + it('calls openModal on mount', () => { + expect(actionSpies.openModal).toHaveBeenCalled(); + }); + + it('renders GlModal', () => { + expect(findModal().exists()).toBeTruthy(); + }); + }); + + describe('methods', () => { + beforeEach(() => { + createComponent(); + }); + + describe('submitModal', () => { + beforeEach(() => { + wrapper.vm.$refs.form.requestSubmit = jest.fn(); + }); + + it('calls requestSubmit', () => { + wrapper.vm.submitModal(); + expect(wrapper.vm.$refs.form.requestSubmit).toHaveBeenCalled(); + }); + }); + + describe('dismiss', () => { + it('removes gl-modal', () => { + expect(findModal().exists()).toBeTruthy(); + wrapper.vm.dismiss(); + + return wrapper.vm.$nextTick(() => { + expect(findModal().exists()).toBeFalsy(); + }); + }); + }); + }); +}); -- cgit v1.2.1