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
|
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { GlFilteredSearchToken } from '@gitlab/ui';
import { s__ } from '~/locale';
import HarborDetailsPage from '~/packages_and_registries/harbor_registry/pages/details.vue';
import TagsLoader from '~/packages_and_registries/shared/components/tags_loader.vue';
import ArtifactsList from '~/packages_and_registries/harbor_registry/components/details/artifacts_list.vue';
import waitForPromises from 'helpers/wait_for_promises';
import DetailsHeader from '~/packages_and_registries/harbor_registry/components/details/details_header.vue';
import PersistedSearch from '~/packages_and_registries/shared/components/persisted_search.vue';
import { OPERATORS_IS } from '~/vue_shared/components/filtered_search_bar/constants';
import {
NAME_SORT_FIELD,
TOKEN_TYPE_TAG_NAME,
} from '~/packages_and_registries/harbor_registry/constants/index';
import { harborArtifactsResponse, harborArtifactsList, defaultConfig } from '../mock_data';
let mockHarborArtifactsResponse;
jest.mock('~/rest_api', () => ({
getHarborArtifacts: () => mockHarborArtifactsResponse,
}));
describe('Harbor Details Page', () => {
let wrapper;
const findTagsLoader = () => wrapper.findComponent(TagsLoader);
const findArtifactsList = () => wrapper.findComponent(ArtifactsList);
const findDetailsHeader = () => wrapper.findComponent(DetailsHeader);
const findPersistedSearch = () => wrapper.findComponent(PersistedSearch);
const waitForHarborDetailRequest = async () => {
await waitForPromises();
await nextTick();
};
const $route = {
params: {
project: 'test-project',
image: 'test-repository',
},
};
const breadCrumbState = {
updateName: jest.fn(),
updateHref: jest.fn(),
};
const defaultHeaders = {
'x-page': '1',
'X-Per-Page': '20',
'X-TOTAL': '1',
'X-Total-Pages': '1',
};
const mountComponent = ({ config = defaultConfig } = {}) => {
wrapper = shallowMount(HarborDetailsPage, {
mocks: {
$route,
},
provide() {
return {
breadCrumbState,
...config,
};
},
});
};
beforeEach(() => {
mockHarborArtifactsResponse = Promise.resolve({
data: harborArtifactsResponse,
headers: defaultHeaders,
});
});
afterEach(() => {
wrapper.destroy();
});
describe('when isLoading is true', () => {
it('shows the loader', () => {
mountComponent();
expect(findTagsLoader().exists()).toBe(true);
});
it('does not show the list', () => {
mountComponent();
expect(findArtifactsList().exists()).toBe(false);
});
});
describe('artifacts list', () => {
it('exists', async () => {
mountComponent();
findPersistedSearch().vm.$emit('update', { sort: 'NAME_ASC', filters: [] });
await waitForHarborDetailRequest();
expect(findArtifactsList().exists()).toBe(true);
});
it('has the correct props bound', async () => {
mountComponent();
findPersistedSearch().vm.$emit('update', { sort: 'NAME_ASC', filters: [] });
await waitForHarborDetailRequest();
expect(findArtifactsList().props()).toMatchObject({
isLoading: false,
filter: '',
artifacts: harborArtifactsList,
pageInfo: {
page: 1,
perPage: 20,
total: 1,
totalPages: 1,
},
});
});
});
describe('persisted search', () => {
it('has the correct props', () => {
mountComponent();
expect(findPersistedSearch().props()).toMatchObject({
sortableFields: [NAME_SORT_FIELD],
defaultOrder: NAME_SORT_FIELD.orderBy,
defaultSort: 'asc',
tokens: [
{
type: TOKEN_TYPE_TAG_NAME,
icon: 'tag',
title: s__('HarborRegistry|Tag'),
unique: true,
token: GlFilteredSearchToken,
operators: OPERATORS_IS,
},
],
});
});
});
describe('header', () => {
it('has the correct props', async () => {
mountComponent();
findPersistedSearch().vm.$emit('update', { sort: 'NAME_ASC', filters: [] });
await waitForHarborDetailRequest();
expect(findDetailsHeader().props()).toMatchObject({
imagesDetail: {
name: 'test-project/test-repository',
artifactCount: 1,
},
});
});
});
});
|