Skip to content

Commit

Permalink
Adds integration tests in the repo for customImportMap plugin (#30)
Browse files Browse the repository at this point in the history
* adds github workflow for cypress tests

Signed-off-by: Shivam Dhar <dhshivam@amazon.com>
  • Loading branch information
Shivamdhar authored Aug 17, 2022
1 parent e7cef5b commit 02fb05e
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 2 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/cypress-workflow.yml
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Unit tests](https://github.com/opensearch-project/dashboards-maps/workflows/Unit%20tests%20workflow/badge.svg)](https://github.com/opensearch-project/dashboards-maps/actions?query=workflow%3A%22Unit+tests+workflow%22)
[![Integration tests](https://github.com/opensearch-project/dashboards-maps/workflows/E2E%20Cypress%20tests/badge.svg)](https://github.com/opensearch-project/dashboards-maps/actions?query=workflow%3A%22E2E+Cypress+tests%22)
[![codecov](https://codecov.io/gh/opensearch-project/dashboards-maps/branch/main/graph/badge.svg)](https://codecov.io/gh/opensearch-project/dashboards-maps)
[![Forum](https://img.shields.io/badge/chat-on%20forums-blue)](https://forum.opensearch.org/)
![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success)
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/custom_import_map/cypress.json
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"
}
}


Large diffs are not rendered by default.

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();
})
});
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();
})
});
26 changes: 26 additions & 0 deletions src/plugins/custom_import_map/cypress/plugins/index.js
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
};
71 changes: 71 additions & 0 deletions src/plugins/custom_import_map/cypress/support/commands.js
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));
});
9 changes: 9 additions & 0 deletions src/plugins/custom_import_map/cypress/support/constants.js
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',
};
42 changes: 42 additions & 0 deletions src/plugins/custom_import_map/cypress/support/index.js
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')}`);
}
6 changes: 6 additions & 0 deletions src/plugins/custom_import_map/cypress/utils/constants.js
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');
Loading

0 comments on commit 02fb05e

Please sign in to comment.