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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
import { GlModal as RealGlModal, GlLink, GlSprintf } 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';
import {
DELETE_PACKAGE_MODAL_PRIMARY_ACTION,
DELETE_PACKAGE_WITH_REQUEST_FORWARDING_PRIMARY_ACTION,
DELETE_PACKAGES_REQUEST_FORWARDING_MODAL_CONTENT,
DELETE_PACKAGES_WITH_REQUEST_FORWARDING_PRIMARY_ACTION,
REQUEST_FORWARDING_HELP_PAGE_PATH,
} from '~/packages_and_registries/package_registry/constants';
const GlModal = stubComponent(RealGlModal, {
methods: {
show: jest.fn(),
},
});
describe('DeleteModal', () => {
let wrapper;
const defaultItemsToBeDeleted = [
{
name: 'package-1',
version: '1.0.0',
},
{
name: 'package-2',
version: '1.0.0',
},
];
const findModal = () => wrapper.findComponent(GlModal);
const findLink = () => wrapper.findComponent(GlLink);
const mountComponent = ({
itemsToBeDeleted = defaultItemsToBeDeleted,
showRequestForwardingContent = false,
} = {}) => {
wrapper = shallowMountExtended(DeleteModal, {
propsData: {
itemsToBeDeleted,
showRequestForwardingContent,
},
stubs: {
GlModal,
GlSprintf,
},
});
};
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()).toMatchInterpolatedText(
'You are about to delete 2 packages. This operation is irreversible.',
);
});
it('with only one item to be deleted renders correct description', () => {
mountComponent({ itemsToBeDeleted: [defaultItemsToBeDeleted[0]] });
expect(findModal().text()).toMatchInterpolatedText(
'You are about to delete version 1.0.0 of package-1. Are you sure?',
);
});
it('sets the right action primary text', () => {
expect(findModal().props('actionPrimary')).toMatchObject({
text: DELETE_PACKAGE_MODAL_PRIMARY_ACTION,
});
});
describe('when showRequestForwardingContent is set', () => {
it('renders correct description', () => {
mountComponent({ showRequestForwardingContent: true });
expect(findModal().text()).toMatchInterpolatedText(
DELETE_PACKAGES_REQUEST_FORWARDING_MODAL_CONTENT,
);
});
it('contains link to help page', () => {
mountComponent({ showRequestForwardingContent: true });
expect(findLink().exists()).toBe(true);
expect(findLink().attributes('href')).toBe(REQUEST_FORWARDING_HELP_PAGE_PATH);
});
it('sets the right action primary text', () => {
mountComponent({ showRequestForwardingContent: true });
expect(findModal().props('actionPrimary')).toMatchObject({
text: DELETE_PACKAGES_WITH_REQUEST_FORWARDING_PRIMARY_ACTION,
});
});
describe('and only one item to be deleted', () => {
beforeEach(() => {
mountComponent({
showRequestForwardingContent: true,
itemsToBeDeleted: [defaultItemsToBeDeleted[0]],
});
});
it('renders correct description', () => {
expect(findModal().text()).toMatchInterpolatedText(
'Deleting this package while request forwarding is enabled for the project can pose a security risk. Do you want to delete package-1 version 1.0.0 anyway? What are the risks?',
);
});
it('contains link to help page', () => {
expect(findLink().exists()).toBe(true);
expect(findLink().attributes('href')).toBe(REQUEST_FORWARDING_HELP_PAGE_PATH);
});
it('sets the right action primary text', () => {
expect(findModal().props('actionPrimary')).toMatchObject({
text: DELETE_PACKAGE_WITH_REQUEST_FORWARDING_PRIMARY_ACTION,
});
});
});
});
it('emits confirm when primary event is emitted', () => {
expect(wrapper.emitted('confirm')).toBeUndefined();
findModal().vm.$emit('primary');
expect(wrapper.emitted('confirm')).toHaveLength(1);
});
it('emits cancel when cancel event is emitted', () => {
expect(wrapper.emitted('cancel')).toBeUndefined();
findModal().vm.$emit('cancel');
expect(wrapper.emitted('cancel')).toHaveLength(1);
});
it('show calls gl-modal show', () => {
findModal().vm.show();
expect(GlModal.methods.show).toHaveBeenCalled();
});
});
|