Skip to content

Commit

Permalink
[Backport 2.x] Unit tests for public components (#416) (#433)
Browse files Browse the repository at this point in the history
* Unit tests for public components (#383)

* [FEATURE] Detector must have at least one alert set #288

Signed-off-by: Jovan Cvetkovic <[email protected]>

* [BUG] Create detector | Interval field can be empty #378

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Adjust styling for Finding details flyout #369

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* detector unit tests

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Feature/update vertical domain #372

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383
[BUG] Detector Edit | Custom rule are not selected on update rules #406

Signed-off-by: Jovan Cvetkovic <[email protected]>

* Unit tests for public components #383
[BUG] Detector Edit | Custom rule are not selected on update rules #406

Signed-off-by: Jovan Cvetkovic <[email protected]>

* PR code review

Signed-off-by: Jovan Cvetkovic <[email protected]>

* PR code review

Signed-off-by: Jovan Cvetkovic <[email protected]>

---------

Signed-off-by: Jovan Cvetkovic <[email protected]>
(cherry picked from commit 0150c89)

* Backport/backport 383 to 2.x units fix (#425)

* unit tests fix

Signed-off-by: Jovan Cvetkovic <[email protected]>

* unit tests fix

Signed-off-by: Jovan Cvetkovic <[email protected]>

---------

Signed-off-by: Jovan Cvetkovic <[email protected]>

* fixed mock (#430)

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* Updated snapshot for 383 backport (#431)

* fixed mock

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* updated snapshot

Signed-off-by: Amardeepsingh Siglani <[email protected]>

---------

Signed-off-by: Amardeepsingh Siglani <[email protected]>

---------

Signed-off-by: Jovan Cvetkovic <[email protected]>
Signed-off-by: Amardeepsingh Siglani <[email protected]>
Co-authored-by: Jovan Cvetkovic <[email protected]>
Co-authored-by: Amardeepsingh Siglani <[email protected]>
(cherry picked from commit b5e53ab)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] authored Feb 22, 2023
1 parent 2180730 commit 6bf3efe
Show file tree
Hide file tree
Showing 95 changed files with 27,341 additions and 115 deletions.
2 changes: 1 addition & 1 deletion models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Rule {

export interface Detector {
id?: string;
type: 'detector';
type: string;
detector_type: string;
name: string;
enabled: boolean;
Expand Down
1 change: 1 addition & 0 deletions public/components/DeleteModal/DeleteModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('<DeleteModal /> spec', () => {
type={'some type'}
/>
);

expect(tree).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions public/components/FormFieldHeader/FormFieldHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FormFieldHeader } from './FormFieldHeader';
describe('<FormFieldHeader /> spec', () => {
it('renders the component', () => {
const tree = render(<FormFieldHeader headerTitle={'some title'} />);

expect(tree).toMatchSnapshot();
});
});
8 changes: 4 additions & 4 deletions public/components/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { EuiButton, EuiOverlayMask, EuiModal } from '@elastic/eui';
import { render, fireEvent } from '@testing-library/react';
import ModalRoot from './ModalRoot';
import { ModalConsumer, ModalProvider } from './Modal';
import { ServicesConsumer, ServicesContext } from '../../services/Services';
import { browserServicesMock } from '../../../test/mocks';
import { ServicesConsumer, ServicesContext } from '../../services';
import services from '../../../test/mocks/services';

describe('<ModalRoot /> spec', () => {
it('renders nothing when not used', () => {
const { container } = render(
<ServicesContext.Provider value={browserServicesMock}>
<ServicesContext.Provider value={services}>
<ModalProvider>
<ServicesConsumer>
{(services) => services && <ModalRoot services={services} />}
Expand All @@ -34,7 +34,7 @@ describe('<ModalRoot /> spec', () => {
);
const { queryByText, getByTestId, getByLabelText } = render(
<div>
<ServicesContext.Provider value={browserServicesMock}>
<ServicesContext.Provider value={services}>
<ModalProvider>
<ServicesConsumer>
{(services) => services && <ModalRoot services={services} />}
Expand Down
16 changes: 16 additions & 0 deletions public/pages/Alerts/components/AlertFlyout/AlertFlyout.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';
import { AlertFlyout } from './AlertFlyout';
import alertFlyoutMock from '../../../../../test/mocks/Alerts/components/AlertFlyout/AlertFlyout.mock';

describe('<AlertFlyout /> spec', () => {
it('renders the component', () => {
const { container } = render(<AlertFlyout {...alertFlyoutMock} />);
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<AlertFlyout /> spec renders the component 1`] = `
<div
aria-hidden="true"
data-aria-hidden="true"
/>
`;
28 changes: 28 additions & 0 deletions public/pages/Alerts/containers/Alerts/Alerts.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import Alerts from './Alerts';
import contextMock from '../../../../../test/mocks/useContext.mock';
import { mount } from 'enzyme';
import alertsMock from '../../../../../test/mocks/Alerts/Alerts.mock';
import { shallowToJson } from 'enzyme-to-json';
import { Router } from 'react-router-dom';
import browserHistoryMock from '../../../../../test/mocks/services/browserHistory.mock';

describe('<Alerts /> spec', () => {
it('renders the component', () => {
Alerts.WrappedComponent.contextType = contextMock;
const wrapper = mount(
<Router history={browserHistoryMock}>
<Alerts {...alertsMock} />
</Router>,
{
context: contextMock,
}
);
expect(shallowToJson(wrapper.root().children())).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion public/pages/Alerts/containers/Alerts/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const groupByOptions = [
{ text: 'Alert severity', value: 'severity' },
];

class Alerts extends Component<AlertsProps, AlertsState> {
export class Alerts extends Component<AlertsProps, AlertsState> {
static contextType = CoreServicesContext;

constructor(props: AlertsProps) {
Expand Down
Loading

0 comments on commit 6bf3efe

Please sign in to comment.