-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds integration tests in the repo for customImportMap plugin (#30)
* adds github workflow for cypress tests Signed-off-by: Shivam Dhar <dhshivam@amazon.com>
- Loading branch information
1 parent
e7cef5b
commit 02fb05e
Showing
13 changed files
with
381 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
name: E2E Cypress tests | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- 2.* | ||
push: | ||
branches: | ||
- main | ||
- 2.* | ||
env: | ||
OPENSEARCH_DASHBOARDS_VERSION: '2.2' | ||
OPENSEARCH_VERSION: '2.2.0-SNAPSHOT' | ||
jobs: | ||
tests: | ||
name: Run Cypress E2E tests | ||
runs-on: ubuntu-latest | ||
env: | ||
# prevents extra Cypress installation progress messages | ||
CI: 1 | ||
# avoid warnings like "tput: No value for $TERM and no -T specified" | ||
TERM: xterm | ||
steps: | ||
- name: Set up JDK | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Checkout geospatial plugin | ||
uses: actions/checkout@v2 | ||
with: | ||
path: geospatial | ||
repository: opensearch-project/geospatial | ||
ref: '2.2' | ||
- name: Run Opensearch with plugin | ||
run: | | ||
cd geospatial | ||
./gradlew run & | ||
timeout 600 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9200)" != "200" ]]; do sleep 5; done' | ||
- name: Checkout Plugin | ||
uses: actions/checkout@v2 | ||
with: | ||
path: dashboards-maps | ||
|
||
- name: Checkout OpenSearch Dashboards | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: opensearch-project/OpenSearch-Dashboards | ||
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }} | ||
path: OpenSearch-Dashboards | ||
|
||
- name: Get node and yarn versions | ||
id: versions_step | ||
run: | | ||
echo "::set-output name=node_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.node).match(/[.0-9]+/)[0]")" | ||
echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.yarn).match(/[.0-9]+/)[0]")" | ||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ steps.versions_step.outputs.node_version }} | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install correct yarn version for OpenSearch Dashboards | ||
run: | | ||
npm uninstall -g yarn | ||
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}" | ||
npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }} | ||
- name: Move custom_import_map to Plugins Dir | ||
run: | | ||
mv dashboards-maps/src/plugins/custom_import_map OpenSearch-Dashboards/plugins/custom_import_map | ||
- name: Bootstrap plugin/opensearch-dashboards | ||
run: | | ||
cd OpenSearch-Dashboards/plugins/custom_import_map | ||
yarn osd bootstrap | ||
- name: Run OpenSearch Dashboards server | ||
run: | | ||
cd OpenSearch-Dashboards | ||
yarn start --no-base-path --no-watch & | ||
sleep 300 | ||
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:5601/api/status)" != "200" ]]; do sleep 5; done' | ||
- name: Run Cypress tests | ||
uses: cypress-io/github-action@v2 | ||
with: | ||
working-directory: OpenSearch-Dashboards/plugins/custom_import_map | ||
command: yarn run cypress run | ||
wait-on: 'http://localhost:5601' | ||
browser: chrome | ||
|
||
# Screenshots are only captured on failure, will change this once we do visual regression tests | ||
- uses: actions/upload-artifact@v1 | ||
if: failure() | ||
with: | ||
name: cypress-screenshots | ||
path: OpenSearch-Dashboards/plugins/custom_import_map/cypress/screenshots | ||
|
||
# Test run video was always captured, so this action uses "always()" condition | ||
- uses: actions/upload-artifact@v1 | ||
if: always() | ||
with: | ||
name: cypress-videos | ||
path: OpenSearch-Dashboards/plugins/custom_import_map/cypress/videos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"defaultCommandTimeout": 10000, | ||
"env": { | ||
"opensearch_url": "localhost:9200", | ||
"opensearch_dashboards": "http://localhost:5601", | ||
"security_enabled": false, | ||
"base_url": "http://localhost:5601", | ||
"username": "admin", | ||
"password": "admin" | ||
} | ||
} | ||
|
||
|
8 changes: 8 additions & 0 deletions
8
src/plugins/custom_import_map/cypress/fixtures/sample_geojson.json
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/plugins/custom_import_map/cypress/integration/geojson_file_upload.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { BASE_PATH } from '../utils/constants'; | ||
import 'cypress-file-upload'; | ||
|
||
describe('Verify successful custom geojson file upload', () => { | ||
before(() => { | ||
cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`); | ||
// Click on "Sample data" tab | ||
cy.contains('Sample data', { timeout: 60000 }).click({ force: true }); | ||
// Load sample flights data | ||
cy.get(`button[data-test-subj="addSampleDataSetflights"]`).click({ | ||
force: true, | ||
}); | ||
|
||
// Verify that sample data is add by checking toast notification | ||
cy.contains('Sample flight data installed', { timeout: 60000 }); | ||
|
||
cy.visit(`${BASE_PATH}/app/visualize#/`); | ||
|
||
// Click on "Create Visualization" tab | ||
cy.contains('Create visualization').click({ force: true }); | ||
|
||
// Click on "Region Map" icon | ||
cy.contains('Region Map').click({ force: true }); | ||
|
||
// Select index source - [Flights] Flight Log | ||
cy.contains('[Flights] Flight Log').click({ force: true }); | ||
}); | ||
|
||
it('checks if the file uploaded successfully', () => { | ||
// Click on "Import Vector Map" tab, which is part of customImportMap plugin | ||
cy.contains('Import Vector Map').click({ force: true }); | ||
|
||
cy.get('[data-testId="filePicker"]').attachFile('sample_geojson.json'); | ||
cy.get('[data-testId="customIndex"]').type('sample'); | ||
cy.contains('Import file').click({ force: true }); | ||
cy.contains('Successfully added 2 features to sample-map. Refresh to visualize the uploaded map.', { timeout: 60000 }); | ||
}) | ||
|
||
after(() => { | ||
cy.visit(`${BASE_PATH}/app/home#/tutorial_directory`); | ||
cy.get('button[data-test-subj="removeSampleDataSetflights"]').should('be.visible').click(); | ||
}) | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/plugins/custom_import_map/cypress/integration/import_vector_map_tab.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { BASE_PATH } from '../utils/constants'; | ||
|
||
describe('Verify the presence of import custom map tab in region map plugin', () => { | ||
before(() => { | ||
cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`); | ||
// Click on "Sample data" tab | ||
cy.contains('Sample data', { timeout: 60000 }).click({ force: true }); | ||
// Load sample flights data | ||
cy.get(`button[data-test-subj="addSampleDataSetflights"]`).click({ | ||
force: true, | ||
}); | ||
|
||
// Verify that sample data is add by checking toast notification | ||
cy.contains('Sample flight data installed', { timeout: 60000 }); | ||
|
||
cy.visit(`${BASE_PATH}/app/visualize#/`); | ||
|
||
// Click on "Create Visualization" tab | ||
cy.contains('Create visualization').click({ force: true }); | ||
|
||
// Click on "Region Map" icon | ||
cy.contains('Region Map').click({ force: true }); | ||
|
||
// Select index source - [Flights] Flight Log | ||
cy.contains('[Flights] Flight Log').click({ force: true }); | ||
}); | ||
|
||
it('checks import custom map tab is present', () => { | ||
// Click on "Import Vector Map" tab, which is part of customImportMap plugin | ||
cy.contains('Import Vector Map').click({ force: true }); | ||
}) | ||
|
||
after(() => { | ||
cy.visit(`${BASE_PATH}/app/home#/tutorial_directory`); | ||
cy.get('button[data-test-subj="removeSampleDataSetflights"]').should('be.visible').click(); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/// <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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const { ADMIN_AUTH } = require('./constants'); | ||
|
||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add("login", (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) | ||
|
||
Cypress.Commands.overwrite('visit', (originalFn, url, options) => { | ||
// Add the basic auth header when security enabled in the Opensearch cluster | ||
// https://github.com/cypress-io/cypress/issues/1288 | ||
if (Cypress.env('security_enabled')) { | ||
if (options) { | ||
options.auth = ADMIN_AUTH; | ||
} else { | ||
options = { auth: ADMIN_AUTH }; | ||
} | ||
// Add query parameters - select the default OpenSearch Dashboards tenant | ||
options.qs = { security_tenant: 'private' }; | ||
return originalFn(url, options); | ||
} else { | ||
return originalFn(url, options); | ||
} | ||
}); | ||
|
||
// Be able to add default options to cy.request(), https://github.com/cypress-io/cypress/issues/726 | ||
Cypress.Commands.overwrite('request', (originalFn, ...args) => { | ||
let defaults = {}; | ||
// Add the basic authentication header when security enabled in the Opensearch cluster | ||
if (Cypress.env('security_enabled')) { | ||
defaults.auth = ADMIN_AUTH; | ||
} | ||
|
||
let options = {}; | ||
if (typeof args[0] === 'object' && args[0] !== null) { | ||
options = Object.assign({}, args[0]); | ||
} else if (args.length === 1) { | ||
[options.url] = args; | ||
} else if (args.length === 2) { | ||
[options.method, options.url] = args; | ||
} else if (args.length === 3) { | ||
[options.method, options.url, options.body] = args; | ||
} | ||
|
||
return originalFn(Object.assign({}, defaults, options)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const ADMIN_AUTH = { | ||
username: 'admin', | ||
password: 'admin', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// *********************************************************** | ||
// 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') | ||
|
||
// ignore the error "ResizeObserver loop limit exceeded", https://github.com/quasarframework/quasar/issues/2233 | ||
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/; | ||
Cypress.on('uncaught:exception', (err) => { | ||
/* returning false here prevents Cypress from failing the test */ | ||
if (resizeObserverLoopErrRe.test(err.message)) { | ||
return false; | ||
} | ||
}); | ||
|
||
// Switch the base URL of Opensearch when security enabled in the cluster | ||
// Dashboard endpoint can still be http when security enabled | ||
if (Cypress.env('security_enabled')) { | ||
Cypress.env('opensearch', `https://${Cypress.env('opensearch_url')}`); | ||
} else { | ||
Cypress.env('opensearch', `http://${Cypress.env('opensearch_url')}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const BASE_PATH = Cypress.env('base_url'); |
Oops, something went wrong.