Skip to content

Commit

Permalink
Add AD cypress tests for uncovered workflows and pages (#95)
Browse files Browse the repository at this point in the history
* Add test coverage for AD plugin

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add helpers file

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Remove unused constants/helpers/fixtures

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add tests for checking flyouts

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Make sample detector WF more efficient; set up config page test suite

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add detector config page tests

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add tests for real-time results page

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add historical results tests

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add back missing import

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Reorganize tests; add historical analysis test

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Update test data

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Rename historical analysis test suite

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Add more historical analysis tests

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler authored Mar 7, 2022
1 parent 69e7ce3 commit 25afb70
Showing 24 changed files with 1,013 additions and 347 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"_index": ".opendistro-anomaly-detectors",
"_type": "_doc",
"_id": "ulgqpXEBqtadYz9j2MHG",
"_version": 2,
"result": "deleted",
"forced_refresh": true,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 6,
"_primary_term": 1
"ok": true,
"response": {
"_index": ".opendistro-anomaly-detectors",
"_type": "_doc",
"_id": "nKDQ-n4BQogdTzUQtWpL",
"_version": 2,
"result": "deleted",
"forced_refresh": true,
"_shards": { "total": 2, "successful": 1, "failed": 0 },
"_seq_no": 16,
"_primary_term": 15
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ok": true,
"response": {
"indices": [
{ "health": "green", "index": "feature-required-detector-index" },
{ "health": "green", "index": "initializing-detector-index" },
{ "health": "green", "index": "running-detector-index" },
{ "health": "green", "index": "stopped-detector-index" }
]
}
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
{
"id": "ulgqpXEBqtadYz7j2MHG",
"description": "test",
"indices": ["feature-required-index"],
"indices": ["feature-required-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "feature-required-detector",
"timeField": "timestamp",
@@ -28,7 +28,7 @@
{
"id": "ulgqpXEBqtadYz6j2MHG",
"description": "test",
"indices": ["initializing-index"],
"indices": ["initializing-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "initializing-detector",
"timeField": "timestamp",
@@ -63,7 +63,7 @@
{
"id": "ulgqpXEBqtadYz8j2MHG",
"description": "test",
"indices": ["running-index"],
"indices": ["running-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "running-detector",
"timeField": "timestamp",
@@ -98,7 +98,7 @@
{
"id": "ulgqpXEBqtadYz9j2MHG",
"description": "test",
"indices": ["stopped-index"],
"indices": ["stopped-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "stopped-detector",
"timeField": "timestamp",

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"index":{"_id": "id-1"}}
{ "value": 1, "timestamp": "2020-01-01"}
{"index":{"_id": "id-2"}}
{ "value": 2, "timestamp": "2020-01-02"}
{"index":{"_id": "id-3"}}
{ "value": 3, "timestamp": "2020-01-03"}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"ok": true,
"response": {
"mappings": {
"e2e-test-index": {
"test-index": {
"mappings": {
"properties": {
"timestamp": {
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ok": true,
"response": {
"indices": [{ "health": "green", "index": "test-index" }]
}
}
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"detectorList": [
{
"id": "ulgqpXEBqtadYz9j2MHG",
"description": "test",
"indices": ["test-index"],
"description": "A running detector.",
"indices": ["running-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "running-detector",
"timeField": "timestamp",
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"detectorList": [
{
"id": "ulgqpXEBqtadYz9j2MHG",
"description": "test",
"indices": ["test-index"],
"description": "A stopped detector.",
"indices": ["stopped-detector-index"],
"lastUpdateTime": 1587614056945,
"name": "stopped-detector",
"timeField": "timestamp",

This file was deleted.

Original file line number Diff line number Diff line change
@@ -3,48 +3,91 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
AD_FIXTURE_BASE_PATH,
BASE_AD_CREATE_AD_PATH,
} from '../../../utils/constants';

context('Create detector', () => {
it.skip('Create detector - from dashboard', () => {
cy.mockSearchIndexOnAction(
AD_FIXTURE_BASE_PATH + 'search_index_response.json',
() => {
cy.visit(BASE_AD_CREATE_AD_PATH);
}
);
import { AD_FIXTURE_BASE_PATH, AD_URL } from '../../../utils/constants';
import { selectTopItemFromFilter } from '../../../utils/helpers';

cy.contains('h1', 'Create detector');
context('Create detector workflow', () => {
const TEST_DETECTOR_NAME = 'test-detector';
const TEST_DETECTOR_DESCRIPTION = 'Some test detector description.';
const TEST_FEATURE_NAME = 'test-feature';
const TEST_TIMESTAMP_NAME = 'timestamp'; // coming from single_index_response.json fixture
const TEST_INDEX_NAME = 'ad-cypress-test-index';

const detectorName = 'detector-name';
cy.get('input[name="detectorName"]').type(detectorName, { force: true });
// Index some sample data first
before(() => {
cy.server();
cy.fixture(AD_FIXTURE_BASE_PATH + 'sample_test_data.txt').then((data) => {
cy.request({
method: 'POST',
form: true,
url: 'api/console/proxy',
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
},
qs: {
path: `${TEST_INDEX_NAME}/_bulk`,
method: 'POST',
},
body: data,
});
});
});

cy.mockGetIndexMappingsOnAction(
AD_FIXTURE_BASE_PATH + 'index_mapping_response.json',
() => {
cy.get('input[role="textbox"]').first().type('e2e-test-index{enter}', {
force: true,
});
}
// Clean up created resources
after(() => {
cy.log('Deleting index with name: ' + TEST_INDEX_NAME);
cy.deleteIndex(TEST_INDEX_NAME);
});

it('Full creation - based on real index', () => {
// Define detector step
cy.visit(AD_URL.CREATE_AD);
cy.getElementByTestId('defineOrEditDetectorTitle').should('exist');
cy.getElementByTestId('detectorNameTextInput').type(TEST_DETECTOR_NAME);
cy.getElementByTestId('detectorDescriptionTextInput').type(
TEST_DETECTOR_DESCRIPTION
);
cy.getElementByTestId('indicesFilter').type(`${TEST_INDEX_NAME}{enter}`);
selectTopItemFromFilter('timestampFilter', false);
cy.getElementByTestId('defineDetectorNextButton').click();
cy.getElementByTestId('defineOrEditDetectorTitle').should('not.exist');
cy.getElementByTestId('configureOrEditModelConfigurationTitle').should(
'exist'
);

cy.get('input[role="textbox"]').last().type('timestamp{enter}', {
force: true,
});
// Configure model step
cy.getElementByTestId('featureNameTextInput-0').type(TEST_FEATURE_NAME);
selectTopItemFromFilter('featureFieldTextInput-0', false);
cy.getElementByTestId('configureModelNextButton').click();
cy.getElementByTestId('configureOrEditModelConfigurationTitle').should(
'not.exist'
);
cy.getElementByTestId('detectorJobsTitle').should('exist');

cy.mockCreateDetectorOnAction(
AD_FIXTURE_BASE_PATH + 'post_detector_response.json',
() => {
cy.get('[data-test-subj=createOrSaveDetectorButton]').click({
force: true,
});
}
// Set up detector jobs step
cy.getElementByTestId('detectorJobsNextButton').click();
cy.getElementByTestId('detectorJobsTitle').should('not.exist');
cy.getElementByTestId('reviewAndCreateTitle').should('exist');

// Review and create step
cy.getElementByTestId('detectorNameCell').contains(TEST_DETECTOR_NAME);
cy.getElementByTestId('detectorDescriptionCell').contains(
TEST_DETECTOR_DESCRIPTION
);
cy.getElementByTestId('indexNameCell').contains(TEST_INDEX_NAME);
cy.getElementByTestId('timestampNameCell').contains(TEST_TIMESTAMP_NAME);
cy.getElementByTestId('featureTable').contains(TEST_FEATURE_NAME);
cy.getElementByTestId('createDetectorButton').click();

cy.contains('h1', detectorName);
cy.contains('h3', 'Detector configuration');
// Clean up the created detector. Extract detector ID from the detector configuration page
cy.getElementByTestId('detectorIdCell').within(() => {
cy.get('.euiText--medium')
.invoke('text')
.then((detectorId) => {
cy.log('Deleting detector with ID: ' + detectorId);
cy.deleteDetector(detectorId);
});
});
});
});
Loading

0 comments on commit 25afb70

Please sign in to comment.