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
|
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import DetailsHeader from '~/packages_and_registries/harbor_registry/components/details/details_header.vue';
import TitleArea from '~/vue_shared/components/registry/title_area.vue';
import { ROOT_IMAGE_TEXT } from '~/packages_and_registries/harbor_registry/constants/index';
describe('Harbor Details Header', () => {
let wrapper;
const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"]`);
const findTitle = () => findByTestId('title');
const findArtifactsCount = () => findByTestId('artifacts-count');
const mountComponent = ({ propsData }) => {
wrapper = shallowMount(DetailsHeader, {
propsData,
stubs: {
TitleArea,
},
});
};
afterEach(() => {
wrapper.destroy();
});
describe('artifact name', () => {
describe('missing image name', () => {
beforeEach(() => {
mountComponent({ propsData: { imagesDetail: { name: '', artifactCount: 1 } } });
});
it('root image', () => {
expect(findTitle().text()).toBe(ROOT_IMAGE_TEXT);
});
});
describe('with artifact name present', () => {
beforeEach(() => {
mountComponent({ propsData: { imagesDetail: { name: 'shao/flinkx', artifactCount: 1 } } });
});
it('shows artifact.name', () => {
expect(findTitle().text()).toContain('shao/flinkx');
});
});
});
describe('metadata items', () => {
describe('artifacts count', () => {
it('displays "-- artifacts" while loading', async () => {
mountComponent({ propsData: { imagesDetail: {} } });
await nextTick();
expect(findArtifactsCount().props('text')).toBe('-- artifacts');
});
it('when there is more than one artifact has the correct text', async () => {
mountComponent({ propsData: { imagesDetail: { name: 'shao/flinkx', artifactCount: 10 } } });
await nextTick();
expect(findArtifactsCount().props('text')).toBe('10 artifacts');
});
it('when there is one artifact has the correct text', async () => {
mountComponent({
propsData: { imagesDetail: { name: 'shao/flinkx', artifactCount: 1 } },
});
await nextTick();
expect(findArtifactsCount().props('text')).toBe('1 artifact');
});
it('has the correct icon', async () => {
mountComponent({
propsData: { imagesDetail: { name: 'shao/flinkx', artifactCount: 1 } },
});
await nextTick();
expect(findArtifactsCount().props('icon')).toBe('package');
});
});
});
});
|