-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.test.tsx
95 lines (82 loc) · 3.08 KB
/
index.test.tsx
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { DARK_THEME } from '@elastic/charts';
import numeral from '@elastic/numeral';
import { render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { EMPTY_STAT } from '../../../../helpers';
import { alertIndexWithAllResults } from '../../../../mock/pattern_rollup/mock_alerts_pattern_rollup';
import { auditbeatWithAllResults } from '../../../../mock/pattern_rollup/mock_auditbeat_pattern_rollup';
import { packetbeatNoResults } from '../../../../mock/pattern_rollup/mock_packetbeat_pattern_rollup';
import { TestProviders } from '../../../../mock/test_providers/test_providers';
import { PatternRollup } from '../../../../types';
import { Props, IndicesDetails } from '.';
const defaultBytesFormat = '0,0.[0]b';
const formatBytes = (value: number | undefined) =>
value != null ? numeral(value).format(defaultBytesFormat) : EMPTY_STAT;
const defaultNumberFormat = '0,0.[000]';
const formatNumber = (value: number | undefined) =>
value != null ? numeral(value).format(defaultNumberFormat) : EMPTY_STAT;
const ilmPhases = ['hot', 'warm', 'unmanaged'];
const patterns = ['.alerts-security.alerts-default', 'auditbeat-*', 'packetbeat-*'];
const patternRollups: Record<string, PatternRollup> = {
'.alerts-security.alerts-default': alertIndexWithAllResults,
'auditbeat-*': auditbeatWithAllResults,
'packetbeat-*': packetbeatNoResults,
};
const patternIndexNames: Record<string, string[]> = {
'auditbeat-*': [
'.ds-auditbeat-8.6.1-2023.02.07-000001',
'auditbeat-custom-empty-index-1',
'auditbeat-custom-index-1',
],
'.alerts-security.alerts-default': ['.internal.alerts-security.alerts-default-000001'],
'packetbeat-*': [
'.ds-packetbeat-8.5.3-2023.02.04-000001',
'.ds-packetbeat-8.6.1-2023.02.04-000001',
],
};
const defaultProps: Props = {
addSuccessToast: jest.fn(),
canUserCreateAndReadCases: jest.fn(),
formatBytes,
formatNumber,
getGroupByFieldsOnClick: jest.fn(),
ilmPhases,
openCreateCaseFlyout: jest.fn(),
patternIndexNames,
patternRollups,
patterns,
selectedIndex: null,
setSelectedIndex: jest.fn(),
theme: DARK_THEME,
updatePatternIndexNames: jest.fn(),
updatePatternRollup: jest.fn(),
};
describe('IndicesDetails', () => {
beforeEach(async () => {
jest.clearAllMocks();
render(
<TestProviders>
<IndicesDetails {...defaultProps} />
</TestProviders>
);
await waitFor(() => {});
});
describe('rendering patterns', () => {
patterns.forEach((pattern) => {
test(`it renders the ${pattern} pattern`, () => {
expect(screen.getByTestId(`${pattern}PatternPanel`)).toBeInTheDocument();
});
});
});
describe('rendering spacers', () => {
test('it renders the expected number of spacers', () => {
expect(screen.getAllByTestId('bodyPatternSpacer')).toHaveLength(patterns.length - 1);
});
});
});