-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.test.tsx
115 lines (93 loc) · 3.34 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* 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 { render } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../../../../common/mock';
import type { EuiHealthProps } from '@elastic/eui';
import { EuiHealth } from '@elastic/eui';
import { euiThemeVars } from '@kbn/ui-theme';
import { RiskSeverity } from '../../../../../../common/search_strategy';
import { RiskScore } from '.';
import { SEVERITY_COLOR } from '../../../../../overview/components/detection_response/utils';
jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');
return {
...jest.requireActual('@elastic/eui'),
EuiHealth: jest.fn((props: EuiHealthProps) => <original.EuiHealth {...props} />),
};
});
describe('RiskScore', () => {
const context = {};
it('renders critical severity risk score', () => {
const { container } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.critical} />
</TestProviders>
);
expect(container).toHaveTextContent(RiskSeverity.critical);
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith(
expect.objectContaining({ color: SEVERITY_COLOR.critical }),
context
);
});
it('renders hight severity risk score', () => {
const { container } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.high} />
</TestProviders>
);
expect(container).toHaveTextContent(RiskSeverity.high);
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith(
expect.objectContaining({ color: SEVERITY_COLOR.high }),
context
);
});
it('renders moderate severity risk score', () => {
const { container } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.moderate} />
</TestProviders>
);
expect(container).toHaveTextContent(RiskSeverity.moderate);
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith(
expect.objectContaining({ color: SEVERITY_COLOR.medium }),
context
);
});
it('renders low severity risk score', () => {
const { container } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.low} />
</TestProviders>
);
expect(container).toHaveTextContent(RiskSeverity.low);
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith(
expect.objectContaining({ color: SEVERITY_COLOR.low }),
context
);
});
it('renders unknown severity risk score', () => {
const { container } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.unknown} />
</TestProviders>
);
expect(container).toHaveTextContent(RiskSeverity.unknown);
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith(
expect.objectContaining({ color: euiThemeVars.euiColorMediumShade }),
context
);
});
it("doesn't render background-color when hideBackgroundColor is true", () => {
const { queryByTestId } = render(
<TestProviders>
<RiskScore severity={RiskSeverity.critical} hideBackgroundColor />
</TestProviders>
);
expect(queryByTestId('risk-score')).toHaveStyleRule('background-color', undefined);
});
});