Skip to content

Commit

Permalink
refactored some constants and added UTC as default timezone
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed May 18, 2022
1 parent c5d1789 commit f28e419
Show file tree
Hide file tree
Showing 8 changed files with 2,453 additions and 71 deletions.
3 changes: 3 additions & 0 deletions global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => {
process.env.TZ = 'UTC';
}
4 changes: 2 additions & 2 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ export type MonitorAlert = {
state: string;
error: string | null;
startTime: number;
endTime: number;
acknowledgedTime: number;
endTime: number | null;
acknowledgedTime: number | null;
};

export type AnomalySummary = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ describe('anomalyChartUtils function tests', () => {
totalAlerts: 1,
},
};
//TODO: change acknowledgedTime and endTime type to allow null values potentially
const alertConverted = [
{
monitorName: 'Example_monitor_name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import { render, waitFor } from '@testing-library/react';
import React from 'react';
import {
AnomaliesLiveChart,
} from '../AnomaliesLiveChart';
import { AnomaliesLiveChart } from '../AnomaliesLiveChart';
import { selectedDetectors } from '../../../../pages/utils/__tests__/constants';
import { Provider } from 'react-redux';
import { coreServicesMock } from '../../../../../test/mocks';
Expand Down Expand Up @@ -43,10 +41,6 @@ jest.mock('../../utils/utils', () => ({
visualizeAnomalyResultForXYChart: jest.fn(),
}));
describe('<AnomaliesLiveChart /> spec', () => {
beforeEach(() => {
jest.clearAllMocks();
});

test('AnomaliesLiveChart with Sample anomaly data', async () => {
const { container, getByTestId, getAllByText, getByText } = render(
<Provider store={mockedStore()}>
Expand All @@ -58,9 +52,13 @@ describe('<AnomaliesLiveChart /> spec', () => {
//mock current last update to a specific date so doesn't produce new snapshot each minute
Date.now = jest.fn().mockReturnValue(new Date('2021-06-06T12:33:37.000Z'));
await waitFor(() => {
expect(getByTestId('dashboardFullScreenButton').innerHTML.includes('euiIcon-isssLoaded'))
expect(
getByTestId('dashboardFullScreenButton').innerHTML.includes(
'euiIcon-isssLoaded'
)
);
});
await waitFor(()=> {})
await waitFor(() => {});
expect(container).toMatchSnapshot();
getAllByText('Detector with the most recent anomaly');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {
import { DetectorDefinitionFormikValues } from '../../../../models/interfaces';
import { FormikProps, Formik } from 'formik';
import { Provider } from 'react-redux';
import configureStore, { MockStore } from 'redux-mock-store';
import clientMiddleware from '../../../../../../redux/middleware/clientMiddleware';
import { AppState } from '../../../../../../reducers';
import { mockedStore } from '../../../../../../redux/utils/testUtils';

const initialState = {
opensearch: {
Expand Down Expand Up @@ -105,41 +103,40 @@ const formikProps = {
validateOnMount: true,
} as FormikProps<DetectorDefinitionFormikValues>;

const mockedStore = (mockState = initialState): MockStore<AppState> => {
const middlewares = [clientMiddleware(httpClientMock)];
const mockStore = configureStore<AppState>(middlewares);
const store = mockStore(mockState);
return store;
};
const renderWithProvider = () => ({
...render(
<Provider store={mockedStore(initialState)}>
<CoreServicesContext.Provider value={coreServicesMock}>
<Formik initialValues={values} onSubmit={jest.fn()}>
<DataFilter
formikProps={formikProps}
filter={filters}
index={0}
values={values}
replace={jest.fn()}
onOpen={() => {}}
onSave={jest.fn()}
onCancel={jest.fn()}
onDelete={jest.fn()}
openPopoverIndex={0}
setOpenPopoverIndex={jest.fn(() => 0)}
isNewFilter={true}
oldFilterType={undefined}
oldFilterQuery={undefined}
/>
</Formik>
</CoreServicesContext.Provider>
</Provider>
),
});

describe('dataFilter', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test('renders data filter', async () => {
const { container, getByText, getByTestId, getAllByText } = render(
<Provider store={mockedStore()}>
<CoreServicesContext.Provider value={coreServicesMock}>
<Formik initialValues={values} onSubmit={jest.fn()}>
<DataFilter
formikProps={formikProps}
filter={filters}
index={0}
values={values}
replace={jest.fn()}
onOpen={() => {}}
onSave={jest.fn()}
onCancel={jest.fn()}
onDelete={jest.fn()}
openPopoverIndex={0}
setOpenPopoverIndex={jest.fn(() => 0)}
isNewFilter={true}
oldFilterType={undefined}
oldFilterQuery={undefined}
/>
</Formik>
</CoreServicesContext.Provider>
</Provider>
);
const { container, getByText, getByTestId, getAllByText } =
renderWithProvider();
expect(container).toMatchSnapshot();
getByText('Create custom label?');
getByText('Operator');
Expand All @@ -155,30 +152,7 @@ describe('dataFilter', () => {
userEvent.click(getByTestId('cancelFilter0Button'));
}, 10000);
test('renders data filter, click on custom', async () => {
const { container, getByText, getByTestId } = render(
<Provider store={mockedStore()}>
<CoreServicesContext.Provider value={coreServicesMock}>
<Formik initialValues={values} onSubmit={jest.fn()}>
<DataFilter
formikProps={formikProps}
filter={filters}
index={0}
values={values}
replace={jest.fn()}
onOpen={() => {}}
onSave={jest.fn()}
onCancel={jest.fn()}
onDelete={jest.fn()}
openPopoverIndex={0}
setOpenPopoverIndex={jest.fn(() => 0)}
isNewFilter={true}
oldFilterType={undefined}
oldFilterQuery={undefined}
/>
</Formik>
</CoreServicesContext.Provider>
</Provider>
);
const { container, getByText, getByTestId } = renderWithProvider();
getByText('Create custom label?');
getByText('Operator');
userEvent.click(getByTestId('filterTypeButton'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const featureQuery2 = {
} as { [key: string]: any };

describe('<DetectorConfig /> spec', () => {
test.skip('renders the component', () => {
test('renders the component', () => {
const randomDetector = {
...getRandomDetector(false),
};
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('<DetectorConfig /> spec', () => {
);
});

test.skip('renders the component with 2 custom and 1 simple features', () => {
test('renders the component with 2 custom and 1 simple features', () => {
const randomDetector = {
...getRandomDetector(true),
featureAttributes: [
Expand Down
Loading

0 comments on commit f28e419

Please sign in to comment.