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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
import { GlKeysetPagination, GlEmptyState } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
import DeleteImage from '~/packages_and_registries/container_registry/explorer/components/delete_image.vue';
import DeleteAlert from '~/packages_and_registries/container_registry/explorer/components/details_page/delete_alert.vue';
import DetailsHeader from '~/packages_and_registries/container_registry/explorer/components/details_page/details_header.vue';
import PartialCleanupAlert from '~/packages_and_registries/container_registry/explorer/components/details_page/partial_cleanup_alert.vue';
import StatusAlert from '~/packages_and_registries/container_registry/explorer/components/details_page/status_alert.vue';
import TagsList from '~/packages_and_registries/container_registry/explorer/components/details_page/tags_list.vue';
import TagsLoader from '~/packages_and_registries/shared/components/tags_loader.vue';
import {
UNFINISHED_STATUS,
DELETE_SCHEDULED,
ALERT_DANGER_IMAGE,
MISSING_OR_DELETED_IMAGE_BREADCRUMB,
MISSING_OR_DELETED_IMAGE_TITLE,
MISSING_OR_DELETED_IMAGE_MESSAGE,
} from '~/packages_and_registries/container_registry/explorer/constants';
import deleteContainerRepositoryTagsMutation from '~/packages_and_registries/container_registry/explorer/graphql/mutations/delete_container_repository_tags.mutation.graphql';
import getContainerRepositoryDetailsQuery from '~/packages_and_registries/container_registry/explorer/graphql/queries/get_container_repository_details.query.graphql';
import getContainerRepositoryTagsQuery from '~/packages_and_registries/container_registry/explorer/graphql/queries/get_container_repository_tags.query.graphql';
import getContainerRepositoriesDetails from '~/packages_and_registries/container_registry/explorer/graphql/queries/get_container_repositories_details.query.graphql';
import component from '~/packages_and_registries/container_registry/explorer/pages/details.vue';
import Tracking from '~/tracking';
import {
graphQLImageDetailsMock,
graphQLDeleteImageRepositoryTagsMock,
graphQLProjectImageRepositoriesDetailsMock,
containerRepositoryMock,
graphQLEmptyImageDetailsMock,
tagsMock,
imageTagsMock,
} from '../mock_data';
import { DeleteModal } from '../stubs';
describe('Details Page', () => {
let wrapper;
let apolloProvider;
const findDeleteModal = () => wrapper.findComponent(DeleteModal);
const findPagination = () => wrapper.findComponent(GlKeysetPagination);
const findTagsLoader = () => wrapper.findComponent(TagsLoader);
const findTagsList = () => wrapper.findComponent(TagsList);
const findDeleteAlert = () => wrapper.findComponent(DeleteAlert);
const findDetailsHeader = () => wrapper.findComponent(DetailsHeader);
const findEmptyState = () => wrapper.findComponent(GlEmptyState);
const findPartialCleanupAlert = () => wrapper.findComponent(PartialCleanupAlert);
const findStatusAlert = () => wrapper.findComponent(StatusAlert);
const findDeleteImage = () => wrapper.findComponent(DeleteImage);
const routeId = 1;
const breadCrumbState = {
updateName: jest.fn(),
};
const defaultConfig = {
noContainersImage: 'noContainersImage',
projectListUrl: 'projectListUrl',
groupListUrl: 'groupListUrl',
isGroupPage: false,
};
const cleanTags = tagsMock.map((t) => {
const result = { ...t };
// eslint-disable-next-line no-underscore-dangle
delete result.__typename;
return result;
});
const waitForApolloRequestRender = async () => {
await waitForPromises();
await nextTick();
};
const mountComponent = ({
resolver = jest.fn().mockResolvedValue(graphQLImageDetailsMock()),
mutationResolver = jest.fn().mockResolvedValue(graphQLDeleteImageRepositoryTagsMock),
tagsResolver = jest.fn().mockResolvedValue(graphQLImageDetailsMock(imageTagsMock())),
detailsResolver = jest.fn().mockResolvedValue(graphQLProjectImageRepositoriesDetailsMock),
options,
config = defaultConfig,
} = {}) => {
Vue.use(VueApollo);
const requestHandlers = [
[getContainerRepositoryDetailsQuery, resolver],
[deleteContainerRepositoryTagsMutation, mutationResolver],
[getContainerRepositoryTagsQuery, tagsResolver],
[getContainerRepositoriesDetails, detailsResolver],
];
apolloProvider = createMockApollo(requestHandlers);
wrapper = shallowMount(component, {
apolloProvider,
stubs: {
DeleteModal,
DeleteImage,
},
mocks: {
$route: {
params: {
id: routeId,
},
},
},
provide() {
return {
breadCrumbState,
config,
};
},
...options,
});
};
beforeEach(() => {
jest.spyOn(Tracking, 'event');
});
describe('when isLoading is true', () => {
it('shows the loader', () => {
mountComponent();
expect(findTagsLoader().exists()).toBe(true);
});
it('does not show the list', () => {
mountComponent();
expect(findTagsList().exists()).toBe(false);
});
});
describe('when the image does not exist', () => {
it('does not show the default ui', async () => {
mountComponent({ resolver: jest.fn().mockResolvedValue(graphQLEmptyImageDetailsMock) });
await waitForApolloRequestRender();
expect(findTagsLoader().exists()).toBe(false);
expect(findDetailsHeader().exists()).toBe(false);
expect(findTagsList().exists()).toBe(false);
expect(findPagination().exists()).toBe(false);
});
it('shows an empty state message', async () => {
mountComponent({ resolver: jest.fn().mockResolvedValue(graphQLEmptyImageDetailsMock) });
await waitForApolloRequestRender();
expect(findEmptyState().props()).toMatchObject({
description: MISSING_OR_DELETED_IMAGE_MESSAGE,
svgPath: defaultConfig.noContainersImage,
title: MISSING_OR_DELETED_IMAGE_TITLE,
});
});
});
describe('list', () => {
it('exists', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findTagsList().exists()).toBe(true);
});
it('has the correct props bound', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findTagsList().props()).toMatchObject({
isMobile: false,
});
});
describe('deleteEvent', () => {
describe('single item', () => {
let tagToBeDeleted;
beforeEach(async () => {
mountComponent();
await waitForApolloRequestRender();
[tagToBeDeleted] = cleanTags;
findTagsList().vm.$emit('delete', [tagToBeDeleted]);
});
it('open the modal', async () => {
expect(DeleteModal.methods.show).toHaveBeenCalled();
});
it('tracks a single delete event', () => {
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'click_button', {
label: 'registry_tag_delete',
});
});
});
describe('multiple items', () => {
beforeEach(async () => {
mountComponent();
await waitForApolloRequestRender();
findTagsList().vm.$emit('delete', cleanTags);
});
it('open the modal', () => {
expect(DeleteModal.methods.show).toHaveBeenCalled();
});
it('tracks a single delete event', () => {
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'click_button', {
label: 'bulk_registry_tag_delete',
});
});
});
});
});
describe('modal', () => {
it('exists', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findDeleteModal().exists()).toBe(true);
});
describe('cancel event', () => {
it('tracks cancel_delete', async () => {
mountComponent();
await waitForApolloRequestRender();
findDeleteModal().vm.$emit('cancel');
expect(Tracking.event).toHaveBeenCalledWith(undefined, 'cancel_delete', {
label: 'registry_tag_delete',
});
});
});
describe('confirmDelete event', () => {
let mutationResolver;
let tagsResolver;
let detailsResolver;
beforeEach(() => {
mutationResolver = jest.fn().mockResolvedValue(graphQLDeleteImageRepositoryTagsMock);
tagsResolver = jest.fn().mockResolvedValue(graphQLImageDetailsMock(imageTagsMock()));
detailsResolver = jest.fn().mockResolvedValue(graphQLProjectImageRepositoriesDetailsMock);
mountComponent({ mutationResolver, tagsResolver, detailsResolver });
return waitForApolloRequestRender();
});
describe('when one item is selected to be deleted', () => {
it('calls apollo mutation with the right parameters and refetches the tags list query', async () => {
findTagsList().vm.$emit('delete', [cleanTags[0]]);
await nextTick();
findDeleteModal().vm.$emit('confirmDelete');
expect(mutationResolver).toHaveBeenCalledWith(
expect.objectContaining({ tagNames: [cleanTags[0].name] }),
);
await waitForPromises();
expect(tagsResolver).toHaveBeenCalled();
expect(detailsResolver).toHaveBeenCalled();
});
});
describe('when more than one item is selected to be deleted', () => {
it('calls apollo mutation with the right parameters and refetches the tags list query', async () => {
findTagsList().vm.$emit('delete', tagsMock);
await nextTick();
findDeleteModal().vm.$emit('confirmDelete');
expect(mutationResolver).toHaveBeenCalledWith(
expect.objectContaining({ tagNames: tagsMock.map((t) => t.name) }),
);
await waitForPromises();
expect(tagsResolver).toHaveBeenCalled();
expect(detailsResolver).toHaveBeenCalled();
});
});
});
});
describe('Header', () => {
it('exists', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findDetailsHeader().exists()).toBe(true);
});
it('has the correct props', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findDetailsHeader().props()).toMatchObject({
image: {
name: containerRepositoryMock.name,
project: {
visibility: containerRepositoryMock.project.visibility,
},
},
});
});
});
describe('Delete Alert', () => {
const config = {
isAdmin: true,
garbageCollectionHelpPagePath: 'baz',
};
const deleteAlertType = 'success_tag';
it('exists', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(findDeleteAlert().exists()).toBe(true);
});
it('has the correct props', async () => {
mountComponent({
options: {
data: () => ({
deleteAlertType,
}),
},
config,
});
await waitForApolloRequestRender();
expect(findDeleteAlert().props()).toEqual({ ...config, deleteAlertType });
});
});
describe('Partial Cleanup Alert', () => {
const config = {
runCleanupPoliciesHelpPagePath: 'foo',
expirationPolicyHelpPagePath: 'bar',
userCalloutsPath: 'call_out_path',
userCalloutId: 'call_out_id',
showUnfinishedTagCleanupCallout: true,
};
describe(`when expirationPolicyCleanupStatus is ${UNFINISHED_STATUS}`, () => {
let resolver;
beforeEach(() => {
resolver = jest.fn().mockResolvedValue(
graphQLImageDetailsMock({
expirationPolicyCleanupStatus: UNFINISHED_STATUS,
}),
);
});
it('exists', async () => {
mountComponent({ resolver, config });
await waitForApolloRequestRender();
expect(findPartialCleanupAlert().exists()).toBe(true);
});
it('has the correct props', async () => {
mountComponent({ resolver, config });
await waitForApolloRequestRender();
expect(findPartialCleanupAlert().props()).toEqual({
runCleanupPoliciesHelpPagePath: config.runCleanupPoliciesHelpPagePath,
cleanupPoliciesHelpPagePath: config.expirationPolicyHelpPagePath,
});
});
it('dismiss hides the component', async () => {
jest.spyOn(axios, 'post').mockReturnValue();
mountComponent({ resolver, config });
await waitForApolloRequestRender();
expect(findPartialCleanupAlert().exists()).toBe(true);
findPartialCleanupAlert().vm.$emit('dismiss');
await nextTick();
expect(axios.post).toHaveBeenCalledWith(config.userCalloutsPath, {
feature_name: config.userCalloutId,
});
expect(findPartialCleanupAlert().exists()).toBe(false);
});
it('is hidden if the callout is dismissed', async () => {
mountComponent({ resolver });
await waitForApolloRequestRender();
expect(findPartialCleanupAlert().exists()).toBe(false);
});
});
describe(`when expirationPolicyCleanupStatus is not ${UNFINISHED_STATUS}`, () => {
it('the component is hidden', async () => {
mountComponent({ config });
await waitForApolloRequestRender();
expect(findPartialCleanupAlert().exists()).toBe(false);
});
});
});
describe('Breadcrumb connection', () => {
it('when the details are fetched updates the name', async () => {
mountComponent();
await waitForApolloRequestRender();
expect(breadCrumbState.updateName).toHaveBeenCalledWith(containerRepositoryMock.name);
});
it(`when the image is missing set the breadcrumb to ${MISSING_OR_DELETED_IMAGE_BREADCRUMB}`, async () => {
mountComponent({ resolver: jest.fn().mockResolvedValue(graphQLEmptyImageDetailsMock) });
await waitForApolloRequestRender();
expect(breadCrumbState.updateName).toHaveBeenCalledWith(MISSING_OR_DELETED_IMAGE_BREADCRUMB);
});
it(`when the image has no name set the breadcrumb to project name`, async () => {
mountComponent({
resolver: jest
.fn()
.mockResolvedValue(graphQLImageDetailsMock({ ...containerRepositoryMock, name: null })),
});
await waitForApolloRequestRender();
expect(breadCrumbState.updateName).toHaveBeenCalledWith('gitlab-test');
});
});
describe('when the image has a status different from null', () => {
const resolver = jest
.fn()
.mockResolvedValue(graphQLImageDetailsMock({ status: DELETE_SCHEDULED }));
it('disables all the actions', async () => {
mountComponent({ resolver });
await waitForApolloRequestRender();
expect(findDetailsHeader().props('disabled')).toBe(true);
expect(findTagsList().props('disabled')).toBe(true);
});
it('shows a status alert', async () => {
mountComponent({ resolver });
await waitForApolloRequestRender();
expect(findStatusAlert().exists()).toBe(true);
expect(findStatusAlert().props()).toMatchObject({
status: DELETE_SCHEDULED,
});
});
});
describe('delete the image', () => {
const mountComponentAndDeleteImage = async () => {
mountComponent();
await waitForApolloRequestRender();
findDetailsHeader().vm.$emit('delete');
await nextTick();
};
it('on delete event it deletes the image', async () => {
await mountComponentAndDeleteImage();
findDeleteModal().vm.$emit('confirmDelete');
expect(findDeleteImage().emitted('start')).toEqual([[]]);
});
it('binds the correct props to the modal', async () => {
await mountComponentAndDeleteImage();
expect(findDeleteModal().props()).toMatchObject({
itemsToBeDeleted: [{ path: 'gitlab-org/gitlab-test/rails-12009' }],
deleteImage: true,
});
});
it('binds correctly to delete-image start and end events', async () => {
mountComponent();
findDeleteImage().vm.$emit('start');
await waitForPromises();
expect(findTagsLoader().exists()).toBe(true);
findDeleteImage().vm.$emit('end');
await nextTick();
expect(findTagsLoader().exists()).toBe(false);
});
it('binds correctly to delete-image error event', async () => {
mountComponent();
findDeleteImage().vm.$emit('error');
await nextTick();
expect(findDeleteAlert().props('deleteAlertType')).toBe(ALERT_DANGER_IMAGE);
});
});
});
|