From d6a44c6af32ebdd176dda7b89c950ff6acf7b932 Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Tue, 14 Sep 2021 17:48:58 -0700 Subject: [PATCH] Update jest unit tests (#112) * Update .opensearch_dashboards-plugin-helpers.json * Update snapshots * Update whereExpression.test and some snapshots * Update whereExpression.test and some snapshots Signed-off-by: Annie Lee * Update snapshots * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Add icon tooltip * Add test * Update tests * remove license * Update TriggerExpressions.test.js * Update Triggers.test.js * Update validation test * Update getOverviewStats.test.js * Update validate.test.js * Update helpers.test.js and remove unused import * Update Triggers.test.js * Update helpers.js * Update CreateMonitor test and clean up code * Update CreateMonitor test and clean up code Signed-off-by: Annie Lee * Update release note and adding more tests * Add test and modify cypress common-utils branch * Update MonitorDefinitionCard.test.js.snap * Update cypress-workflow.yml Signed-off-by: Annie Lee --- .github/workflows/cypress-workflow.yml | 4 +- .../__snapshots__/Breadcrumbs.test.js.snap | 2 +- .../__snapshots__/ContentPanel.test.js.snap | 8 + .../Flyout/__snapshots__/Flyout.test.js.snap | 1 + .../__snapshots__/flyouts.test.js.snap | 1 + .../FormikCheckableCard.test.js | 38 ++ .../FormikCheckableCard.test.js.snap | 70 +++ .../FormikCodeEditor/FormikCodeEditor.test.js | 12 +- .../FormikCodeEditor.test.js.snap | 70 +++ .../IconToolTip/IconToolTip.test.js | 22 + .../__snapshots__/IconToolTip.test.js.snap | 11 + .../FeatureChart/FeatureChart.test.js | 50 ++ .../__snapshots__/FeatureChart.test.js.snap | 3 + .../ExtractionQuery/ExtractionQuery.test.js | 10 +- .../ExtractionQuery.test.js.snap | 111 ++++ .../MonitorDefinition.test.js.snap | 82 +-- .../MonitorDefinitionCard.js | 2 +- .../MonitorDefinitionCard.test.js | 39 ++ .../MonitorDefinitionCard.test.js.snap | 303 ++++++++++ .../MonitorExpressions.test.js | 2 +- .../MonitorExpressions.test.js.snap | 343 +++++++++--- .../expressions/WhereExpression.test.js | 7 +- .../__snapshots__/ForExpression.test.js.snap | 109 +++- .../WhereExpression.test.js.snap | 63 ++- .../MonitorTimeField/MonitorTimeField.test.js | 2 +- .../MonitorTimeField.test.js.snap | 114 ++-- .../MonitorType/MonitorType.test.js | 27 + .../__snapshots__/MonitorType.test.js.snap | 158 ++++++ .../QueryPerformance.test.js.snap | 151 +++-- .../__snapshots__/Frequencies.test.js.snap | 22 +- .../components/VisualGraph/VisualGraph.js | 1 - .../__snapshots__/VisualGraph.test.js.snap | 10 +- .../VisualGraph/utils/helpers.test.js | 53 +- .../AnomalyDetector.test.js.snap | 48 ++ .../CreateMonitor/CreateMonitor.test.js | 11 +- .../__snapshots__/CreateMonitor.test.js.snap | 8 + .../formikToMonitor.test.js.snap | 40 +- .../__snapshots__/DefineMonitor.test.js.snap | 239 ++++---- .../__snapshots__/MonitorIndex.test.js.snap | 44 +- .../__snapshots__/Message.test.js.snap | 204 ++++--- .../TriggerExpressions.test.js | 40 -- .../TriggerExpressions.test.js.snap | 106 +--- .../__snapshots__/TriggerQuery.test.js.snap | 159 +++--- .../utils/formikToTrigger.test.js | 32 +- .../DefineTrigger/utils/validation.js | 1 + .../DefineTrigger/utils/validation.test.js | 11 +- .../DashboardControls.test.js.snap | 10 +- .../__snapshots__/Dashboard.test.js.snap | 527 +++++++++++++----- .../DestinationsList.test.js.snap | 228 +++++++- .../Home/__snapshots__/Home.test.js.snap | 2 +- .../Main/__snapshots__/Main.test.js.snap | 2 +- .../__snapshots__/EmptyHistory.test.js.snap | 4 +- .../MonitorOverview.test.js.snap | 14 +- .../utils/getOverviewStats.test.js | 4 +- .../containers/Triggers/Triggers.js | 1 + .../containers/Triggers/Triggers.test.js | 25 +- .../__snapshots__/Triggers.test.js.snap | 45 +- public/utils/validate.test.js | 29 +- ...dashboards-plugin.release-notes-1.1.0.0.md | 3 +- test/utils/helpers.js | 31 +- 60 files changed, 2779 insertions(+), 990 deletions(-) create mode 100644 public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js create mode 100644 public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap create mode 100644 public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap create mode 100644 public/components/IconToolTip/IconToolTip.test.js create mode 100644 public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap create mode 100644 public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 69c741ab7..727245837 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -30,7 +30,7 @@ jobs: with: repository: opensearch-project/OpenSearch path: OpenSearch - ref: '1.x' + ref: '1.1' - name: Build OpenSearch working-directory: ./OpenSearch run: ./gradlew publishToMavenLocal @@ -40,7 +40,7 @@ jobs: with: repository: opensearch-project/common-utils path: common-utils - ref: 'main' + ref: '1.1' - name: Build common-utils working-directory: ./common-utils run: ./gradlew publishToMavenLocal -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} diff --git a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap index cfb18b3a6..b3464dafd 100644 --- a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap +++ b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap @@ -38,7 +38,7 @@ Object { exports[`getBreadcrumb returns correct constant breadcrumbs 3`] = ` Object { "href": "/dashboard", - "text": "Dashboard", + "text": "Alerts", } `; diff --git a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap index b7314cf62..96b1926d8 100644 --- a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap +++ b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap @@ -30,6 +30,14 @@ exports[`ContentPanel renders 1`] = ` +
+
+

diff --git a/public/components/Flyout/__snapshots__/Flyout.test.js.snap b/public/components/Flyout/__snapshots__/Flyout.test.js.snap index 9c9f5c7f1..5b62ba8f3 100644 --- a/public/components/Flyout/__snapshots__/Flyout.test.js.snap +++ b/public/components/Flyout/__snapshots__/Flyout.test.js.snap @@ -48,6 +48,7 @@ exports[`Flyout renders 1`] = `
  • diff --git a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap index d720a4c16..0fc5f3de4 100644 --- a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap +++ b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap @@ -18,6 +18,7 @@ Object {
    • diff --git a/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js new file mode 100644 index 000000000..90c9f8efd --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; +import { Formik } from 'formik'; + +import FormikCheckableCard from './FormikCheckableCard'; + +describe('FormikCheckableCard', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('render', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap new file mode 100644 index 000000000..0bda3fa43 --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCheckableCard render 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +
      +`; + +exports[`FormikCheckableCard render formRow 1`] = ` +
      +
      +
      +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js index 71459fb57..95013b9e6 100644 --- a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js +++ b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js @@ -29,10 +29,20 @@ import { render } from 'enzyme'; import { Formik } from 'formik'; import FormikCodeEditor from './FormikCodeEditor'; +import FormikCheckableCard from '../FormikCheckableCard'; // FIXME: This has an issue where EuiCodeEditor is generating a random HTML id and failing snapshot test -describe.skip('FormikCodeEditor', () => { +describe('FormikCodeEditor', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); test('renders', () => { const component = ( diff --git a/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap new file mode 100644 index 000000000..c044cb2f4 --- /dev/null +++ b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCodeEditor render formRow 1`] = ` +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +`; + +exports[`FormikCodeEditor renders 1`] = ` +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +`; diff --git a/public/components/IconToolTip/IconToolTip.test.js b/public/components/IconToolTip/IconToolTip.test.js new file mode 100644 index 000000000..942ecaaa7 --- /dev/null +++ b/public/components/IconToolTip/IconToolTip.test.js @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import IconToolTip from './IconToolTip'; + +describe('IconToolTip', () => { + test('renders', () => { + const component = ; + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap new file mode 100644 index 000000000..26f77365e --- /dev/null +++ b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`IconToolTip renders 1`] = ` + +
      + EuiIconMock +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js new file mode 100644 index 000000000..d834b5cd9 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { mount, render } from 'enzyme'; +import { FeatureChart } from './FeatureChart'; +import AlertingFakes from '../../../../../../test/utils/helpers'; + +const alertingFakes = new AlertingFakes('random seed'); + +function getMountWrapper(customProps = {}) { + return mount( + + ); +} + +describe('FeatureChart', () => { + test('renders ', () => { + const component = ( + + ); + expect(render(component)).toMatchSnapshot(); + }); + + test('go to page ', () => { + const mountWrapper = getMountWrapper(); + mountWrapper.instance().goToPage(1); + expect(mountWrapper.instance().state.activePage).toBe(1); + }); +}); diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap new file mode 100644 index 000000000..306ae56b2 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FeatureChart renders 1`] = `null`; diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js index 20cb76414..87a3a006e 100644 --- a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js +++ b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js @@ -28,10 +28,16 @@ import React from 'react'; import { render } from 'enzyme'; import ExtractionQuery from './ExtractionQuery'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; -describe.skip('ExtractionQuery', () => { +describe('ExtractionQuery', () => { test('renders', () => { - const component = ; + const component = ( + + {() => } + + ); expect(render(component)).toMatchSnapshot(); }); diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap new file mode 100644 index 000000000..f9fd88ebb --- /dev/null +++ b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ExtractionQuery renders 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap index 45264816d..c30d92122 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap @@ -1,56 +1,58 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorDefinition renders 1`] = ` -
      +
      - -
      -
      + +
      -
      - + + + +
      -
      - EuiIconMock -
      - + +
      + EuiIconMock +
      +
      +
      diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js index cab7ee08b..02a5278d5 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js @@ -40,7 +40,7 @@ const onChangeDefinition = (e, form) => { form.setFieldValue('searchType', type, false); }; -const MonitorDefinitionCard = ({ values, resetResponse, plugins }) => { +const MonitorDefinitionCard = ({ values, plugins }) => { const hasADPlugin = plugins.indexOf(OS_AD_PLUGIN) !== -1; const isBucketLevelMonitor = values.monitor_type === MONITOR_TYPE.BUCKET_LEVEL; diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js new file mode 100644 index 000000000..a0f006265 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorDefinitionCard from './MonitorDefinitionCard'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; +import { OS_AD_PLUGIN } from '../../../../utils/constants'; + +describe('MonitorDefinitionCard', () => { + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap new file mode 100644 index 000000000..906c9d308 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap @@ -0,0 +1,303 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorDefinitionCard renders without AD plugin 1`] = ` +
      +
      +

      + Monitor defining method +

      +
      +
      +
      + Specify the way you want to define your query and triggers. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +`; + +exports[`MonitorDefinitionCard renders without AD plugin 2`] = ` +
      +
      +

      + Monitor defining method +

      +
      +
      +
      + Specify the way you want to define your query and triggers. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js index 0304babd3..195f6f937 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js @@ -35,7 +35,7 @@ describe('MonitorExpressions', () => { test('renders', () => { const component = ( - {() => {}} dataTypes={[]} ofEnabled={false} />} + {() => {}} dataTypes={[]} errors={{}} />} ); diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap index 443f5a876..f7f943fab 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap @@ -1,120 +1,317 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorExpressions renders 1`] = ` -
      +
      -
      + Metrics + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      + + - + + + +
      +
      +
      +
      + +
      +
      + You can add up to 1 metric.
      + class="euiSpacer euiSpacer--m" + /> +
      +
      + + Time range for the last + + +
      + EuiIconMock +
      +
      +
      +
      -
      +
      +
      +
      +
      +
      +
      - all documents - - + +
      + +
      + EuiIconMock +
      +
      +
      +
      +
      + class="euiSpacer euiSpacer--l" + /> +
      + + Data filter + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      +
      -
      + + + Add filter + + + +
      +
      + You can add up to 1 data filter.
      +
      + + Group by + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      +
      + No group bys defined. +
      +
      +
      + + + Add group by + + + +
      +
      +
      +
      +
      + You can add up to 1 group by.
      +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js index 45720aba2..1c2acd5d0 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js @@ -27,7 +27,7 @@ import React from 'react'; import { Formik } from 'formik'; import { render, mount } from 'enzyme'; -import { EuiExpression } from '@elastic/eui'; +import { EuiPopover } from '@elastic/eui'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; import WhereExpression from './WhereExpression'; @@ -65,7 +65,7 @@ describe('WhereExpression', () => { }); test('calls openExpression when clicking expression', () => { const wrapper = mount(getMountWrapper()); - const button = wrapper.find(EuiExpression); + const button = wrapper.find('[data-test-subj="where.addFilterButton"]').first(); button.simulate('click'); wrapper.update(); expect(openExpression).toHaveBeenCalled(); @@ -73,8 +73,7 @@ describe('WhereExpression', () => { test('calls closeExpression when closing popover', () => { const wrapper = mount(getMountWrapper(true)); - const button = wrapper.find(EuiExpression); - button.simulate('keyDown', { keyCode: 27 }); + wrapper.find(EuiPopover).simulate('keyDown', { keyCode: 27 }); expect(closeExpression).toHaveBeenCalled(); }); test('should render text input for the text data types', async () => { diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap index 3a8f93a33..d4ade7d01 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap @@ -1,28 +1,103 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ForExpression renders 1`] = ` -
      +
      -
      + +
      +
      +
      +
      +
      - for the last - - - +
      +
      + +
      +
      +
      +
      +
      +
      +
      - 1 hour(s) - - +
      + +
      + +
      + EuiIconMock +
      +
      +
      +
      +
      +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap index 5bee81de7..f437f13da 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap @@ -1,28 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`WhereExpression renders 1`] = ` -
      +
      -
      +
      +
      +
      + No filters defined. +
      +
      + + + +
      +
      + You can add up to 1 data filter. +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js index 12a491208..e47595a26 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js +++ b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js @@ -31,7 +31,7 @@ import { Formik } from 'formik'; import MonitorTimeField from './MonitorTimeField'; describe('MonitorTimeField', () => { - test.skip('renders', () => { + test('renders', () => { const component = ( {}}> diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap index 4b2aa0069..97e5f5159 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap @@ -3,68 +3,86 @@ exports[`MonitorTimeField renders 1`] = `
      - + +
      -
      -
      - Choose the time field you want to use for your x-axis +
      + Choose the time field you want to use for your x-axis +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js new file mode 100644 index 000000000..c62ef4a07 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorType from './MonitorType'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; + +describe('MonitorType', () => { + test('renders', () => { + const component = ( + {() => } + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap new file mode 100644 index 000000000..97be8378c --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap @@ -0,0 +1,158 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorType renders 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      + Per query monitors run a specified query and define triggers that check the results of that query. +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      + Per bucket monitors allow you to group results into buckets and define triggers that check each bucket. +
      +
      +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap index 2466a1bfa..6e89b5f99 100644 --- a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap +++ b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap @@ -1,84 +1,119 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`QueryPerformance renders 1`] = ` -Array [ -

      - Query performance -

      , -
      , +
      - - Check the performance of your query and make sure to follow best practices. - +

      - Learn more - - -

      , + Query performance + +
      +
      +
      +
      +
      +
      +
      , + class="euiText euiText--extraSmall" + style="padding:0px 10px" + > +
      + + Check the performance of your query and make sure to follow best practices. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      - - Query duration - - - 5 ms - + + Query duration + + + 5 ms + +
      -
      -
      - - Request duration - - - - - + + Request duration + + + - + +
      -
      -
      - - Hits - - - 15 - + + Hits + + + 15 + +
      -
      , -] +
      +
      `; diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap index 03f432348..4e44c245b 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap @@ -3,7 +3,7 @@ exports[`Frequencies renders CustomCron 1`] = `
      - Every + Run every
      cron expressions +
      + EuiIconMock +
      for complex schedules
      @@ -137,7 +140,6 @@ exports[`Frequencies renders Frequency 1`] = `
      - Every + Run every
      - Every + Run every
      -
      -
      - There is no data for the current selections. -
      +
      + There is no data for the current selections.
      `; diff --git a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js index e4588a058..d899abd23 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js +++ b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js @@ -40,12 +40,13 @@ import { } from './helpers'; import { DEFAULT_MARK_SIZE } from './constants'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; +import { MONITOR_TYPE } from '../../../../../utils/constants'; describe('getYTitle', () => { test('returns count when empty array, undefined, or null', () => { - expect(getYTitle([])).toBe('count'); - expect(getYTitle(undefined)).toBe('count'); - expect(getYTitle(null)).toBe('count'); + expect(getYTitle([])).toBe('doc_count'); + expect(getYTitle(undefined)).toBe('doc_count'); + expect(getYTitle(null)).toBe('doc_count'); }); }); @@ -154,24 +155,6 @@ describe('getMarkData', () => { }); }); -describe('getAggregationTitle', () => { - test('gets count aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN count() OVER all documents FOR THE LAST 1 hour(s)' - ); - }); - - test('gets avg aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - formikValues.aggregationType = 'avg'; - formikValues.fieldName = [{ label: 'bytes' }]; - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN average() OF bytes OVER all documents FOR THE LAST 1 hour(s)' - ); - }); -}); - describe('getDataFromResponse', () => { test('gets empty array when no response', () => { expect(getDataFromResponse(null)).toEqual([]); @@ -188,67 +171,67 @@ describe('getDataFromResponse', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }, { key_as_string: '2018-10-31T19:00:00.000-07:00', from_as_string: '2018-10-31T19:00:00.000-07:00', key: 1541037600000, doc_count: 67, - when: { value: 6185.373134328358 }, + metric: { value: 6185.373134328358 }, }, { key_as_string: '2018-10-31T20:00:00.000-07:00', from_as_string: '2018-10-31T20:00:00.000-07:00', key: 1541041200000, doc_count: 79, - when: { value: -2439.9367088607596 }, + metric: { value: -2439.9367088607596 }, }, { key_as_string: '2018-10-31T21:00:00.000-07:00', from_as_string: '2018-10-31T21:00:00.000-07:00', key: 1541044800000, doc_count: 31, - when: { value: null }, + metric: { value: null }, }, { key_as_string: '2018-10-31T22:00:00.000-07:00', from_as_string: '2018-10-31T22:00:00.000-07:00', key: 1541048400000, doc_count: 18, - when: { value: 4651.5 }, + metric: { value: 4651.5 }, }, { key_as_string: '2018-10-31T23:00:00.000-07:00', from_as_string: '2018-10-31T23:00:00.000-07:00', key: 1541052000000, doc_count: 3, - when: { value: 4410.666666666667 }, + metric: { value: 4410.666666666667 }, }, ], }, }, }; - expect(getDataFromResponse(response)).toEqual([ + expect(getDataFromResponse(response, 'metric', MONITOR_TYPE.QUERY_LEVEL)).toEqual([ { x: new Date(response.aggregations.over.buckets[0].from_as_string), - y: response.aggregations.over.buckets[0].when.value, + y: response.aggregations.over.buckets[0].metric.value, }, { x: new Date(response.aggregations.over.buckets[1].from_as_string), - y: response.aggregations.over.buckets[1].when.value, + y: response.aggregations.over.buckets[1].metric.value, }, { x: new Date(response.aggregations.over.buckets[2].from_as_string), - y: response.aggregations.over.buckets[2].when.value, + y: response.aggregations.over.buckets[2].metric.value, }, { x: new Date(response.aggregations.over.buckets[4].from_as_string), - y: response.aggregations.over.buckets[4].when.value, + y: response.aggregations.over.buckets[4].metric.value, }, { x: new Date(response.aggregations.over.buckets[5].from_as_string), - y: response.aggregations.over.buckets[5].when.value, + y: response.aggregations.over.buckets[5].metric.value, }, ]); }); @@ -261,11 +244,11 @@ describe('getXYValues', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }; expect(getXYValues(whenBucket)).toEqual({ x: new Date(whenBucket.from_as_string), - y: whenBucket.when.value, + y: whenBucket.metric.value, }); }); diff --git a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap index a89b72633..741d3566c 100644 --- a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap +++ b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap @@ -5,6 +5,7 @@ exports[`AnomalyDetectors renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -59,6 +67,7 @@ exports[`AnomalyDetectors renders 1`] = ` values={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -67,9 +76,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -174,6 +190,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -182,9 +199,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -247,6 +271,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -255,9 +280,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -368,6 +400,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -376,9 +409,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -441,6 +481,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -449,9 +490,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js index 826f971ff..6729d35d2 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js @@ -32,6 +32,7 @@ import { historyMock, httpClientMock } from '../../../../../test/mocks'; import { FORMIK_INITIAL_VALUES } from './utils/constants'; import AlertingFakes from '../../../../../test/utils/helpers'; import { SEARCH_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const alertingFakes = new AlertingFakes('CreateMonitor random seed'); @@ -179,9 +180,10 @@ describe('CreateMonitor', () => { }); describe('onUpdate', () => { - test('calls updateMonitor with monitor with no triggers key', () => { + // Query-level monitor + test('calls updateMonitor with monitor', () => { const monitor = alertingFakes.randomMonitor(); - const trigger = alertingFakes.randomTrigger(); + const trigger = alertingFakes.randomTrigger(TRIGGER_TYPE.QUERY_LEVEL); monitor.triggers = [trigger]; const wrapper = shallow( { ); wrapper.instance().onUpdate(monitor, formikBag); expect(updateMonitor).toHaveBeenCalledTimes(1); - // The updatedMonitor that is passed in should NOT have the trigger key - const updatedMonitor = { ...monitor }; - delete updatedMonitor.triggers; - expect(updateMonitor).toHaveBeenCalledWith(updatedMonitor); + expect(updateMonitor).toHaveBeenCalledWith(monitor); }); test('logs error when updateMonitor rejects', async () => { diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap index 59ec5a38e..b65783ed8 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap @@ -12,6 +12,7 @@ exports[`CreateMonitor renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -20,9 +21,16 @@ exports[`CreateMonitor renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap index 086712815..a898d4d74 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap @@ -123,6 +123,7 @@ Object { }, }, ], + "monitor_type": "query_level_monitor", "name": "random_name", "schedule": Object { "period": Object { @@ -133,6 +134,7 @@ Object { "triggers": Array [], "type": "monitor", "ui_metadata": Object { + "monitor_type": "query_level_monitor", "schedule": Object { "cronExpression": "0 */1 * * *", "daily": 0, @@ -157,13 +159,10 @@ Object { }, }, "search": Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "", "where": Object { @@ -290,13 +289,10 @@ Object { exports[`formikToUiSearch can build ui search 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -311,13 +307,10 @@ Object { exports[`formikToUiSearch can build ui search with range where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -336,13 +329,10 @@ Object { exports[`formikToUiSearch can build ui search with term where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -360,12 +350,4 @@ Object { exports[`formikToWhenAggregation can build when (count) aggregation 1`] = `Object {}`; -exports[`formikToWhenAggregation can build when aggregation 1`] = ` -Object { - "when": Object { - "avg": Object { - "field": "bytes", - }, - }, -} -`; +exports[`formikToWhenAggregation can build when aggregation 1`] = `Object {}`; diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap index 4945154f9..667ce9e32 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap @@ -1,104 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DefineMonitor renders 1`] = ` - - - - -
      -
      -
      -
      - You must specify an index. -
      -
      -
      -
      - - -
      -`; - -exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` - - - - -
      - +
      + +
      - + +
      +
      +
      +
      + You must specify an index. +
      +
      +
      +
      +
      +
      +`; + +exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` +
      + + Run + , + ] + } + bodyStyles={ + Object { + "padding": "initial", + } + } + panelStyles={ + Object { + "paddingLeft": "10px", + "paddingRight": "10px", + } + } + title="Query" + titleSize="s" + > + + +
      +
      +
      +
      + You must specify an index. +
      +
      +
      +
      + + +
      +
      `; diff --git a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap index daf14fde0..84940ee25 100644 --- a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap +++ b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap @@ -5,6 +5,7 @@ exports[`MonitorIndex renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -97,7 +105,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -132,6 +139,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -140,9 +148,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -205,6 +220,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -213,9 +229,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -263,7 +286,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -282,7 +304,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -292,7 +313,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -345,6 +365,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -353,9 +374,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -418,6 +446,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -426,9 +455,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap index 571472c2a..bfc62b2ed 100644 --- a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap +++ b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap @@ -4,7 +4,8 @@ exports[`Message renders 1`] = `
      Message subject @@ -21,14 +22,15 @@ exports[`Message renders 1`] = ` class="euiFormRow__fieldWrapper" >
      @@ -37,7 +39,7 @@ exports[`Message renders 1`] = `
      - - Message - -
      +
      - - - Info - - - + Learn more +
      + EuiIconMock +
      + +
      +
      @@ -74,50 +87,64 @@ exports[`Message renders 1`] = ` > -
      +

      + Action configuration +

      -
      - - Action throttling - - -
      + Throttling
      @@ -254,39 +238,39 @@ exports[`Message renders 1`] = ` >
      minutes
      - Throttle value must be greater than 0 and less than 1440 + Throttle value must be greater than 0 and less than 1440.
      diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js index 2f8076c98..e9037ec65 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js +++ b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js @@ -41,44 +41,4 @@ describe('TriggerExpressions', () => { const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); - - test('calls openExpression when clicking expression', () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const button = wrapper.find(EuiExpression); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - }); - - test('calls closeExpression when closing popover', async () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const closeExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'closeExpression' - ); - const button = wrapper.find(EuiExpression); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - await new Promise((res) => setTimeout(() => res())); - button.simulate('keyDown', { keyCode: 27 }); - wrapper.update(); - expect(closeExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - }); }); diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap index 35abc84bf..445297f3b 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap @@ -1,83 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerExpressions renders 1`] = ` - - - - - - } - closePopover={[Function]} - display="inlineBlock" - hasArrow={true} - id="trigger-popover" - isOpen={false} - ownFocus={true} - panelPaddingSize="none" - withTitle={true} + -
      - - - - - - - - - - - - -
      -
      -
      -
      + + + + + + + + + + + `; diff --git a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap index c8bc024be..9a2b588b5 100644 --- a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap @@ -1,84 +1,95 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerQuery renders 1`] = ` -
      - - - - - - - - - - - - - - - - - - - + + + +
      + + + + + Trigger condition response + + + } + labelType="label" + > + + + + + + - - - Run - - - -
      + Run for condition response + + + `; diff --git a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js index 712051d8f..005f2fa25 100644 --- a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js +++ b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js @@ -27,8 +27,9 @@ import _ from 'lodash'; import { formikToTrigger, formikToTriggerUiMetadata, formikToCondition } from './formikToTrigger'; -import { FORMIK_INITIAL_TRIGGER_VALUES } from './constants'; -import { SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from './constants'; +import { MONITOR_TYPE, SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_VALUES } from '../../../../CreateMonitor/containers/CreateMonitor/utils/constants'; describe('formikToTrigger', () => { test('can create trigger', () => { @@ -46,13 +47,18 @@ describe('formikToTrigger', () => { describe('formikToTriggerUiMetadata', () => { test('can create trigger metadata for AD monitors', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); + _.set(formikValues, 'triggerDefinitions.trigger_type', TRIGGER_TYPE.AD); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.AD } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.AD }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, adTriggerMetadata: { triggerType: 'anomaly_detector_trigger', anomalyGrade: { @@ -69,13 +75,17 @@ describe('formikToTriggerUiMetadata', () => { }); test('can create metadata', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.QUERY } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.QUERY }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, }, }); }); @@ -119,7 +129,7 @@ describe('formikToCondition', () => { ).toEqual({ script: { lang: 'painless', - source: `return ctx.results[0].aggregations.when.value == null ? false : ctx.results[0].aggregations.when.value > 10000`, + source: 'ctx.results[0].hits.total.value > 10000', }, }); }); diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js index a668ea4b3..ee7ecb215 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js @@ -23,6 +23,7 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ +import _ from 'lodash'; import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js index 503b0f6a6..4a6b3a068 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js @@ -25,6 +25,7 @@ */ import { validateTriggerName } from './validation'; +import { TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; describe('validateTriggerName', () => { test('returns undefined if no error', () => { @@ -36,12 +37,16 @@ describe('validateTriggerName', () => { expect(validateTriggerName([], {})('')).toBe('Required'); }); test('returns false if name already exists in monitor while creates new trigger', () => { - const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, {})('Test')).toBe('Trigger name already used'); + const triggers = [{ [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123', name: 'Test' } }]; + expect(validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: {} })('Test')).toBe( + 'Trigger name already used' + ); }); test('returns undefined if editing trigger and name is the same', () => { const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, { id: '123' })('Test')).toBeUndefined(); + expect( + validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123' } })('Test') + ).toBeUndefined(); }); }); diff --git a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap index bae503fda..03257100b 100644 --- a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap +++ b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap @@ -55,27 +55,27 @@ exports[`DashboardControls renders 1`] = `
      + View alert details + , + Acknowledge @@ -64,7 +71,7 @@ exports[`Dashboard renders 1`] = ` "padding": "initial", } } - title="Alerts" + title="Alerts by triggers" titleSize="l" > - Alerts + Alerts by triggers
      @@ -136,18 +143,66 @@ exports[`Dashboard renders 1`] = ` className="euiFlexItem" > + + + + +
      + + +
      +
      + +
      + +
      + +
      + - 1 + 1 (Highest) @@ -774,28 +857,29 @@ exports[`Dashboard renders 1`] = ` columns={ Array [ Object { - "dataType": "date", - "field": "start_time", - "name": "Alert start time", + "field": "total", + "name": "Alerts", "render": [Function], "sortable": true, "truncateText": false, }, Object { - "dataType": "date", - "field": "end_time", - "name": "Alert end time", - "render": [Function], + "field": "ACTIVE", + "name": "Active", "sortable": true, "truncateText": false, }, Object { - "field": "monitor_name", - "name": "Monitor name", - "render": [Function], + "field": "ACKNOWLEDGED", + "name": "Acknowledged", "sortable": true, - "textOnly": true, - "truncateText": true, + "truncateText": false, + }, + Object { + "field": "ERROR", + "name": "Errors", + "sortable": true, + "truncateText": false, }, Object { "field": "trigger_name", @@ -805,25 +889,34 @@ exports[`Dashboard renders 1`] = ` "truncateText": true, }, Object { - "field": "severity", - "name": "Severity", - "sortable": false, + "dataType": "date", + "field": "start_time", + "name": "Trigger start time", + "render": [Function], + "sortable": true, "truncateText": false, }, Object { - "field": "state", - "name": "State", + "dataType": "date", + "field": "last_notification_time", + "name": "Trigger last updated", "render": [Function], + "sortable": true, + "truncateText": true, + }, + Object { + "field": "severity", + "name": "Severity", "sortable": false, "truncateText": false, }, Object { - "dataType": "date", - "field": "acknowledged_time", - "name": "Time acknowledged", + "field": "monitor_name", + "name": "Monitor name", "render": [Function], "sortable": true, - "truncateText": false, + "textOnly": true, + "truncateText": true, }, ] } @@ -832,19 +925,6 @@ exports[`Dashboard renders 1`] = ` items={Array []} noItemsMessage={} onChange={[Function]} - pagination={ - Object { - "pageIndex": 0, - "pageSize": 20, - "pageSizeOptions": Array [ - 5, - 10, - 20, - 50, - ], - "totalItemCount": 0, - } - } responsive={true} selection={ Object { @@ -935,38 +1015,59 @@ exports[`Dashboard renders 1`] = ` items={ Array [ Object { - "isSortAscending": false, - "isSorted": true, - "key": "_data_s_start_time_0", - "name": "Alert start time", + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_total_0", + "name": "Alerts", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_end_time_1", - "name": "Alert end time", + "key": "_data_s_ACTIVE_1", + "name": "Active", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_monitor_name_2", - "name": "Monitor name", + "key": "_data_s_ACKNOWLEDGED_2", + "name": "Acknowledged", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_trigger_name_3", + "key": "_data_s_ERROR_3", + "name": "Errors", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_trigger_name_4", "name": "Trigger name", "onSort": [Function], }, + Object { + "isSortAscending": false, + "isSorted": true, + "key": "_data_s_start_time_5", + "name": "Trigger start time", + "onSort": [Function], + }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_acknowledged_time_6", - "name": "Time acknowledged", + "key": "_data_s_last_notification_time_6", + "name": "Trigger last updated", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_monitor_name_8", + "name": "Monitor name", "onSort": [Function], }, ] @@ -1151,17 +1252,16 @@ exports[`Dashboard renders 1`] = ` + + + + + + + + + + - State + Severity
      @@ -1488,16 +1751,16 @@ exports[`Dashboard renders 1`] = ` - Time acknowledged + Monitor name @@ -1561,12 +1824,12 @@ exports[`Dashboard renders 1`] = ` >
      + +
      + +
      + +
      + @@ -1158,9 +1201,74 @@ exports[`DestinationsList renders 1`] = ` + + + + +
      + +
      + +
      + +
      + @@ -2398,9 +2549,74 @@ exports[`DestinationsList renders when email is disallowed 1`] = ` + + + + + - Dashboard + Alerts
      @@ -36,7 +36,7 @@ exports[` renders 1`] = ` - Create trigger + Edit monitor diff --git a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap index 92ed72756..71a3418ab 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap +++ b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap @@ -30,6 +30,14 @@ exports[`MonitorOverview renders 1`] = `
      +
      +
      +

      @@ -46,10 +54,10 @@ exports[`MonitorOverview renders 1`] = ` class="euiText euiText--extraSmall" > - State + Monitor type
      - Enabled + Per query monitor
      @@ -145,7 +153,7 @@ exports[`MonitorOverview renders 1`] = ` Last updated by
      - N/A + -
      diff --git a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js index 4cb5ceba3..20d4ca5fd 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js +++ b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js @@ -40,8 +40,8 @@ describe('getOverviewStats', () => { const activeCount = 17; expect(getOverviewStats(monitor, monitorId, monitorVersion, activeCount)).toEqual([ { - header: 'State', - value: 'Enabled', + header: 'Monitor type', + value: 'Per query monitor', }, { header: 'Monitor definition type', diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.js index 61c782cb7..f92399abc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.js @@ -28,6 +28,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import uuidv4 from 'uuid/v4'; import { EuiInMemoryTable } from '@elastic/eui'; +import _ from 'lodash'; import ContentPanel from '../../../../components/ContentPanel'; import { MONITOR_TYPE } from '../../../../utils/constants'; diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js index 512a30bf2..8d2672ddc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js @@ -28,6 +28,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import Triggers from './Triggers'; +import { MONITOR_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const props = { monitor: { @@ -79,16 +81,31 @@ describe('Triggers', () => { test('onDelete calls updateMonitor with triggers to keep', () => { const onDelete = jest.spyOn(Triggers.prototype, 'onDelete'); const monitor = { + monitor_type: MONITOR_TYPE.QUERY_LEVEL, triggers: [ - { name: 'one', severity: 1, actions: [{ name: 'one action' }] }, - { name: 'two', severity: 2, actions: [{ name: 'two action' }] }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'one', + severity: 1, + actions: [{ name: 'one action' }], + }, + }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'two', + severity: 2, + actions: [{ name: 'two action' }], + }, + }, ], }; const wrapper = getShallowWrapper({ monitor }); - wrapper.setState({ selectedItems: [monitor.triggers[0]] }); + wrapper.setState({ selectedItems: [monitor.triggers[0][TRIGGER_TYPE.QUERY_LEVEL]] }); wrapper.instance().onDelete(); expect(onDelete).toHaveBeenCalled(); expect(props.updateMonitor).toHaveBeenCalled(); - expect(props.updateMonitor).toHaveBeenCalledWith({ triggers: [monitor.triggers[1]] }); + expect(props.updateMonitor).toHaveBeenCalledWith({ + triggers: [monitor.triggers[1][TRIGGER_TYPE.QUERY_LEVEL]], + }); }); }); diff --git a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap index 2f0cdd59f..7d508b089 100644 --- a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap +++ b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap @@ -2,35 +2,12 @@ exports[`Triggers renders 1`] = ` - Edit - , - - Delete - , - - Create - , - ] - } bodyStyles={ Object { "padding": "initial", } } - title="Triggers" + title="Triggers (1)" titleSize="s" > { describe('validateActionName', () => { const trigger = { name: 'trigger_name', - actions: [{ name: 'foo' }, { name: 'bar' }], + [TRIGGER_TYPE.QUERY_LEVEL]: { actions: [{ name: 'foo' }, { name: 'bar' }] }, }; + const monitor = FORMIK_INITIAL_VALUES; test('returns undefined if no error', () => { - expect(validateActionName(trigger)('valid action name')).toBeUndefined(); + expect(validateActionName(monitor, trigger)('valid action name')).toBeUndefined(); }); test('returns Required string if falsy value', () => { - expect(validateActionName(trigger)()).toBe('Required'); - expect(validateActionName(trigger)('')).toBe('Required'); + expect(validateActionName(monitor, trigger)()).toBe('Required.'); + expect(validateActionName(monitor, trigger)('')).toBe('Required.'); }); - trigger.actions.push({ name: 'foo' }); + trigger[TRIGGER_TYPE.QUERY_LEVEL].actions.push({ name: 'foo' }); test('returns already used if action name is already used', () => { - expect(validateActionName(trigger)('foo')).toBe('Action name is already used'); + expect(validateActionName(monitor, trigger)('foo')).toBe('Action name is already used.'); }); }); @@ -112,8 +115,8 @@ describe('validateMonitorName', () => { }); test('returns Required string if falsy value', () => { - validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required')); - validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required')); + validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required.')); + validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required.')); }); }); @@ -124,7 +127,7 @@ describe('validatePositiveInteger', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer'; + const invalidText = 'Must be a positive integer.'; expect(validatePositiveInteger(-5)).toBe(invalidText); expect(validatePositiveInteger(0)).toBe(invalidText); expect(validatePositiveInteger(1.5)).toBe(invalidText); @@ -142,7 +145,7 @@ describe('validateUnit', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be one of minutes, hours, days'; + const invalidText = 'Must be one of minutes, hours, days.'; expect(validateUnit(5)).toBe(invalidText); expect(validateUnit('RANDOM')).toBe(invalidText); expect(validateUnit(null)).toBe(invalidText); @@ -159,7 +162,7 @@ describe('validateMonthlyDay', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer between 1-31'; + const invalidText = 'Must be a positive integer between 1-31.'; expect(validateMonthlyDay(-5)).toBe(invalidText); expect(validateMonthlyDay(0)).toBe(invalidText); expect(validateMonthlyDay(1.5)).toBe(invalidText); @@ -202,7 +205,7 @@ describe('validateIndex', () => { }); test('returns error string if non array is passed in', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex(1)).toBe(invalidText); expect(validateIndex(null)).toBe(invalidText); expect(validateIndex('test')).toBe(invalidText); @@ -210,7 +213,7 @@ describe('validateIndex', () => { }); test('returns error string if empty array', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex([])).toBe(invalidText); }); diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 1069c108e..b1584f384 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -48,4 +48,5 @@ Compatible with OpenSearch Dashboards 1.1.0 * Add Cypress tests for Bucket-Level Alerting ([#91](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/91)) * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) -* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) \ No newline at end of file +* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file diff --git a/test/utils/helpers.js b/test/utils/helpers.js index dd6f6cdf3..d413bf4b9 100644 --- a/test/utils/helpers.js +++ b/test/utils/helpers.js @@ -9,6 +9,8 @@ * GitHub history for details. */ +import { TRIGGER_TYPE } from '../../public/pages/CreateTrigger/containers/CreateTrigger/utils/constants'; + const Chance = require('chance'); class AlertingFakes { @@ -31,6 +33,7 @@ class AlertingFakes { this.randomInputs = this.randomInputs.bind(this); this.randomMonitorEnabled = this.randomMonitorEnabled.bind(this); this.randomMonitor = this.randomMonitor.bind(this); + this.randomTime = this.randomTime.bind(this); } randomEmailDestination() { @@ -106,20 +109,22 @@ class AlertingFakes { }; } - randomTrigger() { + randomTrigger(type = TRIGGER_TYPE.QUERY_LEVEL) { return { - id: this.chance.guid().slice(0, 20), - name: this.chance.word(), - severity: this.chance.string({ length: 1, pool: '12345' }), - condition: { - script: { - lang: 'painless', - source: `return ${this.chance.bool()}`, + [type]: { + id: this.chance.guid().slice(0, 20), + name: this.chance.word(), + severity: this.chance.string({ length: 1, pool: '12345' }), + condition: { + script: { + lang: 'painless', + source: `return ${this.chance.bool()}`, + }, }, + actions: new Array(this.chance.natural({ max: 10 })) + .fill(null) + .map(() => this.randomAction()), }, - actions: new Array(this.chance.natural({ max: 10 })) - .fill(null) - .map(() => this.randomAction()), }; } @@ -184,6 +189,10 @@ class AlertingFakes { .map(() => this.randomTrigger()), }; } + + randomTime() { + return this.chance.timestamp(); + } } module.exports = AlertingFakes;