diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js new file mode 100644 index 00000000000..d19f9352bbc --- /dev/null +++ b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js @@ -0,0 +1,59 @@ +import { GlModal } from '@gitlab/ui'; +import { mount } from '@vue/test-utils'; +import ConfirmModal from '~/lib/utils/confirm_via_gl_modal/confirm_modal.vue'; + +describe('Confirm Modal', () => { + let wrapper; + let modal; + + const createComponent = ({ primaryText, primaryVariant } = {}) => { + wrapper = mount(ConfirmModal, { + propsData: { + primaryText, + primaryVariant, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + const findGlModal = () => wrapper.findComponent(GlModal); + + describe('Modal events', () => { + beforeEach(() => { + createComponent(); + modal = findGlModal(); + }); + + it('should emit `confirmed` event on `primary` modal event', () => { + findGlModal().vm.$emit('primary'); + expect(wrapper.emitted('confirmed')).toBeTruthy(); + }); + + it('should emit closed` event on `hidden` modal event', () => { + modal.vm.$emit('hidden'); + expect(wrapper.emitted('closed')).toBeTruthy(); + }); + }); + + describe('Custom properties', () => { + it('should pass correct custom primary text & button variant to the modal when provided', () => { + const primaryText = "Let's do it!"; + const primaryVariant = 'danger'; + + createComponent({ primaryText, primaryVariant }); + const customProps = findGlModal().props('actionPrimary'); + expect(customProps.text).toBe(primaryText); + expect(customProps.attributes.variant).toBe(primaryVariant); + }); + + it('should pass default primary text & button variant to the modal if no custom values provided', () => { + createComponent(); + const customProps = findGlModal().props('actionPrimary'); + expect(customProps.text).toBe('OK'); + expect(customProps.attributes.variant).toBe('confirm'); + }); + }); +}); |