Skip to content

Commit f95f52b

Browse files
authored
added UT for validation API related components (#252)
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
1 parent 96a0ab2 commit f95f52b

File tree

40 files changed

+6365
-134
lines changed

40 files changed

+6365
-134
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A clear and concise description of the bug.
1111

1212
**How can one reproduce the bug?**
1313
Steps to reproduce the behavior:
14+
1415
1. Go to '...'
1516
2. Click on '....'
1617
3. Scroll down to '....'
@@ -20,9 +21,10 @@ Steps to reproduce the behavior:
2021
A clear and concise description of what you expected to happen.
2122

2223
**What is your host/environment?**
23-
- OS: [e.g. iOS]
24-
- Version [e.g. 22]
25-
- Plugins
24+
25+
- OS: [e.g. iOS]
26+
- Version [e.g. 22]
27+
- Plugins
2628

2729
**Do you have any screenshots?**
2830
If applicable, add screenshots to help explain your problem.

.github/ISSUE_TEMPLATE/feature_request.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: '[FEATURE]'
55
labels: 'enhancement, untriaged'
66
assignees: ''
77
---
8+
89
**Is your feature request related to a problem?**
910
A clear and concise description of what the problem is, e.g. _I'm always frustrated when [...]_
1011

@@ -15,4 +16,4 @@ A clear and concise description of what you want to happen.
1516
A clear and concise description of any alternative solutions or features you've considered.
1617

1718
**Do you have any additional context?**
18-
Add any other context or screenshots about the feature request here.
19+
Add any other context or screenshots about the feature request here.

global-setup.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default () => {
2+
process.env.TZ = 'UTC';
3+
}

public/components/CodeModal/__tests__/CodeModal.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import React from 'react';
1313
import { render } from '@testing-library/react';
1414
import { CodeModal } from '../CodeModal';
1515

16-
describe('CodeMOdal spec', () => {
16+
describe('CodeModal spec', () => {
1717
const onVisibilityChange = jest.fn(() => true);
1818
const onCloseModal = jest.fn();
1919

public/components/CodeModal/__tests__/__snapshots__/CodeModal.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`CodeMOdal spec renders the component 1`] = `
3+
exports[`CodeModal spec renders the component 1`] = `
44
<div
55
aria-hidden="true"
66
data-aria-hidden="true"

public/components/ContentPanel/ContentPanel.test.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,30 @@ describe('<ContentPanel /> spec', () => {
3838
getByText('Hello');
3939
getByText('World');
4040
});
41+
42+
test('renders array title', () => {
43+
const { getByText } = render(
44+
<ContentPanel
45+
title={['testing-1', 'testing-2']}
46+
actions={[<div>Hello</div>, <div>World</div>]}
47+
>
48+
<div>Testing ContentPanel</div>
49+
</ContentPanel>
50+
);
51+
getByText('testing-1');
52+
getByText('testing-2');
53+
});
54+
test('renders array subtitle', () => {
55+
const { getByText } = render(
56+
<ContentPanel
57+
title="Testing"
58+
subTitle={['testing-1', 'testing-2']}
59+
actions={[<div>Hello</div>, <div>World</div>]}
60+
>
61+
<div>Testing ContentPanel</div>
62+
</ContentPanel>
63+
);
64+
getByText('testing-1');
65+
getByText('testing-2');
66+
});
4167
});

public/components/ContentPanel/ContentPanel.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const ContentPanel = (props: ContentPanelProps) => {
4949
);
5050
return (
5151
<EuiPanel
52-
style={{ padding: '20px'}}
52+
style={{ padding: '20px' }}
5353
className={props.contentPanelClassName}
5454
>
5555
<EuiFlexGroup
@@ -133,9 +133,7 @@ const ContentPanel = (props: ContentPanelProps) => {
133133
margin="s"
134134
className={props.horizontalRuleClassName}
135135
/>
136-
<div style={{ padding: '10px 0px' }}>
137-
{props.children}
138-
</div>
136+
<div style={{ padding: '10px 0px' }}>{props.children}</div>
139137
</div>
140138
) : null}
141139
</EuiPanel>

public/models/interfaces.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ export type MonitorAlert = {
189189
triggerName: string;
190190
severity: number;
191191
state: string;
192-
error: string;
192+
error: string | null;
193193
startTime: number;
194-
endTime: number;
195-
acknowledgedTime: number;
194+
endTime: number | null;
195+
acknowledgedTime: number | null;
196196
};
197197

198198
export type AnomalySummary = {

public/pages/AnomalyCharts/containers/__tests__/__snapshots__/AnomalyHeatmapChart.test.tsx.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,14 @@ exports[`<AnomalyHeatmapChart /> spec AnomalyHeatmapChart with anomaly summaries
434434
xmlns="http://www.w3.org/2000/svg"
435435
>
436436
<path
437-
d="M7.5 11.508L7.468 8H6.25V7h2.401l.03 3.508H9.8v1H7.5zm-.25-6.202a.83.83 0 01.207-.577c.137-.153.334-.229.59-.229.256 0 .454.076.594.23.14.152.209.345.209.576 0 .228-.07.417-.21.568-.14.15-.337.226-.593.226-.256 0-.453-.075-.59-.226a.81.81 0 01-.207-.568zM8 13A5 5 0 108 3a5 5 0 000 10zm0 1A6 6 0 118 2a6 6 0 010 12z"
437+
d="M13.6 12.186l-1.357-1.358c-.025-.025-.058-.034-.084-.056.53-.794.84-1.746.84-2.773a4.977 4.977 0 00-.84-2.772c.026-.02.059-.03.084-.056L13.6 3.813a6.96 6.96 0 010 8.373zM8 15A6.956 6.956 0 013.814 13.6l1.358-1.358c.025-.025.034-.057.055-.084C6.02 12.688 6.974 13 8 13a4.978 4.978 0 002.773-.84c.02.026.03.058.056.083l1.357 1.358A6.956 6.956 0 018 15zm-5.601-2.813a6.963 6.963 0 010-8.373l1.359 1.358c.024.025.057.035.084.056A4.97 4.97 0 003 8c0 1.027.31 1.98.842 2.773-.027.022-.06.031-.084.056l-1.36 1.358zm5.6-.187A4 4 0 118 4a4 4 0 010 8zM8 1c1.573 0 3.019.525 4.187 1.4l-1.357 1.358c-.025.025-.035.057-.056.084A4.979 4.979 0 008 3a4.979 4.979 0 00-2.773.842c-.021-.027-.03-.059-.055-.084L3.814 2.4A6.957 6.957 0 018 1zm0-1a8.001 8.001 0 10.003 16.002A8.001 8.001 0 008 0z"
438438
fill-rule="evenodd"
439439
/>
440440
</svg>
441441
<span
442442
class="euiCallOutHeader__title"
443443
>
444-
No anomalies found in the specified date range.
444+
Choose a filled rectangle in the heat map for a more detailed view of anomalies within that entity.
445445
</span>
446446
</div>
447447
</div>
@@ -931,14 +931,14 @@ exports[`<AnomalyHeatmapChart /> spec AnomalyHeatmapChart with multiple category
931931
xmlns="http://www.w3.org/2000/svg"
932932
>
933933
<path
934-
d="M7.5 11.508L7.468 8H6.25V7h2.401l.03 3.508H9.8v1H7.5zm-.25-6.202a.83.83 0 01.207-.577c.137-.153.334-.229.59-.229.256 0 .454.076.594.23.14.152.209.345.209.576 0 .228-.07.417-.21.568-.14.15-.337.226-.593.226-.256 0-.453-.075-.59-.226a.81.81 0 01-.207-.568zM8 13A5 5 0 108 3a5 5 0 000 10zm0 1A6 6 0 118 2a6 6 0 010 12z"
934+
d="M13.6 12.186l-1.357-1.358c-.025-.025-.058-.034-.084-.056.53-.794.84-1.746.84-2.773a4.977 4.977 0 00-.84-2.772c.026-.02.059-.03.084-.056L13.6 3.813a6.96 6.96 0 010 8.373zM8 15A6.956 6.956 0 013.814 13.6l1.358-1.358c.025-.025.034-.057.055-.084C6.02 12.688 6.974 13 8 13a4.978 4.978 0 002.773-.84c.02.026.03.058.056.083l1.357 1.358A6.956 6.956 0 018 15zm-5.601-2.813a6.963 6.963 0 010-8.373l1.359 1.358c.024.025.057.035.084.056A4.97 4.97 0 003 8c0 1.027.31 1.98.842 2.773-.027.022-.06.031-.084.056l-1.36 1.358zm5.6-.187A4 4 0 118 4a4 4 0 010 8zM8 1c1.573 0 3.019.525 4.187 1.4l-1.357 1.358c-.025.025-.035.057-.056.084A4.979 4.979 0 008 3a4.979 4.979 0 00-2.773.842c-.021-.027-.03-.059-.055-.084L3.814 2.4A6.957 6.957 0 018 1zm0-1a8.001 8.001 0 10.003 16.002A8.001 8.001 0 008 0z"
935935
fill-rule="evenodd"
936936
/>
937937
</svg>
938938
<span
939939
class="euiCallOutHeader__title"
940940
>
941-
No anomalies found in the specified date range.
941+
Choose a filled rectangle in the heat map for a more detailed view of anomalies within that entity.
942942
</span>
943943
</div>
944944
</div>
@@ -1516,14 +1516,14 @@ exports[`<AnomalyHeatmapChart /> spec AnomalyHeatmapChart with one category fiel
15161516
xmlns="http://www.w3.org/2000/svg"
15171517
>
15181518
<path
1519-
d="M7.5 11.508L7.468 8H6.25V7h2.401l.03 3.508H9.8v1H7.5zm-.25-6.202a.83.83 0 01.207-.577c.137-.153.334-.229.59-.229.256 0 .454.076.594.23.14.152.209.345.209.576 0 .228-.07.417-.21.568-.14.15-.337.226-.593.226-.256 0-.453-.075-.59-.226a.81.81 0 01-.207-.568zM8 13A5 5 0 108 3a5 5 0 000 10zm0 1A6 6 0 118 2a6 6 0 010 12z"
1519+
d="M13.6 12.186l-1.357-1.358c-.025-.025-.058-.034-.084-.056.53-.794.84-1.746.84-2.773a4.977 4.977 0 00-.84-2.772c.026-.02.059-.03.084-.056L13.6 3.813a6.96 6.96 0 010 8.373zM8 15A6.956 6.956 0 013.814 13.6l1.358-1.358c.025-.025.034-.057.055-.084C6.02 12.688 6.974 13 8 13a4.978 4.978 0 002.773-.84c.02.026.03.058.056.083l1.357 1.358A6.956 6.956 0 018 15zm-5.601-2.813a6.963 6.963 0 010-8.373l1.359 1.358c.024.025.057.035.084.056A4.97 4.97 0 003 8c0 1.027.31 1.98.842 2.773-.027.022-.06.031-.084.056l-1.36 1.358zm5.6-.187A4 4 0 118 4a4 4 0 010 8zM8 1c1.573 0 3.019.525 4.187 1.4l-1.357 1.358c-.025.025-.035.057-.056.084A4.979 4.979 0 008 3a4.979 4.979 0 00-2.773.842c-.021-.027-.03-.059-.055-.084L3.814 2.4A6.957 6.957 0 018 1zm0-1a8.001 8.001 0 10.003 16.002A8.001 8.001 0 008 0z"
15201520
fill-rule="evenodd"
15211521
/>
15221522
</svg>
15231523
<span
15241524
class="euiCallOutHeader__title"
15251525
>
1526-
No anomalies found in the specified date range.
1526+
Choose a filled rectangle in the heat map for a more detailed view of anomalies within that entity.
15271527
</span>
15281528
</div>
15291529
</div>

public/pages/AnomalyCharts/utils/__tests__/anomalyChartUtils.test.ts

+84-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
//@ts-ignore
1313
import moment from 'moment';
14-
import { getAnomalySummary } from '../anomalyChartUtils';
14+
import {
15+
getAnomalySummary,
16+
convertAlerts,
17+
generateAlertAnnotations,
18+
} from '../anomalyChartUtils';
19+
import { httpClientMock, coreServicesMock } from '../../../../../test/mocks';
20+
import { MonitorAlert } from '../../../../models/interfaces';
1521

1622
describe('anomalyChartUtils', () => {
1723
describe('getAnomalySummary', () => {
@@ -75,3 +81,80 @@ describe('anomalyChartUtils', () => {
7581
});
7682
});
7783
});
84+
85+
describe('anomalyChartUtils function tests', () => {
86+
const alertResponse = {
87+
response: {
88+
alerts: [
89+
{
90+
id: 'eQURa3gBKo1jAh6qUo49',
91+
version: 300,
92+
monitor_id: 'awUMa3gBKo1jAh6qu47E',
93+
schema_version: 2,
94+
monitor_version: 2,
95+
monitor_name: 'Example_monitor_name',
96+
monitor_user: {
97+
name: 'admin',
98+
backend_roles: ['admin'],
99+
roles: ['all_access', 'own_index'],
100+
custom_attribute_names: [],
101+
user_requested_tenant: null,
102+
},
103+
trigger_id: 'bQUQa3gBKo1jAh6qnY6G',
104+
trigger_name: 'Example_trigger_name',
105+
state: 'ACTIVE',
106+
error_message: null,
107+
alert_history: [
108+
{
109+
timestamp: 1617314504873,
110+
message: 'Example error emssage',
111+
},
112+
{
113+
timestamp: 1617312543925,
114+
message: 'Example error message',
115+
},
116+
],
117+
severity: 1,
118+
action_execution_results: [
119+
{
120+
action_id: 'bgUQa3gBKo1jAh6qnY6G',
121+
last_execution_time: 1617317979908,
122+
throttled_count: 0,
123+
},
124+
],
125+
start_time: 1616704000492,
126+
last_notification_time: 1617317979908,
127+
end_time: null,
128+
acknowledged_time: null,
129+
},
130+
],
131+
totalAlerts: 1,
132+
},
133+
};
134+
const alertConverted = [
135+
{
136+
monitorName: 'Example_monitor_name',
137+
triggerName: 'Example_trigger_name',
138+
severity: 1,
139+
state: 'ACTIVE',
140+
error: null,
141+
startTime: 1616704000492,
142+
endTime: null,
143+
acknowledgedTime: null,
144+
},
145+
] as MonitorAlert[];
146+
test('convertAlerts', () => {
147+
expect(convertAlerts(alertResponse)).toStrictEqual(alertConverted);
148+
});
149+
test('generateAlertAnnotations', () => {
150+
const alertsConverted = generateAlertAnnotations(alertConverted);
151+
expect(alertsConverted).toStrictEqual([
152+
{
153+
dataValue: 1616704000492,
154+
details:
155+
'There is a severity 1 alert with state ACTIVE from 03/25/21 08:26:40 PM.',
156+
header: '03/25/21 08:26:40 PM',
157+
},
158+
]);
159+
});
160+
});

public/pages/AnomalyCharts/utils/anomalyChartUtils.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ export const getEntityAnomaliesHeatmapData = (
406406
singleAnomalySummary.startTime >= timeWindow.startDate &&
407407
singleAnomalySummary.startTime < timeWindow.endDate
408408
);
409-
410409
if (isEmpty(anomalySummaryInTimeRange)) {
411410
maxAnomalyGradesForEntity.push(0);
412411
numAnomalyGradesForEntity.push(0);

public/pages/ConfigureModel/containers/__tests__/ConfigureModel.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('<ConfigureModel /> spec', () => {
6464
test('validate all required fields', async () => {
6565
const { getByText } = renderWithRouter();
6666
fireEvent.click(getByText('Next'));
67-
await waitFor(()=>{});
67+
await waitFor(() => {});
6868
getByText('You must enter a feature name');
6969
getByText('You must select a field');
7070
});

public/pages/Dashboard/Components/AnomaliesLiveChart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => {
128128
ALL_CUSTOM_AD_RESULT_INDICES,
129129
false
130130
);
131-
132131
setLiveAnomalyData(latestLiveAnomalyResult);
133132

134133
setLatestLiveAnomalousDetectorsCount(
@@ -144,6 +143,7 @@ export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => {
144143
} else {
145144
setLastAnomalyResult(undefined);
146145
}
146+
147147
setLiveTimeRange({
148148
startDateTime: moment().subtract(31, 'minutes'),
149149
endDateTime: moment(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { render, waitFor } from '@testing-library/react';
7+
import React from 'react';
8+
import { AnomaliesLiveChart } from '../AnomaliesLiveChart';
9+
import { selectedDetectors } from '../../../../pages/utils/__tests__/constants';
10+
import { Provider } from 'react-redux';
11+
import { coreServicesMock } from '../../../../../test/mocks';
12+
import { CoreServicesContext } from '../../../../components/CoreServices/CoreServices';
13+
import { mockedStore } from '../../../../redux/utils/testUtils';
14+
const anomalyResponse = [
15+
{
16+
ok: true,
17+
response: {
18+
anomaly_grade: 0.10949221682655441,
19+
data_start_time: 1651817250642,
20+
data_end_time: 1651817310642,
21+
detector_id: 'gtU2l4ABuV34PY9ITTdm',
22+
name: 'test2',
23+
},
24+
},
25+
];
26+
const anomalyResultQuery = [
27+
{
28+
anomaly_grade: 0.10949221682655441,
29+
data_start_time: 1651817250642,
30+
data_end_time: 1651817310642,
31+
detector_id: 'gtU2l4ABuV34PY9ITTdm',
32+
},
33+
];
34+
35+
jest.mock('../../utils/utils', () => ({
36+
getLatestAnomalyResultsForDetectorsByTimeRange: jest.fn(
37+
() => anomalyResponse
38+
),
39+
getFloorPlotTime: jest.fn(() => 1651817250642),
40+
getLatestAnomalyResultsByTimeRange: jest.fn(() => anomalyResultQuery),
41+
visualizeAnomalyResultForXYChart: jest.fn(),
42+
}));
43+
describe('<AnomaliesLiveChart /> spec', () => {
44+
test('AnomaliesLiveChart with Sample anomaly data', async () => {
45+
const { container, getByTestId, getAllByText, getByText } = render(
46+
<Provider store={mockedStore()}>
47+
<CoreServicesContext.Provider value={coreServicesMock}>
48+
<AnomaliesLiveChart {...selectedDetectors} />
49+
</CoreServicesContext.Provider>
50+
</Provider>
51+
);
52+
//mock current last update to a specific date so doesn't produce new snapshot each minute
53+
Date.now = jest.fn().mockReturnValue(new Date('2021-06-06T12:33:37.000Z'));
54+
await waitFor(() => {
55+
expect(
56+
getByTestId('dashboardFullScreenButton').innerHTML.includes(
57+
'euiIcon-isssLoaded'
58+
)
59+
);
60+
});
61+
await waitFor(() => {});
62+
expect(container).toMatchSnapshot();
63+
getAllByText('Detector with the most recent anomaly');
64+
});
65+
});

0 commit comments

Comments
 (0)