From 5e6eaba4683d28ecd0b4c3392faaccf59dae5729 Mon Sep 17 00:00:00 2001 From: Jialiang Liang <109499885+RyanL1997@users.noreply.github.com> Date: Sun, 14 Jan 2024 19:48:14 -0800 Subject: [PATCH] Add functional test for datasources at observability dashboards plugin (#987) * Add functional test for datasources at observability dashboards plugin Signed-off-by: Ryan Liang * Extend the header locating to 2 mins Signed-off-by: Ryan Liang * Fix lint Signed-off-by: Ryan Liang --------- Signed-off-by: Ryan Liang (cherry picked from commit 8cd68dc509eeb01ca7658f1f784201ce117cf009) --- .../7_datasources_dashboard.spec.js | 82 +++++++++++++++++++ .../observability-dashboards/constants.js | 7 ++ 2 files changed, 89 insertions(+) create mode 100644 cypress/integration/plugins/observability-dashboards/7_datasources_dashboard.spec.js diff --git a/cypress/integration/plugins/observability-dashboards/7_datasources_dashboard.spec.js b/cypress/integration/plugins/observability-dashboards/7_datasources_dashboard.spec.js new file mode 100644 index 000000000..ac554e5d1 --- /dev/null +++ b/cypress/integration/plugins/observability-dashboards/7_datasources_dashboard.spec.js @@ -0,0 +1,82 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/// + +import { BASE_PATH } from '../../../utils/base_constants'; + +import { + DATASOURCES_API_PREFIX, + DATASOURCES_PATH, +} from '../../../utils/plugins/observability-dashboards/constants'; + +const manageDataSourcesTag = 'button[data-test-subj="manage"]'; +const newDataSourcesTag = 'button[data-test-subj="new"]'; +const createS3Button = '[data-test-subj="datasource_card_s3glue"]'; +const createPrometheusButton = '[data-test-subj="datasource_card_prometheus"]'; + +const visitDatasourcesHomePage = () => { + cy.visit(BASE_PATH + DATASOURCES_API_PREFIX); +}; + +const visitDatasourcesCreationPage = () => { + cy.visit(BASE_PATH + DATASOURCES_PATH.DATASOURCES_CREATION_BASE); +}; + +describe('Integration tests for datasources plugin', () => { + it('Navigates to datasources plugin and expects the correct header', () => { + visitDatasourcesHomePage(); + cy.get('[data-test-subj="dataconnections-header"]', { + timeout: 120000, + }).should('exist'); + }); + + it('Tests navigation between tabs', () => { + visitDatasourcesHomePage(); + + cy.get(manageDataSourcesTag) + .should('have.class', 'euiTab-isSelected') + .and('have.attr', 'aria-selected', 'true'); + cy.get(manageDataSourcesTag).click(); + cy.url().should('include', '/manage'); + + cy.get(newDataSourcesTag).click(); + cy.get(newDataSourcesTag) + .should('have.class', 'euiTab-isSelected') + .and('have.attr', 'aria-selected', 'true'); + cy.url().should('include', '/new'); + + cy.get(createS3Button).should('be.visible'); + cy.get(createPrometheusButton).should('be.visible'); + }); + + it('Tests navigation of S3 datasources creation page with hash', () => { + visitDatasourcesCreationPage(); + + cy.get(createS3Button).should('be.visible').click(); + cy.url().should( + 'include', + DATASOURCES_PATH.DATASOURCES_CONFIG_BASE + '/AmazonS3AWSGlue' + ); + + cy.get('h1.euiTitle.euiTitle--medium') + .should('be.visible') + .and('contain', 'Configure Amazon S3 data source'); + }); + + it('Tests navigation of Prometheus datasources creation page with hash', () => { + visitDatasourcesCreationPage(); + + cy.get(createPrometheusButton).should('be.visible').click(); + cy.url().should( + 'include', + DATASOURCES_PATH.DATASOURCES_CONFIG_BASE + '/Prometheus' + ); + + cy.get('h4.euiTitle.euiTitle--medium') + .should('be.visible') + .and('contain', 'Configure Prometheus data source'); + }); +}); diff --git a/cypress/utils/plugins/observability-dashboards/constants.js b/cypress/utils/plugins/observability-dashboards/constants.js index 2d59cf04d..ac1c15566 100644 --- a/cypress/utils/plugins/observability-dashboards/constants.js +++ b/cypress/utils/plugins/observability-dashboards/constants.js @@ -6,6 +6,13 @@ import { BASE_PATH } from '../../base_constants'; export const delayTime = 1500; +//Datasources API Constants +export const DATASOURCES_API_PREFIX = '/app/datasources'; +export const DATASOURCES_PATH = { + DATASOURCES_CREATION_BASE: `${DATASOURCES_API_PREFIX}#/new`, + DATASOURCES_CONFIG_BASE: `${DATASOURCES_API_PREFIX}#/configure`, +}; + // trace analytics export const TRACE_ID = '8832ed6abbb2a83516461960c89af49d'; export const SPAN_ID = 'a673bc074b438374';