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
|
import { shallowMount, RouterLinkStub as RouterLink } from '@vue/test-utils';
import { GlIcon, GlSkeletonLoader } from '@gitlab/ui';
import HarborListRow from '~/packages_and_registries/harbor_registry/components/list/harbor_list_row.vue';
import ListItem from '~/vue_shared/components/registry/list_item.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import { harborImagesList } from '../../mock_data';
describe('Harbor List Row', () => {
let wrapper;
const item = harborImagesList[0];
const findDetailsLink = () => wrapper.findComponent(RouterLink);
const findClipboardButton = () => wrapper.findComponent(ClipboardButton);
const findArtifactsCount = () => wrapper.find('[data-testid="artifacts-count"]');
const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
const mountComponent = (props) => {
wrapper = shallowMount(HarborListRow, {
stubs: {
RouterLink,
ListItem,
},
propsData: {
item,
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
describe('image title and path', () => {
it('contains a link to the details page', () => {
mountComponent();
const link = findDetailsLink();
expect(link.text()).toBe(item.name);
expect(findDetailsLink().props('to')).toMatchObject({
name: 'details',
params: {
image: 'nginx',
project: 'nginx',
},
});
});
it('contains a clipboard button', () => {
mountComponent();
const button = findClipboardButton();
expect(button.exists()).toBe(true);
expect(button.props('text')).toBe(item.location);
expect(button.props('title')).toBe(item.location);
});
});
describe('artifacts count', () => {
it('exists', () => {
mountComponent();
expect(findArtifactsCount().exists()).toBe(true);
});
it('contains a package icon', () => {
mountComponent();
const icon = findArtifactsCount().findComponent(GlIcon);
expect(icon.exists()).toBe(true);
expect(icon.props('name')).toBe('package');
});
describe('loading state', () => {
it('shows a loader when metadataLoading is true', () => {
mountComponent({ metadataLoading: true });
expect(findSkeletonLoader().exists()).toBe(true);
});
it('hides the artifacts count while loading', () => {
mountComponent({ metadataLoading: true });
expect(findArtifactsCount().exists()).toBe(false);
});
});
describe('artifacts count text', () => {
it('with one artifact in the image', () => {
mountComponent({ item: { ...item, artifactCount: 1 } });
expect(findArtifactsCount().text()).toMatchInterpolatedText('1 artifact');
});
it('with more than one artifact in the image', () => {
mountComponent({ item: { ...item, artifactCount: 3 } });
expect(findArtifactsCount().text()).toMatchInterpolatedText('3 artifacts');
});
});
});
});
|