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
|
import { PROJECT_STORAGE_TYPES } from '~/usage_quotas/storage/constants';
import {
getStorageTypesFromProjectStatistics,
descendingStorageUsageSort,
} from '~/usage_quotas/storage/utils';
import { mockGetProjectStorageStatisticsGraphQLResponse } from './mock_data';
describe('getStorageTypesFromProjectStatistics', () => {
const {
statistics: projectStatistics,
statisticsDetailsPaths,
} = mockGetProjectStorageStatisticsGraphQLResponse.data.project;
describe('matches project statistics value with matching storage type', () => {
const typesWithStats = getStorageTypesFromProjectStatistics(
PROJECT_STORAGE_TYPES,
projectStatistics,
);
it.each(PROJECT_STORAGE_TYPES)('storage type: $id', ({ id }) => {
expect(typesWithStats).toContainEqual(
expect.objectContaining({
id,
value: projectStatistics[`${id}Size`],
}),
);
});
});
it('adds helpPath to a relevant type', () => {
const helpLinks = PROJECT_STORAGE_TYPES.reduce((acc, { id }) => {
return {
...acc,
[id]: `url://${id}`,
};
}, {});
const typesWithStats = getStorageTypesFromProjectStatistics(
PROJECT_STORAGE_TYPES,
projectStatistics,
{},
helpLinks,
);
typesWithStats.forEach((type) => {
expect(type.helpPath).toBe(helpLinks[type.id]);
});
});
it('adds details page path', () => {
const typesWithStats = getStorageTypesFromProjectStatistics(
PROJECT_STORAGE_TYPES,
projectStatistics,
statisticsDetailsPaths,
{},
);
typesWithStats.forEach((type) => {
expect(type.detailsPath).toBe(statisticsDetailsPaths[type.id]);
});
});
});
describe('descendingStorageUsageSort', () => {
it('sorts items by a given key in descending order', () => {
const items = [{ k: 1 }, { k: 3 }, { k: 2 }];
const sorted = [...items].sort(descendingStorageUsageSort('k'));
const expectedSorted = [{ k: 3 }, { k: 2 }, { k: 1 }];
expect(sorted).toEqual(expectedSorted);
});
});
|