From 4eefe97690a0c24fb9d953bc40222de17b60ebfa Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Thu, 27 Jan 2022 17:09:08 -0800 Subject: [PATCH] Adding basic unit tests (#151) * Add flyout render Signed-off-by: Annie Lee * Add some basic tests Signed-off-by: Annie Lee * Add more tests Signed-off-by: Annie Lee * Update jest.config.js Signed-off-by: Annie Lee * Add tests Signed-off-by: Annie Lee * Update dashboard sample alerttime Signed-off-by: Annie Lee * Update dashboard test alert time snapshot Signed-off-by: Annie Lee * Update Dashboard.test.js Signed-off-by: Annie Lee * Remove test alert start time Signed-off-by: Annie Lee * Update VisualGraph test and code Signed-off-by: Annie Lee * Update package.json to run unit tests in UTC timezone Signed-off-by: Annie Lee * Update dashboard sample alert start time Signed-off-by: Annie Lee * Update Dashboard test Signed-off-by: Annie Lee * Update Dashboard.test.js.snap Signed-off-by: Annie Lee * Update snapshot file Signed-off-by: Annie Lee --- package.json | 2 +- .../components/VisualGraph/VisualGraph.js | 15 +- .../VisualGraph/VisualGraph.test.js | 91 +- .../__snapshots__/VisualGraph.test.js.snap | 1087 ++++- .../containers/DataSource/DataSource.test.js | 30 + .../__snapshots__/DataSource.test.js.snap | 27 + .../containers/DefineMonitor/DefineMonitor.js | 2 +- .../ActionEmptyPrompt.test.js | 15 + .../ActionEmptyPrompt.test.js.snap | 26 + .../AddActionButton/AddActionButton.test.js | 15 + .../AddActionButton.test.js.snap | 11 + .../AddTriggerButton/AddTriggerButton.test.js | 15 + .../AddTriggerButton.test.js.snap | 11 + .../AddTriggerConditionButton.test.js | 15 + .../AddTriggerConditionButton.test.js.snap | 11 + .../BucketLevelTriggerExpression.test.js | 15 + .../BucketLevelTriggerExpression.test.js.snap | 79 + .../BucketLevelTriggerGraph.test.js | 15 + .../components/TriggerGraph.test.js | 15 + .../BucketLevelTriggerGraph.test.js.snap | 20 + .../__snapshots__/TriggerGraph.test.js.snap | 23 + .../Dashboard/containers/Dashboard.test.js | 119 +- .../__snapshots__/Dashboard.test.js.snap | 4131 +++++++++++++++-- test/jest.config.js | 5 + 24 files changed, 5329 insertions(+), 466 deletions(-) create mode 100644 public/pages/CreateMonitor/containers/DataSource/DataSource.test.js create mode 100644 public/pages/CreateMonitor/containers/DataSource/__snapshots__/DataSource.test.js.snap create mode 100644 public/pages/CreateTrigger/components/ActionEmptyPrompt/ActionEmptyPrompt.test.js create mode 100644 public/pages/CreateTrigger/components/ActionEmptyPrompt/__snapshots__/ActionEmptyPrompt.test.js.snap create mode 100644 public/pages/CreateTrigger/components/AddActionButton/AddActionButton.test.js create mode 100644 public/pages/CreateTrigger/components/AddActionButton/__snapshots__/AddActionButton.test.js.snap create mode 100644 public/pages/CreateTrigger/components/AddTriggerButton/AddTriggerButton.test.js create mode 100644 public/pages/CreateTrigger/components/AddTriggerButton/__snapshots__/AddTriggerButton.test.js.snap create mode 100644 public/pages/CreateTrigger/components/AddTriggerConditionButton/AddTriggerConditionButton.test.js create mode 100644 public/pages/CreateTrigger/components/AddTriggerConditionButton/__snapshots__/AddTriggerConditionButton.test.js.snap create mode 100644 public/pages/CreateTrigger/components/BucketLevelTriggerExpression/BucketLevelTriggerExpression.test.js create mode 100644 public/pages/CreateTrigger/components/BucketLevelTriggerExpression/__snapshots__/BucketLevelTriggerExpression.test.js.snap create mode 100644 public/pages/CreateTrigger/components/BucketLevelTriggerGraph.test.js create mode 100644 public/pages/CreateTrigger/components/TriggerGraph.test.js create mode 100644 public/pages/CreateTrigger/components/__snapshots__/BucketLevelTriggerGraph.test.js.snap create mode 100644 public/pages/CreateTrigger/components/__snapshots__/TriggerGraph.test.js.snap diff --git a/package.json b/package.json index 5fad73ef2..4c26edb66 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "osd": "node ../../scripts/osd", "opensearch": "node ../../scripts/opensearch", "lint": "../../node_modules/.bin/eslint '**/*.js' -c .eslintrc --ignore-path .gitignore", - "test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js", + "test:jest": "TZ=UTC ../../node_modules/.bin/jest --config ./test/jest.config.js", "build": "yarn plugin-helpers build", "plugin-helpers": "node ../../scripts/plugin_helpers", "postbuild": "echo Renaming build artifact to [$npm_package_config_id-$npm_package_version.zip] && mv build/$npm_package_config_id*.zip build/$npm_package_config_id-$npm_package_version.zip" diff --git a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js index aa61530df..9ed8f47ae 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js +++ b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js @@ -208,18 +208,11 @@ export default class VisualGraph extends Component { ? null : getMapDataFromResponse(response, aggTypeFieldName, values.groupBy); // Show empty graph view when data is empty or aggregation monitor does not have group by defined. - const showEmpty = - !data.length || (monitorType == MONITOR_TYPE.BUCKET_LEVEL && !values.groupBy.length); + const showEmpty = !data.length || (!isQueryMonitor && !values.groupBy.length); - return ( - <> - {showEmpty - ? this.renderEmptyData() - : isQueryMonitor - ? this.renderXYPlot(data) - : this.renderAggregationXYPlot(data, groupedData)} - - ); + if (showEmpty) return <>{this.renderEmptyData()}; + else if (isQueryMonitor) return <>{this.renderXYPlot(data)}; + else return <>{this.renderAggregationXYPlot(data, groupedData)}; } } diff --git a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.test.js b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.test.js index b66a7439a..9e361fe99 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.test.js +++ b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.test.js @@ -29,10 +29,99 @@ import { render } from 'enzyme'; import VisualGraph from './VisualGraph'; import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; +import { MONITOR_TYPE } from '../../../../utils/constants'; + +const queryGraphResponse = { + _shards: { total: 1, failed: 0, successful: 1, skipped: 0 }, + hits: { hits: [], total: { value: 28, relation: 'eq' }, max_score: null }, + took: 5, + timed_out: false, + aggregations: { + over: { + buckets: [ + { key_as_string: '2021-11-19T07:00:00.000-08:00', doc_count: 0, key: 1637334000000 }, + { key_as_string: '2021-11-19T08:00:00.000-08:00', doc_count: 6, key: 1637337600000 }, + { key_as_string: '2021-11-19T09:00:00.000-08:00', doc_count: 5, key: 1637341200000 }, + { key_as_string: '2021-11-19T10:00:00.000-08:00', doc_count: 4, key: 1637344800000 }, + { key_as_string: '2021-11-19T11:00:00.000-08:00', doc_count: 8, key: 1637348400000 }, + { key_as_string: '2021-11-19T12:00:00.000-08:00', doc_count: 5, key: 1637352000000 }, + ], + }, + }, +}; +const bucketMonitorValues = { + name: '', + disabled: false, + frequency: 'interval', + timezone: [], + daily: 0, + period: { interval: 1, unit: 'MINUTES' }, + weekly: { mon: false, tue: false, wed: false, thur: false, fri: false, sat: false, sun: false }, + monthly: { type: 'day', day: 1 }, + cronExpression: '0 */1 * * *', + monitor_type: 'bucket_level_monitor', + searchType: 'graph', + index: [ + { label: 'opensearch_dashboards_sample_data_ecommerce', health: 'green', status: 'open' }, + ], + timeField: 'order_date', + query: '{\n "size": 0,\n "query": {\n "match_all": {}\n }\n}', + aggregationType: 'count', + fieldName: [], + aggregations: [], + groupBy: ['customer_gender'], + groupByField: [{ label: '' }], + overDocuments: 'all documents', + groupedOverTop: 5, + groupedOverFieldName: 'bytes', + bucketValue: 1, + bucketUnitOfTime: 'h', + where: { fieldName: [], operator: 'is', fieldValue: '', fieldRangeStart: 0, fieldRangeEnd: 0 }, + detectorId: '', + triggerDefinitions: [], +}; + +const bucketGraphResponse = { + _shards: { total: 1, failed: 0, successful: 1, skipped: 0 }, + hits: { hits: [], total: { value: 28, relation: 'eq' }, max_score: null }, + took: 19, + timed_out: false, + aggregations: { + composite_agg: { + buckets: [ + { doc_count: 6, key: { date: 1637337600000 } }, + { doc_count: 5, key: { date: 1637341200000 } }, + { doc_count: 4, key: { date: 1637344800000 } }, + { doc_count: 8, key: { date: 1637348400000 } }, + { doc_count: 5, key: { date: 1637352000000 } }, + ], + after_key: { date: 1637352000000 }, + }, + }, +}; describe('VisualGraph', () => { test('renders', () => { - const component = ; + const component = ( + + ); + expect(render(component)).toMatchSnapshot(); + }); + + test('renders with bucket level monitor', () => { + const values = FORMIK_INITIAL_VALUES; + values.monitor_type = MONITOR_TYPE.BUCKET_LEVEL; + const component = ( + + ); expect(render(component)).toMatchSnapshot(); }); }); diff --git a/public/pages/CreateMonitor/components/VisualGraph/__snapshots__/VisualGraph.test.js.snap b/public/pages/CreateMonitor/components/VisualGraph/__snapshots__/VisualGraph.test.js.snap index 0382b4252..5753da187 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/__snapshots__/VisualGraph.test.js.snap +++ b/public/pages/CreateMonitor/components/VisualGraph/__snapshots__/VisualGraph.test.js.snap @@ -2,10 +2,1091 @@ exports[`VisualGraph renders 1`] = `
-
- There is no data for the current selections. +
+
+

+ COUNT of documents +

+
+
+
+
+
+
+
+
+
+ FOR THE LAST 1 hour(s) +
+
+
+
+
+
+ + + + + + + + 03 PM + + + + + + 04 PM + + + + + + 05 PM + + + + + + 06 PM + + + + + + 07 PM + + + + + + 08 PM + + + + + + + + + + + 0 + + + + + + 1 + + + + + + 2 + + + + + + 3 + + + + + + 4 + + + + + + 5 + + + + + + 6 + + + + + + 7 + + + + + + 8 + + + + + + 9 + + + + + + 10 + + + + + + 11 + + + + + + 12 + + + + + + + doc_count + + + + + + + + + + + + + + +
+
+
+
+`; + +exports[`VisualGraph renders with bucket level monitor 1`] = ` +
+
+
+

+ COUNT of documents +

+
+
+
+
+
+
+
+
+
+ + FOR THE LAST 1 hour(s), GROUP BY customer_gender, Showing top 3 buckets. + +
+
+
+
+
+
+ + + + + + + + 04 PM + + + + + + 05 PM + + + + + + 06 PM + + + + + + 07 PM + + + + + + 08 PM + + + + + + + order_date + + + + + + + + + + + 0 + + + + + + 1 + + + + + + 2 + + + + + + 3 + + + + + + 4 + + + + + + 5 + + + + + + 6 + + + + + + 7 + + + + + + 8 + + + + + + 9 + + + + + + 10 + + + + + + 11 + + + + + + 12 + + + + + + + doc_count + + + + + + + + + + + + +
+
+ + + + + - + +
+
+
+
`; diff --git a/public/pages/CreateMonitor/containers/DataSource/DataSource.test.js b/public/pages/CreateMonitor/containers/DataSource/DataSource.test.js new file mode 100644 index 000000000..135d50fcc --- /dev/null +++ b/public/pages/CreateMonitor/containers/DataSource/DataSource.test.js @@ -0,0 +1,30 @@ +/* + * 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 { shallow } from 'enzyme'; + +import { httpClientMock } from '../../../../../test/mocks'; +import DataSource from './DataSource'; +import { FORMIK_INITIAL_VALUES } from '../CreateMonitor/utils/constants'; + +beforeEach(() => { + jest.clearAllMocks(); +}); + +describe('DataSource', () => { + test('renders', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/containers/DataSource/__snapshots__/DataSource.test.js.snap b/public/pages/CreateMonitor/containers/DataSource/__snapshots__/DataSource.test.js.snap new file mode 100644 index 000000000..da337a372 --- /dev/null +++ b/public/pages/CreateMonitor/containers/DataSource/__snapshots__/DataSource.test.js.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DataSource renders 1`] = ` + + + + + +`; diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js index 7f3afed98..c6a929d6f 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js +++ b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js @@ -402,7 +402,7 @@ class DefineMonitor extends Component { showPluginWarning() { const { values } = this.props; const { plugins } = this.state; - return values.searchType == SEARCH_TYPE.AD && plugins.indexOf(OS_AD_PLUGIN) == -1; + return values.searchType === SEARCH_TYPE.AD && plugins.indexOf(OS_AD_PLUGIN) === -1; } render() { diff --git a/public/pages/CreateTrigger/components/ActionEmptyPrompt/ActionEmptyPrompt.test.js b/public/pages/CreateTrigger/components/ActionEmptyPrompt/ActionEmptyPrompt.test.js new file mode 100644 index 000000000..00b120472 --- /dev/null +++ b/public/pages/CreateTrigger/components/ActionEmptyPrompt/ActionEmptyPrompt.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import ActionEmptyPrompt from './ActionEmptyPrompt'; + +describe('ActionEmptyPrompt', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/ActionEmptyPrompt/__snapshots__/ActionEmptyPrompt.test.js.snap b/public/pages/CreateTrigger/components/ActionEmptyPrompt/__snapshots__/ActionEmptyPrompt.test.js.snap new file mode 100644 index 000000000..ba7f2772d --- /dev/null +++ b/public/pages/CreateTrigger/components/ActionEmptyPrompt/__snapshots__/ActionEmptyPrompt.test.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ActionEmptyPrompt renders 1`] = ` + + Add destination + + } + body={ + +

+ There are no existing destinations. Add a destinations to create an action. +

+
+ } + style={ + Object { + "maxWidth": "45em", + } + } +/> +`; diff --git a/public/pages/CreateTrigger/components/AddActionButton/AddActionButton.test.js b/public/pages/CreateTrigger/components/AddActionButton/AddActionButton.test.js new file mode 100644 index 000000000..ce97c0152 --- /dev/null +++ b/public/pages/CreateTrigger/components/AddActionButton/AddActionButton.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import AddActionButton from './AddActionButton'; + +describe('AddActionButton', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/AddActionButton/__snapshots__/AddActionButton.test.js.snap b/public/pages/CreateTrigger/components/AddActionButton/__snapshots__/AddActionButton.test.js.snap new file mode 100644 index 000000000..77ddf9b3c --- /dev/null +++ b/public/pages/CreateTrigger/components/AddActionButton/__snapshots__/AddActionButton.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddActionButton renders 1`] = ` + + Add action + +`; diff --git a/public/pages/CreateTrigger/components/AddTriggerButton/AddTriggerButton.test.js b/public/pages/CreateTrigger/components/AddTriggerButton/AddTriggerButton.test.js new file mode 100644 index 000000000..b1ce4773a --- /dev/null +++ b/public/pages/CreateTrigger/components/AddTriggerButton/AddTriggerButton.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import AddTriggerButton from './AddTriggerButton'; + +describe('AddTriggerButton', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/AddTriggerButton/__snapshots__/AddTriggerButton.test.js.snap b/public/pages/CreateTrigger/components/AddTriggerButton/__snapshots__/AddTriggerButton.test.js.snap new file mode 100644 index 000000000..ce44dfe55 --- /dev/null +++ b/public/pages/CreateTrigger/components/AddTriggerButton/__snapshots__/AddTriggerButton.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddTriggerButton renders 1`] = ` + + Add trigger + +`; diff --git a/public/pages/CreateTrigger/components/AddTriggerConditionButton/AddTriggerConditionButton.test.js b/public/pages/CreateTrigger/components/AddTriggerConditionButton/AddTriggerConditionButton.test.js new file mode 100644 index 000000000..f011b13bd --- /dev/null +++ b/public/pages/CreateTrigger/components/AddTriggerConditionButton/AddTriggerConditionButton.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import AddTriggerConditionButton from './AddTriggerConditionButton'; + +describe('AddTriggerConditionButton', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/AddTriggerConditionButton/__snapshots__/AddTriggerConditionButton.test.js.snap b/public/pages/CreateTrigger/components/AddTriggerConditionButton/__snapshots__/AddTriggerConditionButton.test.js.snap new file mode 100644 index 000000000..46541ed58 --- /dev/null +++ b/public/pages/CreateTrigger/components/AddTriggerConditionButton/__snapshots__/AddTriggerConditionButton.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AddTriggerConditionButton renders 1`] = ` + + + Add condition + +`; diff --git a/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/BucketLevelTriggerExpression.test.js b/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/BucketLevelTriggerExpression.test.js new file mode 100644 index 000000000..f033f62e6 --- /dev/null +++ b/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/BucketLevelTriggerExpression.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import BucketLevelTriggerExpression from './BucketLevelTriggerExpression'; + +describe('BucketLevelTriggerExpression', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/__snapshots__/BucketLevelTriggerExpression.test.js.snap b/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/__snapshots__/BucketLevelTriggerExpression.test.js.snap new file mode 100644 index 000000000..070802868 --- /dev/null +++ b/public/pages/CreateTrigger/components/BucketLevelTriggerExpression/__snapshots__/BucketLevelTriggerExpression.test.js.snap @@ -0,0 +1,79 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BucketLevelTriggerExpression renders 1`] = ` + + + + + + + + + + + + + + + + + + + + + + + + Remove condition + + + +`; diff --git a/public/pages/CreateTrigger/components/BucketLevelTriggerGraph.test.js b/public/pages/CreateTrigger/components/BucketLevelTriggerGraph.test.js new file mode 100644 index 000000000..7451f6d0b --- /dev/null +++ b/public/pages/CreateTrigger/components/BucketLevelTriggerGraph.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import BucketLevelTriggerGraph from './BucketLevelTriggerGraph'; + +describe('BucketLevelTriggerGraph', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/TriggerGraph.test.js b/public/pages/CreateTrigger/components/TriggerGraph.test.js new file mode 100644 index 000000000..45dc1fbe1 --- /dev/null +++ b/public/pages/CreateTrigger/components/TriggerGraph.test.js @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import TriggerGraph from './TriggerGraph'; + +describe('TriggerGraph', () => { + test('renders', () => { + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateTrigger/components/__snapshots__/BucketLevelTriggerGraph.test.js.snap b/public/pages/CreateTrigger/components/__snapshots__/BucketLevelTriggerGraph.test.js.snap new file mode 100644 index 000000000..06b31912c --- /dev/null +++ b/public/pages/CreateTrigger/components/__snapshots__/BucketLevelTriggerGraph.test.js.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BucketLevelTriggerGraph renders 1`] = ` +
+ +
+`; diff --git a/public/pages/CreateTrigger/components/__snapshots__/TriggerGraph.test.js.snap b/public/pages/CreateTrigger/components/__snapshots__/TriggerGraph.test.js.snap new file mode 100644 index 000000000..70f3c8791 --- /dev/null +++ b/public/pages/CreateTrigger/components/__snapshots__/TriggerGraph.test.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TriggerGraph renders 1`] = ` +
+ + + +
+`; diff --git a/public/pages/Dashboard/containers/Dashboard.test.js b/public/pages/Dashboard/containers/Dashboard.test.js index 345b3832d..4f440e976 100644 --- a/public/pages/Dashboard/containers/Dashboard.test.js +++ b/public/pages/Dashboard/containers/Dashboard.test.js @@ -36,6 +36,45 @@ const location = { state: undefined, }; +const sampleQueryAlerts = [ + { + id: 'Ciw2DH0B3-v9t8HD4m3Q', + monitor_id: '7SwkDH0B3-v9t8HDk2zN', + schema_version: 3, + monitor_version: 2, + monitor_name: 'test-query-monitor', + trigger_id: '7CwkDH0B3-v9t8HDk2w_', + trigger_name: 'test-query-trigger', + state: 'ACTIVE', + error_message: null, + alert_history: [], + severity: '1', + action_execution_results: [], + start_time: 1636587463371, + last_notification_time: 1636587523369, + end_time: null, + acknowledged_time: null, + }, + { + id: 'Cyw2DH0B3-v9t8HD4m3Q', + monitor_id: '7SwkDH0B3-v9t8HDk2zN', + schema_version: 3, + monitor_version: 2, + monitor_name: 'test-query-monitor', + trigger_id: '_iw2DH0B3-v9t8HDNWwE', + trigger_name: 'test-query-trigger2', + state: 'ACTIVE', + error_message: null, + alert_history: [], + severity: '1', + action_execution_results: [], + start_time: 1636587463371, + last_notification_time: 1636587523370, + end_time: null, + acknowledged_time: null, + }, +]; + const runAllPromises = () => new Promise(setImmediate); describe('Dashboard', () => { @@ -43,7 +82,7 @@ describe('Dashboard', () => { jest.clearAllMocks(); }); - test('renders', () => { + test('renders with per alert view', () => { const resp = { ok: true, alerts: [], @@ -53,7 +92,56 @@ describe('Dashboard', () => { httpClientMock.get = jest.fn().mockImplementation(() => Promise.resolve(resp)); const wrapper = mount( - + + ); + + expect(wrapper).toMatchSnapshot(); + }); + + test('renders with alert by triggers view', () => { + const resp = { + ok: true, + alerts: [], + totalAlerts: 0, + }; + + httpClientMock.get = jest.fn().mockImplementation(() => Promise.resolve(resp)); + + const wrapper = mount( + + ); + + expect(wrapper).toMatchSnapshot(); + }); + + test('renders in flyout', () => { + const resp = { + ok: true, + alerts: [], + totalAlerts: 0, + }; + + httpClientMock.get = jest.fn().mockImplementation(() => Promise.resolve(resp)); + + const wrapper = mount( + ); expect(wrapper).toMatchSnapshot(); @@ -104,4 +192,31 @@ describe('Dashboard', () => { expect(wrapper.instance().state.alerts[0].alert_history).toStrictEqual([]); expect(wrapper.instance().state.alerts[0].error_message).toBe(''); }); + + test.skip('able to select single alert in flyout', () => { + const resp = { + ok: true, + alerts: [], + totalAlerts: 0, + }; + + httpClientMock.get = jest.fn().mockImplementation(() => Promise.resolve(resp)); + + const wrapper = mount( + + ); + //TODO: Figure out how to find the 1 acknowledge button out of 3 nodes + expect(wrapper.find('[data-test-subj="acknowledgeButton"]').is('[disabled]')).toBe(true); + wrapper + .find('[data-test-subj="checkboxSelectRow-Ciw2DH0B3-v9t8HD4m3Q-3"]') + .hostNodes() + .simulate('change'); + expect(wrapper.find('[data-test-subj="acknowledgeButton"]').is('[disabled]')).toBe(false); + }); }); diff --git a/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap b/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap index 5532eefe1..0476105c2 100644 --- a/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap +++ b/public/pages/Dashboard/containers/__snapshots__/Dashboard.test.js.snap @@ -1,8 +1,48 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Dashboard renders 1`] = ` +exports[`Dashboard renders in flyout 1`] = ` - View alert details - , - Alerts by triggers + Alerts
@@ -139,53 +175,6 @@ exports[`Dashboard renders 1`] = ` > -
- - - - - -
-
-
- -
- - -
-
- - - - -
- - - - - -
-
-
-
-
-
-
-
@@ -863,27 +715,18 @@ exports[`Dashboard renders 1`] = ` columns={ Array [ Object { - "field": "total", - "name": "Alerts", + "dataType": "date", + "field": "start_time", + "name": "Alert start time", "render": [Function], "sortable": true, "truncateText": false, }, Object { - "field": "ACTIVE", - "name": "Active", - "sortable": true, - "truncateText": false, - }, - Object { - "field": "ACKNOWLEDGED", - "name": "Acknowledged", - "sortable": true, - "truncateText": false, - }, - Object { - "field": "ERROR", - "name": "Errors", + "dataType": "date", + "field": "end_time", + "name": "Alert end time", + "render": [Function], "sortable": true, "truncateText": false, }, @@ -895,34 +738,25 @@ exports[`Dashboard renders 1`] = ` "truncateText": true, }, Object { - "dataType": "date", - "field": "start_time", - "name": "Trigger start time", - "render": [Function], - "sortable": true, + "field": "severity", + "name": "Severity", + "sortable": false, "truncateText": false, }, Object { - "dataType": "date", - "field": "last_notification_time", - "name": "Trigger last updated", + "field": "state", + "name": "State", "render": [Function], - "sortable": true, - "truncateText": true, - }, - Object { - "field": "severity", - "name": "Severity", "sortable": false, "truncateText": false, }, Object { - "field": "monitor_name", - "name": "Monitor name", + "dataType": "date", + "field": "acknowledged_time", + "name": "Time acknowledged", "render": [Function], "sortable": true, - "textOnly": true, - "truncateText": true, + "truncateText": false, }, ] } @@ -931,6 +765,19 @@ 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 { @@ -1021,59 +868,31 @@ exports[`Dashboard renders 1`] = ` items={ Array [ Object { - "isSortAscending": undefined, - "isSorted": false, - "key": "_data_s_total_0", - "name": "Alerts", + "isSortAscending": false, + "isSorted": true, + "key": "_data_s_start_time_0", + "name": "Alert start time", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_ACTIVE_1", - "name": "Active", + "key": "_data_s_end_time_1", + "name": "Alert end time", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_ACKNOWLEDGED_2", - "name": "Acknowledged", + "key": "_data_s_trigger_name_2", + "name": "Trigger name", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "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_last_notification_time_6", - "name": "Trigger last updated", - "onSort": [Function], - }, - Object { - "isSortAscending": undefined, - "isSorted": false, - "key": "_data_s_monitor_name_8", - "name": "Monitor name", + "key": "_data_s_acknowledged_time_5", + "name": "Time acknowledged", "onSort": [Function], }, ] @@ -1258,16 +1077,17 @@ exports[`Dashboard renders 1`] = ` + + + Severity + + +
- + + + State + + +
+ + + + + +
+ + + + + +
+
+ + + + + + + +
+ +
+ +
+ + +
+
+
+ + +
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + + +
+
+
+
+
+ +
+
+ } + onChange={[Function]} + responsive={true} + selection={ + Object { + "onSelectionChange": [Function], + "selectable": [Function], + "selectableMessage": [Function], + } + } + sorting={ + Object { + "sort": Object { + "direction": "desc", + "field": "start_time", + }, + } + } + tableLayout="fixed" + > +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + +
+
+ + + +
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ +
+
+ + +
+
+ + + + + + + + + + + + + + +
+ + + Severity + + +
+
+ +
+
+ + + + Create monitor + + } + body={ + +

+ There are no existing alerts. Create a monitor to add triggers and actions. Once an alarm is triggered, the state will show in this table. +

+
+ } + style={ + Object { + "maxWidth": "45em", + } + } + > +
+ + + +
+ +
+

+ There are no existing alerts. Create a monitor to add triggers and actions. Once an alarm is triggered, the state will show in this table. +

+
+
+
+
+
+
+ +
+ + + + + + +
+
+
+
+
+ +
+
+ + + +`; + +exports[`Dashboard renders with per alert view 1`] = ` + + + Acknowledge + , + ] + } + bodyStyles={ + Object { + "padding": "initial", + } + } + title="Alerts" + titleSize="l" + > + +
+ +
+ +
+ +

+ Alerts +

+
+
+
+ +
+ +
+ +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ +
+ +
+ + +
+
+
+ + +
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+ +
+ + + +
+
+
+
+
+ +
+
+ } + onChange={[Function]} + pagination={ + Object { + "pageIndex": 0, + "pageSize": 20, + "pageSizeOptions": Array [ + 5, + 10, + 20, + 50, + ], + "totalItemCount": 0, + } + } + responsive={true} + selection={ + Object { + "onSelectionChange": [Function], + "selectable": [Function], + "selectableMessage": [Function], + } + } + sorting={ + Object { + "sort": Object { + "direction": "desc", + "field": "start_time", + }, + } + } + tableLayout="fixed" + > +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + +
+
+ + + +
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ +
+
+ + +
+
+ + + + + +
+ + + State + + +
+
- Monitor name + Time acknowledged @@ -1830,12 +5067,12 @@ exports[`Dashboard renders 1`] = ` > /public/app.js', '!/public/actions/**', '!/public/components/Charts/Highlight/Highlight.js', '!/public/reducers/**', @@ -55,6 +56,10 @@ module.exports = { '!/scripts/**', '!/build/**', '!/gather-info.js', + '!/cypress/**', '!**/vendor/**', ], + clearMocks: true, + testPathIgnorePatterns: ['/build/', '/node_modules/'], + modulePathIgnorePatterns: ['alertingDashboards'], };