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
|
import { GlTableLite, GlPopover } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ProjectStorageDetail from '~/usage_quotas/storage/components/project_storage_detail.vue';
import {
containerRegistryPopoverId,
containerRegistryId,
uploadsPopoverId,
uploadsId,
} from '~/usage_quotas/storage/constants';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { projectData, projectHelpLinks } from '../mock_data';
describe('ProjectStorageDetail', () => {
let wrapper;
const { storageTypes } = projectData.storage;
const defaultProps = { storageTypes };
const createComponent = (props = {}) => {
wrapper = extendedWrapper(
mount(ProjectStorageDetail, {
propsData: {
...defaultProps,
...props,
},
provide: {
containerRegistryPopoverContent: 'Sample popover message',
},
}),
);
};
const generateStorageType = (id = 'buildArtifactsSize') => {
return {
storageType: {
id,
name: 'Test Name',
description: 'Test Description',
helpPath: '/test-type',
},
value: 400000,
};
};
const findTable = () => wrapper.findComponent(GlTableLite);
const findPopoverById = (id) =>
wrapper.findAllComponents(GlPopover).filter((p) => p.attributes('data-testid') === id);
const findContainerRegistryPopover = () => findPopoverById(containerRegistryPopoverId);
const findUploadsPopover = () => findPopoverById(uploadsPopoverId);
const findContainerRegistryWarningIcon = () => wrapper.find(`#${containerRegistryPopoverId}`);
const findUploadsWarningIcon = () => wrapper.find(`#${uploadsPopoverId}`);
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('with storage types', () => {
it.each(storageTypes)(
'renders table row correctly %o',
({ storageType: { id, name, description } }) => {
expect(wrapper.findByTestId(`${id}-name`).text()).toBe(name);
expect(wrapper.findByTestId(`${id}-description`).text()).toBe(description);
expect(wrapper.findByTestId(`${id}-icon`).props('name')).toBe(id);
expect(wrapper.findByTestId(`${id}-help-link`).attributes('href')).toBe(
projectHelpLinks[id.replace(`Size`, ``)],
);
},
);
it('should render items in order from the biggest usage size to the smallest', () => {
const rows = findTable().find('tbody').findAll('tr');
// Cloning array not to mutate the source
const sortedStorageTypes = [...storageTypes].sort((a, b) => b.value - a.value);
sortedStorageTypes.forEach((storageType, i) => {
const rowUsageAmount = rows.wrappers[i].find('td:last-child').text();
const expectedUsageAmount = numberToHumanSize(storageType.value, 1);
expect(rowUsageAmount).toBe(expectedUsageAmount);
});
});
});
describe('without storage types', () => {
beforeEach(() => {
createComponent({ storageTypes: [] });
});
it('should render the table header <th>', () => {
expect(findTable().find('th').exists()).toBe(true);
});
it('should not render any table data <td>', () => {
expect(findTable().find('td').exists()).toBe(false);
});
});
describe.each`
description | mockStorageTypes | rendersContainerRegistryPopover | rendersUploadsPopover
${'without any storage type that has popover'} | ${[generateStorageType()]} | ${false} | ${false}
${'with container registry storage type'} | ${[generateStorageType(containerRegistryId)]} | ${true} | ${false}
${'with uploads storage type'} | ${[generateStorageType(uploadsId)]} | ${false} | ${true}
${'with container registry and uploads storage types'} | ${[generateStorageType(containerRegistryId), generateStorageType(uploadsId)]} | ${true} | ${true}
`(
'$description',
({ mockStorageTypes, rendersContainerRegistryPopover, rendersUploadsPopover }) => {
beforeEach(() => {
createComponent({ storageTypes: mockStorageTypes });
});
it(`does ${
rendersContainerRegistryPopover ? '' : ' not'
} render container registry warning icon and popover`, () => {
expect(findContainerRegistryWarningIcon().exists()).toBe(rendersContainerRegistryPopover);
expect(findContainerRegistryPopover().exists()).toBe(rendersContainerRegistryPopover);
});
it(`does ${
rendersUploadsPopover ? '' : ' not'
} render container registry warning icon and popover`, () => {
expect(findUploadsWarningIcon().exists()).toBe(rendersUploadsPopover);
expect(findUploadsPopover().exists()).toBe(rendersUploadsPopover);
});
},
);
});
|