From d17ec6939165930a93d7bee4167e46c312719b59 Mon Sep 17 00:00:00 2001 From: Jialiang Liang <109499885+RyanL1997@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:45:38 -0800 Subject: [PATCH] [Enhancement/Fix] Refactor datasources cypress tests (#1323) * Fix the datasources cypress tests Signed-off-by: Ryan Liang * Clean up test setup and setup constants Signed-off-by: Ryan Liang * Refactor datasources test and disable security config Signed-off-by: Ryan Liang * Fix some lint Signed-off-by: Ryan Liang * Switch to capitalized naming Signed-off-by: Ryan Liang * Fix lint Signed-off-by: Ryan Liang * debugging Signed-off-by: Ryan Liang * List out all the changed files Signed-off-by: Ryan Liang * Add output for file changes Signed-off-by: Ryan Liang * Switch to use env var Signed-off-by: Ryan Liang * Add echo Signed-off-by: Ryan Liang * Remove github env setup Signed-off-by: Ryan Liang * Add msg to check which file is being linted Signed-off-by: Ryan Liang * Use jq for parsing Signed-off-by: Ryan Liang * Lint both modified and added Signed-off-by: Ryan Liang --------- Signed-off-by: Ryan Liang --- .../datasources_test/datasources.spec.js | 42 ------------ .../datasources_basic_ui.spec.js | 67 +++++++++++++++++++ .cypress/utils/constants.js | 11 +++ .../workflows/integration-tests-workflow.yml | 9 +++ .github/workflows/lint.yml | 33 +++++---- cypress.config.js | 4 +- 6 files changed, 108 insertions(+), 58 deletions(-) delete mode 100644 .cypress/integration/datasources_test/datasources.spec.js create mode 100644 .cypress/integration/datasources_test/datasources_basic_ui.spec.js diff --git a/.cypress/integration/datasources_test/datasources.spec.js b/.cypress/integration/datasources_test/datasources.spec.js deleted file mode 100644 index fdfe21b28..000000000 --- a/.cypress/integration/datasources_test/datasources.spec.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -/// - - - const moveToDatasourcesHome = () => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/datasources`); - }; - - const moveToNewDatasourcesPage = () => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/datasources#/new`); - }; - - const moveToCreatePrometheusDatasourcePage = () => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/datasources#/configure/PROMETHEUS`); - }; - - describe('Integration tests for datasources plugin', () => { - const testPrometheusSuffix = (Math.random() + 1).toString(36).substring(7); -const testPrometheusInstance = `Prometheus_${testPrometheusSuffix}`; -const testS3Suffix = (Math.random() + 1).toString(36).substring(7); -const testS3Instance = `S3_${testS3Suffix}`; - it('Navigates to datasources plugin and expects the correct header', () => { - moveToDatasourcesHome(); - cy.get('[data-test-subj="dataconnections-header"]').should('exist'); - }); - - it('Tests navigation between tabs and goes to Prometheus creation flow', () => { - moveToDatasourcesHome(); - cy.get('[data-test-subj="new"]').click(); - cy.url().should('include', '/new') - cy.get('[data-test-subj="datasource_card_prometheus"]').click(); - cy.url().should('include', '/configure/PROMETHEUS'); - }); - -}); - - - diff --git a/.cypress/integration/datasources_test/datasources_basic_ui.spec.js b/.cypress/integration/datasources_test/datasources_basic_ui.spec.js new file mode 100644 index 000000000..4f9259ef5 --- /dev/null +++ b/.cypress/integration/datasources_test/datasources_basic_ui.spec.js @@ -0,0 +1,67 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { FONTEND_BASE_PATH, DATASOURCES_API_PREFIX, DATASOURCES_PATH } from '../../utils/constants'; + +const MANAGE_DATASOURCES_TAG = 'button[data-test-subj="manage"]'; +const NEW_DATASOURCES_TAG = 'button[data-test-subj="new"]'; +const CREATE_S3_BUTTON = '[data-test-subj="datasource_card_s3glue"]'; +const CREATE_PROMETHEUS_BUTTON = '[data-test-subj="datasource_card_prometheus"]'; + +const visitDatasourcesHomePage = () => { + cy.visit(FONTEND_BASE_PATH + DATASOURCES_API_PREFIX); +}; + +const visitDatasourcesCreationPage = () => { + cy.visit(FONTEND_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"]').should('exist'); + }); + + it('Tests navigation between tabs', () => { + visitDatasourcesHomePage(); + + cy.get(MANAGE_DATASOURCES_TAG) + .should('have.class', 'euiTab-isSelected') + .and('have.attr', 'aria-selected', 'true'); + cy.get(MANAGE_DATASOURCES_TAG).click(); + cy.url().should('include', '/manage'); + + cy.get(NEW_DATASOURCES_TAG).click(); + cy.get(NEW_DATASOURCES_TAG) + .should('have.class', 'euiTab-isSelected') + .and('have.attr', 'aria-selected', 'true'); + cy.url().should('include', '/new'); + + cy.get(CREATE_S3_BUTTON).should('be.visible'); + cy.get(CREATE_PROMETHEUS_BUTTON).should('be.visible'); + }); + + it('Tests navigation of S3 datasources creation page with hash', () => { + visitDatasourcesCreationPage(); + + cy.get(CREATE_S3_BUTTON).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(CREATE_PROMETHEUS_BUTTON).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/constants.js b/.cypress/utils/constants.js index af655fbe3..706061baf 100644 --- a/.cypress/utils/constants.js +++ b/.cypress/utils/constants.js @@ -6,6 +6,17 @@ export const delay = 1500; export const COMMAND_TIMEOUT_LONG = 10000; +//BASE Constants +export const BACKEND_BASE_PATH = Cypress.env('opensearch'); +export const FONTEND_BASE_PATH = Cypress.env('opensearchDashboards'); + +//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'; diff --git a/.github/workflows/integration-tests-workflow.yml b/.github/workflows/integration-tests-workflow.yml index 2ee8a85ec..d1179a6e2 100644 --- a/.github/workflows/integration-tests-workflow.yml +++ b/.github/workflows/integration-tests-workflow.yml @@ -109,6 +109,15 @@ jobs: node-version: ${{ steps.versions_step.outputs.node_version }} registry-url: 'https://registry.npmjs.org' + - name: Configure OpenSearch Dashboards + run: | + rm -rf ./config/opensearch_dashboards.yml + cat << 'EOT' > ./config/opensearch_dashboards.yml + server.host: "0.0.0.0" + home.disableWelcomeScreen: true + EOT + working-directory: OpenSearch-Dashboards + - name: Install correct yarn version for OpenSearch Dashboards run: | npm uninstall -g yarn diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f26802c59..22d20d68d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -48,25 +48,32 @@ jobs: working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} run: yarn osd bootstrap - - name: Get list of changed files - id: files + - name: Get list of changed files using GitHub Action + uses: lots0logs/gh-action-get-changed-files@2.2.2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Check Changes of Files run: | - BASE_SHA="${{ github.event.pull_request.base.sha }}" - HEAD_SHA="${{ github.event.pull_request.head.sha }}" - git fetch origin $BASE_SHA - git diff --name-only $BASE_SHA...$HEAD_SHA > changed_files.txt - CHANGED_FILES=$(cat changed_files.txt | grep -E '\.(js|ts|tsx)$' || true) - echo "::set-output name=changed::${CHANGED_FILES}" - working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + echo "FILES_MODIFIED=$(cat ${HOME}/files_modified.json)" + echo "FILES_ADDED=$(cat ${HOME}/files_added.json)" + echo "FILES_RENAMED=$(cat ${HOME}/files_renamed.json)" + echo "FILES_DELETED=$(cat ${HOME}/files_deleted.json)" - name: Lint Changed Files run: | - CHANGED_FILES="${{ steps.files.outputs.changed }}" + jq -r '.[]' ${HOME}/files_modified.json ${HOME}/files_added.json | sort | uniq > /tmp/changed_files.txt + CHANGED_FILES=$(cat /tmp/changed_files.txt) + echo "These are the changed files: $CHANGED_FILES" if [[ -n "$CHANGED_FILES" ]]; then echo "Linting changed files..." - IFS=$'\n' read -r -a FILES_TO_LINT <<< "$CHANGED_FILES" - yarn lint "${FILES_TO_LINT[@]}" + while IFS= read -r file; do + if [[ $file == *.js || $file == *.ts || $file == *.tsx ]]; then + echo "linting file $file" + yarn lint "$file" + fi + done < /tmp/changed_files.txt else echo "No matched files to lint." fi - working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} + working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }} diff --git a/cypress.config.js b/cypress.config.js index dff98e5eb..84ad08946 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -18,14 +18,12 @@ module.exports = defineConfig({ env: { opensearch: 'localhost:9200', opensearchDashboards: 'localhost:5601', - security_enabled: true, + security_enabled: false, }, 'cypress-watch-and-reload': { watch: ['common/**', 'public/**', 'server/**'], }, e2e: { - // We've imported your old cypress plugins here. - // You may want to clean this up later by importing these. setupNodeEvents(on, config) { return require('./.cypress/plugins/index.js')(on, config); },