From b5e53ab8a429db3348947e8224ec0356cf436731 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:38:41 -0800 Subject: [PATCH] [Backport 2.x] Unit tests for public components (#416) * Unit tests for public components (#383) * [FEATURE] Detector must have at least one alert set #288 Signed-off-by: Jovan Cvetkovic * [BUG] Create detector | Interval field can be empty #378 Signed-off-by: Jovan Cvetkovic * Adjust styling for Finding details flyout #369 Signed-off-by: Jovan Cvetkovic * unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * detector unit tests Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * unit tests review Signed-off-by: Jovan Cvetkovic * Feature/update vertical domain #372 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 [BUG] Detector Edit | Custom rule are not selected on update rules #406 Signed-off-by: Jovan Cvetkovic * Unit tests for public components #383 [BUG] Detector Edit | Custom rule are not selected on update rules #406 Signed-off-by: Jovan Cvetkovic * PR code review Signed-off-by: Jovan Cvetkovic * PR code review Signed-off-by: Jovan Cvetkovic --------- Signed-off-by: Jovan Cvetkovic (cherry picked from commit 0150c89a263e13d19d91e527e86cafea2da2bc96) * Backport/backport 383 to 2.x units fix (#425) * unit tests fix Signed-off-by: Jovan Cvetkovic * unit tests fix Signed-off-by: Jovan Cvetkovic --------- Signed-off-by: Jovan Cvetkovic * fixed mock (#430) Signed-off-by: Amardeepsingh Siglani * Updated snapshot for 383 backport (#431) * fixed mock Signed-off-by: Amardeepsingh Siglani * updated snapshot Signed-off-by: Amardeepsingh Siglani --------- Signed-off-by: Amardeepsingh Siglani --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Amardeepsingh Siglani Co-authored-by: Jovan Cvetkovic Co-authored-by: Amardeepsingh Siglani --- models/interfaces.ts | 2 +- .../DeleteModal/DeleteModal.test.tsx | 1 + .../FormFieldHeader/FormFieldHeader.test.tsx | 1 + public/components/Modal/Modal.test.tsx | 8 +- .../AlertFlyout/AlertFlyout.test.tsx | 16 + .../__snapshots__/AlertFlyout.test.tsx.snap | 8 + .../Alerts/containers/Alerts/Alerts.test.tsx | 28 + .../pages/Alerts/containers/Alerts/Alerts.tsx | 2 +- .../Alerts/__snapshots__/Alerts.test.tsx.snap | 2392 +++++++++ .../AlertConditionPanel.test.tsx | 16 + .../AlertConditionPanel.test.tsx.snap | 1536 ++++++ .../AlertTriggerView.test.tsx | 17 + .../AlertTriggerView.test.tsx.snap | 786 +++ .../DetectorBasicDetailsView.test.tsx | 17 + .../DetectorBasicDetailsView.test.tsx.snap | 750 +++ .../DetectorRulesView.test.tsx | 22 + .../DetectorRulesView.test.tsx.snap | 1865 +++++++ .../FieldMappingsView.test.tsx | 17 + .../FieldMappingsView.test.tsx.snap | 468 ++ .../UpdateAlertConditions.test.tsx | 31 + .../UpdateAlertConditions.test.tsx.snap | 1153 +++++ .../UpdateDetectorBasicDetails.test.tsx | 27 + .../UpdateDetectorBasicDetails.test.tsx.snap | 1870 +++++++ .../UpdateFieldMappings.test.tsx | 23 + .../UpdateFieldMappings.test.tsx.snap | 186 + .../UpdateRules/UpdateDetectorRules.test.tsx | 17 + .../UpdateDetectorRules.test.tsx.snap | 814 +++ .../AlertTriggersView.test.tsx | 22 + .../AlertTriggersView.test.tsx.snap | 2759 +++++++++++ .../Detector/DetectorDetails.test.tsx | 24 + .../DetectorDetails.test.tsx.snap | 4352 +++++++++++++++++ .../DetectorDetailsView.test.tsx | 22 + .../DetectorDetailsView.test.tsx.snap | 3101 ++++++++++++ .../containers/Detectors/Detectors.test.tsx | 24 + .../containers/Detectors/Detectors.tsx | 2 +- .../__snapshots__/Detectors.test.tsx.snap | 2558 ++++++++++ .../FieldMappings/EditFieldMappings.test.tsx | 22 + .../EditFieldMappings.test.tsx.snap | 1104 +++++ public/pages/Overview/utils/helper.test.ts | 8 +- public/utils/helpers.tsx | 2 +- test/jest.config.js | 1 + test/mocks/Alerts/AlertItem.mock.ts | 18 + test/mocks/Alerts/Alerts.mock.ts | 24 + test/mocks/Alerts/PeriodSchedule.mock.ts | 13 + .../AlertFlyout/AlertFlyout.mock.ts | 22 + test/mocks/Alerts/index.ts | 16 + .../AlertCondition/AlertCondition.mock.ts | 27 + .../AlertConditionPanel.mock.ts | 30 + .../AlertCondition/TriggerAction.mock.ts | 25 + test/mocks/CreateDetector/index.ts | 14 + .../AlertTriggerView/AlertTriggerView.mock.ts | 17 + .../DetectorBasicDetailsView.mock.ts | 15 + .../DetectorRulesView.mock.ts | 15 + .../FieldMappingsView/FieldMapping.mock.ts | 11 + .../FieldMappingsView.mock.ts | 11 + .../UpdateAlertConditions.mock.ts | 27 + .../UpdateDetectorBasicDetails.mock.ts | 18 + .../UpdateDetectorRules.mock.ts | 16 + .../UpdateFieldMappings.mock.ts | 21 + .../AlertTriggersView.mock.ts | 14 + .../DetectorDetails/DetectorDetails.mock.ts | 22 + .../DetectorDetailsView.mock.ts | 18 + .../containers/Detectors/Detector.mock.ts | 27 + .../containers/Detectors/DetectorHit.mock.ts | 13 + .../Detectors/DetectorInput.mock.ts | 16 + .../Detectors/DetectorResponse.mock.ts | 13 + .../containers/Detectors/Detectors.mock.ts | 13 + .../EditFieldMappings.mock.ts | 16 + test/mocks/Detectors/index.ts | 46 + test/mocks/Rules/RuleInfo.mock.ts | 16 + test/mocks/Rules/RuleOptions.mock.ts | 13 + test/mocks/Rules/RulePage.mock.ts | 10 + test/mocks/Rules/RuleSource.mock.ts | 12 + test/mocks/Rules/index.ts | 12 + test/mocks/browserServicesMock.ts | 24 - test/mocks/index.ts | 10 +- test/mocks/services/alertService.mock.ts | 15 + test/mocks/services/browserHistory.mock.ts | 12 + test/mocks/services/detectorService.mock.ts | 20 + .../services/fieldMappingService.mock.ts | 27 + test/mocks/services/findingsService.mock.ts | 16 + .../httpClient.mock.ts} | 1 - .../iLegacyCustomClusterClient.mock.ts | 15 + test/mocks/services/index.ts | 32 + test/mocks/services/indexService.mock.ts | 18 + .../NotificationChannelOption.mock.ts | 13 + .../NotificationChannelTypeOptions.mock.ts | 12 + .../notifications/NotificationsStart.mock.ts | 12 + test/mocks/services/notifications/index.ts | 9 + .../notificationsService.mock.ts | 18 + test/mocks/services/ruleService.mock.ts | 19 + .../mocks/services/savedObjectsClient.mock.ts | 16 + test/mocks/useContext.mock.ts | 68 + test/setup.jest.ts | 83 + yarn.lock | 341 +- 95 files changed, 27341 insertions(+), 115 deletions(-) create mode 100644 public/pages/Alerts/components/AlertFlyout/AlertFlyout.test.tsx create mode 100644 public/pages/Alerts/components/AlertFlyout/__snapshots__/AlertFlyout.test.tsx.snap create mode 100644 public/pages/Alerts/containers/Alerts/Alerts.test.tsx create mode 100644 public/pages/Alerts/containers/Alerts/__snapshots__/Alerts.test.tsx.snap create mode 100644 public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.test.tsx create mode 100644 public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/__snapshots__/AlertConditionPanel.test.tsx.snap create mode 100644 public/pages/Detectors/components/AlertTriggerView/AlertTriggerView.test.tsx create mode 100644 public/pages/Detectors/components/AlertTriggerView/__snapshots__/AlertTriggerView.test.tsx.snap create mode 100644 public/pages/Detectors/components/DetectorBasicDetailsView/DetectorBasicDetailsView.test.tsx create mode 100644 public/pages/Detectors/components/DetectorBasicDetailsView/__snapshots__/DetectorBasicDetailsView.test.tsx.snap create mode 100644 public/pages/Detectors/components/DetectorRulesView/DetectorRulesView.test.tsx create mode 100644 public/pages/Detectors/components/DetectorRulesView/__snapshots__/DetectorRulesView.test.tsx.snap create mode 100644 public/pages/Detectors/components/FieldMappingsView/FieldMappingsView.test.tsx create mode 100644 public/pages/Detectors/components/FieldMappingsView/__snapshots__/FieldMappingsView.test.tsx.snap create mode 100644 public/pages/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.test.tsx create mode 100644 public/pages/Detectors/components/UpdateAlertConditions/__snapshots__/UpdateAlertConditions.test.tsx.snap create mode 100644 public/pages/Detectors/components/UpdateBasicDetails/UpdateDetectorBasicDetails.test.tsx create mode 100644 public/pages/Detectors/components/UpdateBasicDetails/__snapshots__/UpdateDetectorBasicDetails.test.tsx.snap create mode 100644 public/pages/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.test.tsx create mode 100644 public/pages/Detectors/components/UpdateFieldMappings/__snapshots__/UpdateFieldMappings.test.tsx.snap create mode 100644 public/pages/Detectors/components/UpdateRules/UpdateDetectorRules.test.tsx create mode 100644 public/pages/Detectors/components/UpdateRules/__snapshots__/UpdateDetectorRules.test.tsx.snap create mode 100644 public/pages/Detectors/containers/AlertTriggersView/AlertTriggersView.test.tsx create mode 100644 public/pages/Detectors/containers/AlertTriggersView/__snapshots__/AlertTriggersView.test.tsx.snap create mode 100644 public/pages/Detectors/containers/Detector/DetectorDetails.test.tsx create mode 100644 public/pages/Detectors/containers/Detector/__snapshots__/DetectorDetails.test.tsx.snap create mode 100644 public/pages/Detectors/containers/DetectorDetailsView/DetectorDetailsView.test.tsx create mode 100644 public/pages/Detectors/containers/DetectorDetailsView/__snapshots__/DetectorDetailsView.test.tsx.snap create mode 100644 public/pages/Detectors/containers/Detectors/Detectors.test.tsx create mode 100644 public/pages/Detectors/containers/Detectors/__snapshots__/Detectors.test.tsx.snap create mode 100644 public/pages/Detectors/containers/FieldMappings/EditFieldMappings.test.tsx create mode 100644 public/pages/Detectors/containers/FieldMappings/__snapshots__/EditFieldMappings.test.tsx.snap create mode 100644 test/mocks/Alerts/AlertItem.mock.ts create mode 100644 test/mocks/Alerts/Alerts.mock.ts create mode 100644 test/mocks/Alerts/PeriodSchedule.mock.ts create mode 100644 test/mocks/Alerts/components/AlertFlyout/AlertFlyout.mock.ts create mode 100644 test/mocks/Alerts/index.ts create mode 100644 test/mocks/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertCondition.mock.ts create mode 100644 test/mocks/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.mock.ts create mode 100644 test/mocks/CreateDetector/components/ConfigureAlerts/components/AlertCondition/TriggerAction.mock.ts create mode 100644 test/mocks/CreateDetector/index.ts create mode 100644 test/mocks/Detectors/components/AlertTriggerView/AlertTriggerView.mock.ts create mode 100644 test/mocks/Detectors/components/DetectorBasicDetailsView/DetectorBasicDetailsView.mock.ts create mode 100644 test/mocks/Detectors/components/DetectorRulesView/DetectorRulesView.mock.ts create mode 100644 test/mocks/Detectors/components/FieldMappingsView/FieldMapping.mock.ts create mode 100644 test/mocks/Detectors/components/FieldMappingsView/FieldMappingsView.mock.ts create mode 100644 test/mocks/Detectors/components/UpdateAlertConditions/UpdateAlertConditions.mock.ts create mode 100644 test/mocks/Detectors/components/UpdateDetectorBasicDetails/UpdateDetectorBasicDetails.mock.ts create mode 100644 test/mocks/Detectors/components/UpdateDetectorRules/UpdateDetectorRules.mock.ts create mode 100644 test/mocks/Detectors/components/UpdateFieldMappings/UpdateFieldMappings.mock.ts create mode 100644 test/mocks/Detectors/containers/AlertTriggersView/AlertTriggersView.mock.ts create mode 100644 test/mocks/Detectors/containers/DetectorDetails/DetectorDetails.mock.ts create mode 100644 test/mocks/Detectors/containers/DetectorDetailsView/DetectorDetailsView.mock.ts create mode 100644 test/mocks/Detectors/containers/Detectors/Detector.mock.ts create mode 100644 test/mocks/Detectors/containers/Detectors/DetectorHit.mock.ts create mode 100644 test/mocks/Detectors/containers/Detectors/DetectorInput.mock.ts create mode 100644 test/mocks/Detectors/containers/Detectors/DetectorResponse.mock.ts create mode 100644 test/mocks/Detectors/containers/Detectors/Detectors.mock.ts create mode 100644 test/mocks/Detectors/containers/EditFieldMappings/EditFieldMappings.mock.ts create mode 100644 test/mocks/Detectors/index.ts create mode 100644 test/mocks/Rules/RuleInfo.mock.ts create mode 100644 test/mocks/Rules/RuleOptions.mock.ts create mode 100644 test/mocks/Rules/RulePage.mock.ts create mode 100644 test/mocks/Rules/RuleSource.mock.ts create mode 100644 test/mocks/Rules/index.ts delete mode 100644 test/mocks/browserServicesMock.ts create mode 100644 test/mocks/services/alertService.mock.ts create mode 100644 test/mocks/services/browserHistory.mock.ts create mode 100644 test/mocks/services/detectorService.mock.ts create mode 100644 test/mocks/services/fieldMappingService.mock.ts create mode 100644 test/mocks/services/findingsService.mock.ts rename test/mocks/{httpClientMock.ts => services/httpClient.mock.ts} (99%) create mode 100644 test/mocks/services/iLegacyCustomClusterClient.mock.ts create mode 100644 test/mocks/services/index.ts create mode 100644 test/mocks/services/indexService.mock.ts create mode 100644 test/mocks/services/notifications/NotificationChannelOption.mock.ts create mode 100644 test/mocks/services/notifications/NotificationChannelTypeOptions.mock.ts create mode 100644 test/mocks/services/notifications/NotificationsStart.mock.ts create mode 100644 test/mocks/services/notifications/index.ts create mode 100644 test/mocks/services/notifications/notificationsService.mock.ts create mode 100644 test/mocks/services/ruleService.mock.ts create mode 100644 test/mocks/services/savedObjectsClient.mock.ts create mode 100644 test/mocks/useContext.mock.ts diff --git a/models/interfaces.ts b/models/interfaces.ts index a2982c8fc..bf3f1ec71 100644 --- a/models/interfaces.ts +++ b/models/interfaces.ts @@ -20,7 +20,7 @@ export interface Rule { export interface Detector { id?: string; - type: 'detector'; + type: string; detector_type: string; name: string; enabled: boolean; diff --git a/public/components/DeleteModal/DeleteModal.test.tsx b/public/components/DeleteModal/DeleteModal.test.tsx index 4a187ea45..67d1561dc 100644 --- a/public/components/DeleteModal/DeleteModal.test.tsx +++ b/public/components/DeleteModal/DeleteModal.test.tsx @@ -17,6 +17,7 @@ describe(' spec', () => { type={'some type'} /> ); + expect(tree).toMatchSnapshot(); }); }); diff --git a/public/components/FormFieldHeader/FormFieldHeader.test.tsx b/public/components/FormFieldHeader/FormFieldHeader.test.tsx index a696d8830..0ce747854 100644 --- a/public/components/FormFieldHeader/FormFieldHeader.test.tsx +++ b/public/components/FormFieldHeader/FormFieldHeader.test.tsx @@ -10,6 +10,7 @@ import { FormFieldHeader } from './FormFieldHeader'; describe(' spec', () => { it('renders the component', () => { const tree = render(); + expect(tree).toMatchSnapshot(); }); }); diff --git a/public/components/Modal/Modal.test.tsx b/public/components/Modal/Modal.test.tsx index 3c844a174..04de2cecf 100644 --- a/public/components/Modal/Modal.test.tsx +++ b/public/components/Modal/Modal.test.tsx @@ -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(' spec', () => { it('renders nothing when not used', () => { const { container } = render( - + {(services) => services && } @@ -34,7 +34,7 @@ describe(' spec', () => { ); const { queryByText, getByTestId, getByLabelText } = render(
- + {(services) => services && } diff --git a/public/pages/Alerts/components/AlertFlyout/AlertFlyout.test.tsx b/public/pages/Alerts/components/AlertFlyout/AlertFlyout.test.tsx new file mode 100644 index 000000000..75f1d974e --- /dev/null +++ b/public/pages/Alerts/components/AlertFlyout/AlertFlyout.test.tsx @@ -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(' spec', () => { + it('renders the component', () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/public/pages/Alerts/components/AlertFlyout/__snapshots__/AlertFlyout.test.tsx.snap b/public/pages/Alerts/components/AlertFlyout/__snapshots__/AlertFlyout.test.tsx.snap new file mode 100644 index 000000000..025af3ff5 --- /dev/null +++ b/public/pages/Alerts/components/AlertFlyout/__snapshots__/AlertFlyout.test.tsx.snap @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` spec renders the component 1`] = ` +