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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
import { GlFormCheckbox, GlSprintf, GlIcon, GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import component from '~/packages_and_registries/container_registry/explorer/components/details_page/tags_list_row.vue';
import {
REMOVE_TAG_BUTTON_TITLE,
MISSING_MANIFEST_WARNING_TOOLTIP,
NOT_AVAILABLE_TEXT,
NOT_AVAILABLE_SIZE,
COPY_IMAGE_PATH_TITLE,
} from '~/packages_and_registries/container_registry/explorer/constants/index';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import DetailsRow from '~/vue_shared/components/registry/details_row.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { tagsMock } from '../../mock_data';
import { ListItem } from '../../stubs';
describe('tags list row', () => {
let wrapper;
const [tag] = [...tagsMock];
const defaultProps = { tag, isMobile: false, index: 0 };
const findCheckbox = () => wrapper.findComponent(GlFormCheckbox);
const findName = () => wrapper.find('[data-testid="name"]');
const findSize = () => wrapper.find('[data-testid="size"]');
const findTime = () => wrapper.find('[data-testid="time"]');
const findShortRevision = () => wrapper.find('[data-testid="digest"]');
const findClipboardButton = () => wrapper.findComponent(ClipboardButton);
const findTimeAgoTooltip = () => wrapper.findComponent(TimeAgoTooltip);
const findDetailsRows = () => wrapper.findAllComponents(DetailsRow);
const findPublishedDateDetail = () => wrapper.find('[data-testid="published-date-detail"]');
const findManifestDetail = () => wrapper.find('[data-testid="manifest-detail"]');
const findConfigurationDetail = () => wrapper.find('[data-testid="configuration-detail"]');
const findWarningIcon = () => wrapper.findComponent(GlIcon);
const findAdditionalActionsMenu = () => wrapper.findComponent(GlDropdown);
const findDeleteButton = () => wrapper.findComponent(GlDropdownItem);
const mountComponent = (propsData = defaultProps) => {
wrapper = shallowMount(component, {
stubs: {
GlSprintf,
ListItem,
DetailsRow,
GlDropdown,
},
propsData,
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
},
});
};
describe('checkbox', () => {
it('exists', () => {
mountComponent();
expect(findCheckbox().exists()).toBe(true);
});
it("does not exist when the row can't be deleted", () => {
const customTag = { ...tag, canDelete: false };
mountComponent({ ...defaultProps, tag: customTag });
expect(findCheckbox().exists()).toBe(false);
});
it.each`
digest | disabled | isDisabled
${'foo'} | ${true} | ${'true'}
${null} | ${true} | ${'true'}
${null} | ${false} | ${undefined}
${'foo'} | ${false} | ${undefined}
`(
'disabled attribute is set to $isDisabled when the digest $digest and disabled is $disabled',
({ digest, disabled, isDisabled }) => {
mountComponent({ tag: { ...tag, digest }, disabled });
expect(findCheckbox().attributes('disabled')).toBe(isDisabled);
},
);
it('is wired to the selected prop', () => {
mountComponent({ ...defaultProps, selected: true });
expect(findCheckbox().attributes('checked')).toBe('true');
});
it('when changed emit a select event', () => {
mountComponent();
findCheckbox().vm.$emit('change');
expect(wrapper.emitted('select')).toEqual([[]]);
});
});
describe('tag name', () => {
it('exists', () => {
mountComponent();
expect(findName().exists()).toBe(true);
});
it('has the correct text', () => {
mountComponent();
expect(findName().text()).toBe(tag.name);
});
it('has a tooltip', () => {
mountComponent();
const tooltip = getBinding(findName().element, 'gl-tooltip');
expect(tooltip.value.title).toBe(tag.name);
});
it('on mobile has mw-s class', () => {
mountComponent({ ...defaultProps, isMobile: true });
expect(findName().classes('mw-s')).toBe(true);
});
});
describe('clipboard button', () => {
it('exist if tag.location exist', () => {
mountComponent();
expect(findClipboardButton().exists()).toBe(true);
});
it('is hidden if tag does not have a location', () => {
mountComponent({ ...defaultProps, tag: { ...tag, location: null } });
expect(findClipboardButton().exists()).toBe(false);
});
it('has the correct props/attributes', () => {
mountComponent();
expect(findClipboardButton().attributes()).toMatchObject({
text: tag.location,
title: COPY_IMAGE_PATH_TITLE,
});
});
it('is disabled when the component is disabled', () => {
mountComponent({ ...defaultProps, disabled: true });
expect(findClipboardButton().attributes('disabled')).toBe('true');
});
});
describe('warning icon', () => {
it('is normally hidden', () => {
mountComponent();
expect(findWarningIcon().exists()).toBe(false);
});
it('is shown when the tag is broken', () => {
mountComponent({ tag: { ...tag, digest: null } });
expect(findWarningIcon().exists()).toBe(true);
});
it('has an appropriate tooltip', () => {
mountComponent({ tag: { ...tag, digest: null } });
const tooltip = getBinding(findWarningIcon().element, 'gl-tooltip');
expect(tooltip.value.title).toBe(MISSING_MANIFEST_WARNING_TOOLTIP);
});
});
describe('size', () => {
it('exists', () => {
mountComponent();
expect(findSize().exists()).toBe(true);
});
it('contains the totalSize and layers', () => {
mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1024', layers: 10 } });
expect(findSize().text()).toMatchInterpolatedText('1.00 KiB · 10 layers');
});
it('when totalSize is giantic', () => {
mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1099511627776', layers: 2 } });
expect(findSize().text()).toMatchInterpolatedText('1024.00 GiB · 2 layers');
});
it('when totalSize is missing', () => {
mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '0', layers: 10 } });
expect(findSize().text()).toMatchInterpolatedText(`${NOT_AVAILABLE_SIZE} · 10 layers`);
});
it('when layers are missing', () => {
mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1024' } });
expect(findSize().text()).toMatchInterpolatedText('1.00 KiB');
});
it('when there is 1 layer', () => {
mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '0', layers: 1 } });
expect(findSize().text()).toMatchInterpolatedText(`${NOT_AVAILABLE_SIZE} · 1 layer`);
});
});
describe('time', () => {
it('exists', () => {
mountComponent();
expect(findTime().exists()).toBe(true);
});
it('has the correct text', () => {
mountComponent();
expect(findTime().text()).toBe('Published');
});
it('contains time_ago_tooltip component', () => {
mountComponent();
expect(findTimeAgoTooltip().exists()).toBe(true);
});
it('pass the correct props to time ago tooltip', () => {
mountComponent();
expect(findTimeAgoTooltip().attributes()).toMatchObject({ time: tag.createdAt });
});
});
describe('digest', () => {
it('exists', () => {
mountComponent();
expect(findShortRevision().exists()).toBe(true);
});
it('has the correct text', () => {
mountComponent();
expect(findShortRevision().text()).toMatchInterpolatedText('Digest: 2cf3d2f');
});
it(`displays ${NOT_AVAILABLE_TEXT} when digest is missing`, () => {
mountComponent({ tag: { ...tag, digest: null } });
expect(findShortRevision().text()).toMatchInterpolatedText(`Digest: ${NOT_AVAILABLE_TEXT}`);
});
});
describe('additional actions menu', () => {
it('exists', () => {
mountComponent();
expect(findAdditionalActionsMenu().exists()).toBe(true);
});
it('has the correct props', () => {
mountComponent();
expect(findAdditionalActionsMenu().props()).toMatchObject({
icon: 'ellipsis_v',
text: 'More actions',
textSrOnly: true,
category: 'tertiary',
right: true,
});
});
it.each`
canDelete | digest | disabled | buttonDisabled
${true} | ${null} | ${true} | ${true}
${false} | ${'foo'} | ${true} | ${true}
${false} | ${null} | ${true} | ${true}
${true} | ${'foo'} | ${true} | ${true}
${true} | ${'foo'} | ${false} | ${false}
`(
'is $visible that is visible when canDelete is $canDelete and digest is $digest and disabled is $disabled',
({ canDelete, digest, disabled, buttonDisabled }) => {
mountComponent({ ...defaultProps, tag: { ...tag, canDelete, digest }, disabled });
expect(findAdditionalActionsMenu().props('disabled')).toBe(buttonDisabled);
expect(findAdditionalActionsMenu().classes('gl-opacity-0')).toBe(buttonDisabled);
expect(findAdditionalActionsMenu().classes('gl-pointer-events-none')).toBe(buttonDisabled);
},
);
describe('delete button', () => {
it('exists and has the correct attrs', () => {
mountComponent();
expect(findDeleteButton().exists()).toBe(true);
expect(findDeleteButton().attributes()).toMatchObject({
variant: 'danger',
});
expect(findDeleteButton().text()).toBe(REMOVE_TAG_BUTTON_TITLE);
});
it('delete event emits delete', () => {
mountComponent();
findDeleteButton().vm.$emit('click');
expect(wrapper.emitted('delete')).toEqual([[]]);
});
});
});
describe('details rows', () => {
describe('when the tag has a digest', () => {
it('has 3 details rows', async () => {
mountComponent();
await nextTick();
expect(findDetailsRows().length).toBe(3);
});
describe.each`
name | finderFunction | text | icon | clipboard
${'published date detail'} | ${findPublishedDateDetail} | ${'Published to the gitlab-org/gitlab-test/rails-12009 image repository at 13:29:38 UTC on 2020-11-03'} | ${'clock'} | ${false}
${'manifest detail'} | ${findManifestDetail} | ${'Manifest digest: sha256:2cf3d2fdac1b04a14301d47d51cb88dcd26714c74f91440eeee99ce399089062'} | ${'log'} | ${true}
${'configuration detail'} | ${findConfigurationDetail} | ${'Configuration digest: sha256:c2613843ab33aabf847965442b13a8b55a56ae28837ce182627c0716eb08c02b'} | ${'cloud-gear'} | ${true}
`('$name details row', ({ finderFunction, text, icon, clipboard }) => {
it(`has ${text} as text`, async () => {
mountComponent();
await nextTick();
expect(finderFunction().text()).toMatchInterpolatedText(text);
});
it(`has the ${icon} icon`, async () => {
mountComponent();
await nextTick();
expect(finderFunction().props('icon')).toBe(icon);
});
if (clipboard) {
it(`clipboard button exist`, async () => {
mountComponent();
await nextTick();
expect(finderFunction().findComponent(ClipboardButton).exists()).toBe(clipboard);
});
it('is disabled when the component is disabled', async () => {
mountComponent({ ...defaultProps, disabled: true });
await nextTick();
expect(finderFunction().findComponent(ClipboardButton).attributes('disabled')).toBe(
'true',
);
});
}
});
});
describe('when the tag does not have a digest', () => {
it('hides the details rows', async () => {
mountComponent({ tag: { ...tag, digest: null } });
await nextTick();
expect(findDetailsRows().length).toBe(0);
});
});
});
});
|