1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import { GlSprintf, GlModal } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import DeletePackageModal from '~/packages_and_registries/shared/components/delete_package_modal.vue';
describe('DeletePackageModal', () => {
let wrapper;
const defaultItemToBeDeleted = {
name: 'package 01',
};
const findModal = () => wrapper.findComponent(GlModal);
const mountComponent = ({ itemToBeDeleted = defaultItemToBeDeleted } = {}) => {
wrapper = shallowMountExtended(DeletePackageModal, {
propsData: {
itemToBeDeleted,
},
});
};
describe('when itemToBeDeleted prop is defined', () => {
beforeEach(() => {
mountComponent();
});
it('displays modal', () => {
expect(findModal().props('visible')).toBe(true);
});
it('passes title prop', () => {
expect(findModal().props('title')).toBe(wrapper.vm.$options.i18n.modalTitle);
});
it('passes actionPrimary prop', () => {
expect(findModal().props('actionPrimary')).toStrictEqual({
text: wrapper.vm.$options.i18n.modalAction,
attributes: {
variant: 'danger',
},
});
});
it('displays description', () => {
const descriptionEl = findModal().findComponent(GlSprintf);
expect(descriptionEl.exists()).toBe(true);
expect(descriptionEl.attributes('message')).toBe(wrapper.vm.$options.i18n.modalDescription);
});
it('emits ok when modal is validate', () => {
expect(wrapper.emitted().ok).toBeUndefined();
findModal().vm.$emit('ok');
expect(wrapper.emitted().ok).toHaveLength(1);
});
it('emits cancel when modal close', () => {
expect(wrapper.emitted().cancel).toBeUndefined();
findModal().vm.$emit('change', false);
expect(wrapper.emitted().cancel).toHaveLength(1);
});
});
describe('when itemToBeDeleted prop is null', () => {
beforeEach(() => {
mountComponent({ itemToBeDeleted: null });
});
it("doesn't display modal", () => {
expect(findModal().props('visible')).toBe(false);
});
});
});
|