Skip to content

Commit

Permalink
Adding basic unit tests (opensearch-project#151)
Browse files Browse the repository at this point in the history
* Add flyout render

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Add some basic tests

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Add more tests

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update jest.config.js

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Add tests

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update dashboard sample alerttime

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update dashboard test alert time snapshot

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update Dashboard.test.js

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Remove test alert start time

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update VisualGraph test and code

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update package.json to run unit tests in UTC timezone

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update dashboard sample alert start time

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update Dashboard test

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update Dashboard.test.js.snap

Signed-off-by: Annie Lee <leeyun@amazon.com>

* Update snapshot file

Signed-off-by: Annie Lee <leeyun@amazon.com>
  • Loading branch information
annie3431 authored and Annie Lee committed Feb 17, 2022
1 parent da762b7 commit 4eefe97
Show file tree
Hide file tree
Showing 24 changed files with 5,329 additions and 466 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 4 additions & 11 deletions public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}</>;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <VisualGraph values={FORMIK_INITIAL_VALUES} />;
const component = (
<VisualGraph
values={FORMIK_INITIAL_VALUES}
fieldName="doc_count"
response={queryGraphResponse}
/>
);
expect(render(component)).toMatchSnapshot();
});

test('renders with bucket level monitor', () => {
const values = FORMIK_INITIAL_VALUES;
values.monitor_type = MONITOR_TYPE.BUCKET_LEVEL;
const component = (
<VisualGraph
values={bucketMonitorValues}
fieldName="doc_count"
response={bucketGraphResponse}
/>
);
expect(render(component)).toMatchSnapshot();
});
});
Loading

0 comments on commit 4eefe97

Please sign in to comment.