Skip to content

Commit 755b6b6

Browse files
authored
Move over remaining AD tests; clean up cypress run scripts (opensearch-project#89)
Signed-off-by: Tyler Ohlsen <[email protected]>
1 parent d8ead25 commit 755b6b6

17 files changed

+586
-114
lines changed

.github/workflows/cypress-workflow-bundle-snapshot-based.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
uses: cypress-io/github-action@v2
7373
with:
7474
working-directory: monterey-test
75-
command: yarn run cypress run --browser chrome --headless --env SECURITY_ENABLED=true --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/*.js'
75+
command: yarn cypress:run-with-security --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/*.js'
7676
wait-on: 'http://localhost:5601'
7777
# Screenshots are only captured on failure, will change this once we do visual regression tests
7878
- uses: actions/upload-artifact@v1

.github/workflows/cypress-workflow-plugins-bundle-snapshot-based.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
uses: cypress-io/github-action@v2
7373
with:
7474
working-directory: monterey-test
75-
command: env TZ=America/Los_Angeles yarn run cypress run --browser chrome --headless --env SECURITY_ENABLED=true --spec 'cypress/integration/plugins/*/*.js'
75+
command: yarn cypress:run-plugin-tests-with-security
7676
wait-on: 'http://localhost:5601'
7777
# Screenshots are only captured on failure, will change this once we do visual regression tests
7878
- uses: actions/upload-artifact@v1

.github/workflows/cypress-workflow-vanilla-snapshot-based.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
uses: cypress-io/github-action@v2
7171
with:
7272
working-directory: monetery-test
73-
command: yarn run cypress run --browser chrome --headless --env SECURITY_ENABLED=false --spec 'cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js'
73+
command: yarn cypress:run-without-security --spec 'cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js'
7474
wait-on: 'http://localhost:5601'
7575
# Screenshots are only captured on failure, will change this once we do visual regression tests
7676
- uses: actions/upload-artifact@v1

CONTRIBUTING.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ opensearch-dashboards-test-library is the test utility library used by this proj
3434
"@opensearch-dashboards-test/opensearch-dashboards-test-library": "^1.0.1"
3535
```
3636

37-
You can aslo import from the git repository target branch to use the development code directly
37+
You can also import from the git repository target branch to use the development code directly
3838

3939
```
4040
"@opensearch-dashboards-test/opensearch-dashboards-test-library": "opensearch-project/opensearch-dashboards-test-library#main"
@@ -48,28 +48,30 @@ $ npm uninstall @opensearch-dashboards-test/opensearch-dashboards-test-library &
4848

4949
### Run Tests
5050

51-
You can run the cypress tests by cli:
51+
You can run the cypress tests by cli. There are some handy sripts in [package.json](package.json) to run the tests with some pre-set configurations.
52+
53+
To run without security:
5254

5355
```
54-
$ npx cypress run --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js"
56+
$ yarn cypress run-without-security --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js"
5557
```
5658

57-
By default, it uses headless mode (hide the broswer) You can turn on the browser display by:
59+
To run with security:
5860

5961
```
60-
$ npx cypress run --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js --headed"
62+
$ yarn cypress run-with-security --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js"
6163
```
6264

63-
You can also manually trigger the test via browser UI by:
65+
These tests run in headless mode by default. You can also manually trigger the test via browser UI by running:
6466

6567
```
66-
$ npx cypress open
68+
$ yarn cypress open
6769
```
6870

6971
And you can override certain cypress config or environment variable by appling additional cli arguments, for example to override the baseUrl and OpensearchUrl to test a remote endpoint:
7072

7173
```
72-
$ npx cypress run --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js" --env "openSearchUrl=https://foo.com" --config "baseUrl=https://foo.com/_dashboards"
74+
$ yarn cypress run --spec "cypress/integration/core-opensearch-dashboards/vanilla-opensearch-dashboards/*.js" --env "openSearchUrl=https://foo.com" --config "baseUrl=https://foo.com/_dashboards"
7375
```
7476

7577
### Formatting

cypress.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"defaultCommandTimeout": 60000,
3+
"requestTimeout": 60000,
4+
"responseTimeout": 60000,
35
"baseUrl": "http://localhost:5601",
46
"reporter": "cypress-multi-reporters",
57
"reporterOptions": {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"_index": ".opendistro-anomaly-detectors",
3+
"_type": "_doc",
4+
"_id": "ulgqpXEBqtadYz9j2MHG",
5+
"_version": 2,
6+
"result": "deleted",
7+
"forced_refresh": true,
8+
"_shards": {
9+
"total": 2,
10+
"successful": 2,
11+
"failed": 0
12+
},
13+
"_seq_no": 6,
14+
"_primary_term": 1
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"ok": true,
3+
"response": {
4+
"name": "detector-name",
5+
"description": "",
6+
"timeField": "timestamp",
7+
"indices": ["e2e-test-index"],
8+
"detectionInterval": { "period": { "interval": 10, "unit": "Minutes" } },
9+
"windowDelay": { "period": { "interval": 1, "unit": "Minutes" } },
10+
"schemaVersion": 0,
11+
"id": "MiSon3IBq0Ub5wDcgBII",
12+
"primaryTerm": 3,
13+
"seqNo": 41,
14+
"filterQuery": { "match_all": { "boost": 1 } },
15+
"featureAttributes": [],
16+
"uiMetadata": {
17+
"features": {},
18+
"filters": [],
19+
"filterType": "simple_filter"
20+
},
21+
"enabled": false
22+
}
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"ok": true,
3+
"response": {
4+
"totalDetectors": 1,
5+
"detectorList": [
6+
{
7+
"id": "ulgqpXEBqtadYz9j2MHG",
8+
"description": "test",
9+
"indices": ["test-index"],
10+
"lastUpdateTime": 1587614056945,
11+
"name": "stopped-detector",
12+
"timeField": "timestamp",
13+
"detectionInterval": { "period": { "interval": 1, "unit": "Minutes" } },
14+
"windowDelay": { "period": { "interval": 1, "unit": "Minutes" } },
15+
"schemaVersion": 0,
16+
"filterQuery": { "match_all": { "boost": 1 } },
17+
"featureAttributes": [
18+
{
19+
"featureId": "1mMspXEBcngjFp58AS_u",
20+
"featureName": "test-f",
21+
"featureEnabled": true,
22+
"aggregationQuery": { "aa": { "sum": { "field": "value" } } }
23+
}
24+
],
25+
"uiMetadata": {
26+
"features": {
27+
"aa": {
28+
"aggregationBy": "sum",
29+
"aggregationOf": "value",
30+
"featureType": "simple_aggs"
31+
}
32+
},
33+
"filters": [],
34+
"filterType": "simple_filter"
35+
},
36+
"enabled": false,
37+
"totalAnomalies": 0,
38+
"lastActiveAnomaly": 1591593056550,
39+
"curState": "Stopped"
40+
}
41+
]
42+
}
43+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"_id": "ulgqpXEBqtadYz9j2MHG",
3+
"_version": 1,
4+
"_seq_no": 1,
5+
"_primary_term": 1
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Stopped detector": "ulgqpXEBqtadYz9j2MHG"
3+
}

cypress/integration/common/ad_dashboard_sample_data_spec.js

Lines changed: 0 additions & 94 deletions
This file was deleted.

cypress/integration/plugins/anomaly-detection-dashboards-plugin/ad_dashboard_sanity_test_spec.js

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,111 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { adDashboardSanityTests } from '../../common/ad_dashboard_sample_data_spec.js';
6+
import {
7+
AD_FIXTURE_BASE_PATH,
8+
BASE_AD_DASHBOARDS_PATH,
9+
} from '../../../utils/constants';
710

8-
adDashboardSanityTests();
11+
// Contains basic sanity tests on AD Dashboards page
12+
describe('AD Dashboard page', () => {
13+
// start a server so that server responses can be mocked via fixtures
14+
// in all of the below test cases
15+
before(() => {
16+
cy.server();
17+
});
18+
19+
it('empty - no detector index', () => {
20+
cy.mockGetDetectorOnAction(
21+
AD_FIXTURE_BASE_PATH + 'no_detector_index_response.json',
22+
() => {
23+
cy.visit(BASE_AD_DASHBOARDS_PATH);
24+
}
25+
);
26+
cy.contains('h2', 'You have no detectors');
27+
});
28+
29+
it('empty - empty detector index', () => {
30+
cy.mockGetDetectorOnAction(
31+
AD_FIXTURE_BASE_PATH + 'empty_detector_index_response.json',
32+
() => {
33+
cy.visit(BASE_AD_DASHBOARDS_PATH);
34+
}
35+
);
36+
cy.contains('h2', 'You have no detectors');
37+
});
38+
39+
it('non-empty - single running detector', () => {
40+
cy.mockGetDetectorOnAction(
41+
AD_FIXTURE_BASE_PATH + 'single_running_detector_response.json',
42+
() => {
43+
cy.visit(BASE_AD_DASHBOARDS_PATH);
44+
}
45+
);
46+
47+
cy.contains('h3', 'Live anomalies');
48+
cy.contains('a', 'running-detector');
49+
});
50+
51+
it('redirect to create detector page', () => {
52+
cy.mockGetDetectorOnAction(
53+
AD_FIXTURE_BASE_PATH + 'no_detector_index_response.json',
54+
() => {
55+
cy.visit(BASE_AD_DASHBOARDS_PATH);
56+
}
57+
);
58+
59+
cy.mockSearchIndexOnAction(
60+
AD_FIXTURE_BASE_PATH + 'search_index_response.json',
61+
() => {
62+
cy.get('a[data-test-subj="createDetectorButton"]').click({
63+
force: true,
64+
});
65+
}
66+
);
67+
68+
cy.contains('span', 'Create detector');
69+
});
70+
71+
it('filter by detector', () => {
72+
cy.mockGetDetectorOnAction(
73+
AD_FIXTURE_BASE_PATH + 'multiple_detectors_response.json',
74+
() => {
75+
cy.visit(BASE_AD_DASHBOARDS_PATH);
76+
}
77+
);
78+
79+
cy.contains('stopped-detector');
80+
cy.contains('running-detector');
81+
82+
cy.get('[data-test-subj=comboBoxToggleListButton]')
83+
.first()
84+
.click({ force: true });
85+
cy.get('.euiFilterSelectItem').first().click({ force: true });
86+
cy.get('.euiPageSideBar').click({ force: true });
87+
88+
cy.contains('feature-required-detector'); // first one in the list returned by multiple_detectors_response.json
89+
cy.contains('stopped-detector').should('not.be.visible');
90+
cy.contains('running-detector').should('not.be.visible');
91+
});
92+
93+
it('filter by detector state', () => {
94+
cy.mockGetDetectorOnAction(
95+
AD_FIXTURE_BASE_PATH + 'multiple_detectors_response.json',
96+
() => {
97+
cy.visit(BASE_AD_DASHBOARDS_PATH);
98+
}
99+
);
100+
101+
cy.contains('stopped-detector');
102+
cy.contains('running-detector');
103+
104+
cy.get('[data-test-subj=comboBoxToggleListButton]')
105+
.eq(1)
106+
.click({ force: true });
107+
cy.get('.euiFilterSelectItem').first().click({ force: true });
108+
cy.get('.euiPageSideBar').click({ force: true });
109+
110+
cy.contains('stopped-detector'); // because stopped is the first item in the detector state dropdown
111+
cy.contains('running-detector').should('not.be.visible');
112+
});
113+
});

0 commit comments

Comments
 (0)