diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js')
-rw-r--r-- | spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js b/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js new file mode 100644 index 00000000000..e0e26434680 --- /dev/null +++ b/spec/frontend/packages_and_registries/package_registry/components/delete_modal_spec.js @@ -0,0 +1,71 @@ +import { GlModal as RealGlModal } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { stubComponent } from 'helpers/stub_component'; +import DeleteModal from '~/packages_and_registries/package_registry/components/delete_modal.vue'; + +const GlModal = stubComponent(RealGlModal, { + methods: { + show: jest.fn(), + }, +}); + +describe('DeleteModal', () => { + let wrapper; + + const defaultItemsToBeDeleted = [ + { + name: 'package 01', + }, + { + name: 'package 02', + }, + ]; + + const findModal = () => wrapper.findComponent(GlModal); + + const mountComponent = ({ itemsToBeDeleted = defaultItemsToBeDeleted } = {}) => { + wrapper = shallowMountExtended(DeleteModal, { + propsData: { + itemsToBeDeleted, + }, + stubs: { + GlModal, + }, + }); + }; + + beforeEach(() => { + mountComponent(); + }); + + it('passes title prop', () => { + expect(findModal().props('title')).toMatchInterpolatedText('Delete packages'); + }); + + it('passes actionPrimary prop', () => { + expect(findModal().props('actionPrimary')).toStrictEqual({ + text: 'Permanently delete', + attributes: [{ variant: 'danger' }, { category: 'primary' }], + }); + }); + + it('renders description', () => { + expect(findModal().text()).toContain( + 'You are about to delete 2 packages. This operation is irreversible.', + ); + }); + + it('emits confirm when primary event is emitted', () => { + expect(wrapper.emitted('confirm')).toBeUndefined(); + + findModal().vm.$emit('primary'); + + expect(wrapper.emitted('confirm')).toHaveLength(1); + }); + + it('show calls gl-modal show', () => { + findModal().vm.show(); + + expect(GlModal.methods.show).toHaveBeenCalled(); + }); +}); |