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
|
import { GlSkeletonLoader } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import Vue from 'vue';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import ArtifactsApp from '~/artifacts/components/app.vue';
import JobArtifactsTable from '~/artifacts/components/job_artifacts_table.vue';
import getBuildArtifactsSizeQuery from '~/artifacts/graphql/queries/get_build_artifacts_size.query.graphql';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { PAGE_TITLE, TOTAL_ARTIFACTS_SIZE, SIZE_UNKNOWN } from '~/artifacts/constants';
const TEST_BUILD_ARTIFACTS_SIZE = 1024;
const TEST_PROJECT_PATH = 'project/path';
const TEST_PROJECT_ID = 'gid://gitlab/Project/22';
const createBuildArtifactsSizeResponse = (buildArtifactsSize) => ({
data: {
project: {
__typename: 'Project',
id: TEST_PROJECT_ID,
statistics: {
__typename: 'ProjectStatistics',
buildArtifactsSize,
},
},
},
});
Vue.use(VueApollo);
describe('ArtifactsApp component', () => {
let wrapper;
let apolloProvider;
let getBuildArtifactsSizeSpy;
const findTitle = () => wrapper.findByTestId('artifacts-page-title');
const findBuildArtifactsSize = () => wrapper.findByTestId('build-artifacts-size');
const findJobArtifactsTable = () => wrapper.findComponent(JobArtifactsTable);
const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
const createComponent = () => {
wrapper = shallowMountExtended(ArtifactsApp, {
provide: { projectPath: 'project/path' },
apolloProvider,
});
};
beforeEach(() => {
getBuildArtifactsSizeSpy = jest.fn();
apolloProvider = createMockApollo([[getBuildArtifactsSizeQuery, getBuildArtifactsSizeSpy]]);
});
describe('when loading', () => {
beforeEach(() => {
// Promise that never resolves so it's always loading
getBuildArtifactsSizeSpy.mockReturnValue(new Promise(() => {}));
createComponent();
});
it('shows the page title', () => {
expect(findTitle().text()).toBe(PAGE_TITLE);
});
it('shows a skeleton while loading the artifacts size', () => {
expect(findSkeletonLoader().exists()).toBe(true);
});
it('shows the job artifacts table', () => {
expect(findJobArtifactsTable().exists()).toBe(true);
});
it('does not show message', () => {
expect(findBuildArtifactsSize().text()).toBe('');
});
it('calls apollo query', () => {
expect(getBuildArtifactsSizeSpy).toHaveBeenCalledWith({ projectPath: TEST_PROJECT_PATH });
});
});
describe.each`
buildArtifactsSize | expectedText
${TEST_BUILD_ARTIFACTS_SIZE} | ${numberToHumanSize(TEST_BUILD_ARTIFACTS_SIZE)}
${null} | ${SIZE_UNKNOWN}
`('when buildArtifactsSize is $buildArtifactsSize', ({ buildArtifactsSize, expectedText }) => {
beforeEach(async () => {
getBuildArtifactsSizeSpy.mockResolvedValue(
createBuildArtifactsSizeResponse(buildArtifactsSize),
);
createComponent();
await waitForPromises();
});
it('hides loader', () => {
expect(findSkeletonLoader().exists()).toBe(false);
});
it('shows the size', () => {
expect(findBuildArtifactsSize().text()).toMatchInterpolatedText(
`${TOTAL_ARTIFACTS_SIZE} ${expectedText}`,
);
});
});
});
|