Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Initial test case using Cypress (#196)
Browse files Browse the repository at this point in the history
* Initial test case using Cypress

* Add readme for how to run e2e tests
  • Loading branch information
yizheliu-amazon authored Jun 4, 2020
1 parent e12442f commit 3179e88
Show file tree
Hide file tree
Showing 13 changed files with 707 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["plugin:cypress/recommended"]
}
4 changes: 4 additions & 0 deletions .cypress/fixtures/no_detector_index_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ok": false,
"error": "[index_not_found_exception] no such index [.opendistro-anomaly-detectors], with { resource.type=\"index_or_alias\" & resource.id=\".opendistro-anomaly-detectors\" & index_uuid=\"_na_\" & index=\".opendistro-anomaly-detectors\" }"
}
43 changes: 43 additions & 0 deletions .cypress/integration/ad/dashboard/ad_dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/// <reference types="cypress" />

import {
AD_PATH,
AD_URL,
API_URL_PREFIX,
APP_URL_PREFIX,
DASHBOARD,
DETECTORS,
SLASH,
} from '../../../utils/constants';

context('AD Dashboard', () => {
it('Empty dashboard - no detector', () => {
cy.server();
cy.route(
'GET',
[API_URL_PREFIX, AD_PATH, DETECTORS + '*'].join(SLASH),
'fixture:no_detector_index_response.json'
).as('getDetectors');

cy.visit([APP_URL_PREFIX, AD_URL, DASHBOARD].join(SLASH));

cy.wait('@getDetectors', { requestTimeout: 60_000 });

cy.contains('h2', 'You have no detectors');
});
});
36 changes: 36 additions & 0 deletions .cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
35 changes: 35 additions & 0 deletions .cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
// import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
4 changes: 4 additions & 0 deletions .cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.*"]
}
23 changes: 23 additions & 0 deletions .cypress/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

export const AD_URL = 'opendistro-anomaly-detection-kibana#';
export const APP_URL_PREFIX = 'app';
export const API_URL_PREFIX = 'api';
export const AD_PATH = 'anomaly_detectors';
export const SLASH = '/';

export const DASHBOARD = 'dashboard';
export const DETECTORS = 'detectors';
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ coverage
*.code-workspace
offline-module-cache/v2/*
offline-module-cache/v1/*
.cypress/screenshots
.cypress/videos
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Example output: `./build/opendistro-anomaly-detection-kibana-1.8.0.0.zip`

Runs the plugin tests.

- `yarn test:e2e`

Start Kibana, wait for it to be available on `localhost:5601`, and runs end-to-end tests.

## Contributing to Open Distro for Elasticsearch Anomaly detection Kibana

We welcome you to get involved in development, documentation, testing the anomaly detection plugin. See our [CONTRIBUTING.md](./CONTRIBUTING.md) and join in.
Expand Down
10 changes: 10 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"baseUrl": "http://localhost:5601",
"video": false,
"fixturesFolder": ".cypress/fixtures",
"integrationFolder": ".cypress/integration",
"pluginsFile": ".cypress/plugins/index.js",
"screenshotsFolder": ".cypress/screenshots",
"supportFile": ".cypress/support/index.js",
"videosFolder": ".cypress/videos"
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"test:browser": "plugin-helpers test:browser",
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"build": "plugin-helpers build",
"release": "./tasks/release.sh"
"release": "./tasks/release.sh",
"start-cy-server": "yarn start --no-base-path --oss",
"cy:open": "cypress open",
"cy:run": "cypress run",
"test:e2e": "WAIT_ON_TIMEOUT=900000 start-server-and-test 'yarn start-cy-server' http-get://localhost:5601/app/opendistro-anomaly-detection-kibana 'yarn cy:run'"
},
"lint-staged": {
"*.{ts,tsx,js,jsx,json,css,md}": [
Expand Down Expand Up @@ -53,6 +57,7 @@
"babel-jest": "^24.8.0",
"babel-polyfill": "^6.26.0",
"chance": "^1.1.0",
"cypress": "^4.6.0",
"eslint": "^5.6.0",
"eslint-plugin-babel": "^5.2.0",
"eslint-plugin-import": "^2.14.0",
Expand All @@ -67,11 +72,13 @@
"moment-timezone": "^0.5.26",
"react-router-dom": "^5.0.1",
"redux-mock-store": "^1.5.3",
"start-server-and-test": "^1.11.0",
"typescript": "3.0.3"
},
"dependencies": {
"@elastic/charts": "^18.2.2",
"babel-polyfill": "^6.26.0",
"eslint-plugin-cypress": "^2.11.1",
"formik": "^1.5.8",
"query-string": "^6.8.2",
"react-redux": "^7.1.0",
Expand Down
24 changes: 11 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
"paths": {
// Allows for importing from `kibana` package for the exported types.
"kibana": ["./kibana"],
"ui/*": [
"src/legacy/ui/public/*"
],
"test_utils/*": [
"src/test_utils/public/*"
]
"ui/*": ["src/legacy/ui/public/*"],
"test_utils/*": ["src/test_utils/public/*"]
},
// Support .tsx files and transform JSX into calls to React.createElement
"jsx": "react",
Expand Down Expand Up @@ -49,12 +45,14 @@
// import tslib helpers rather than inlining helpers for iteration or spreading, for instance
"importHelpers": true,
// adding global typings
"types": [
"node",
"jest",
"react"
]
"types": ["node", "jest", "react"]
},
"include": ["server/**/*", "public/**/*", "utils/**/*", "models/**/*", "test/**/*"],
"exclude": ["node_modules", "*/node_modules/"],
"include": [
"server/**/*",
"public/**/*",
"utils/**/*",
"models/**/*",
"test/**/*"
],
"exclude": ["node_modules", "*/node_modules/"]
}
Loading

0 comments on commit 3179e88

Please sign in to comment.