From 212d4102bb839285a29855e5227428ca2a5c8864 Mon Sep 17 00:00:00 2001 From: Miki Date: Fri, 12 Jan 2024 13:05:12 -0800 Subject: [PATCH] Add tests for the new homepage Signed-off-by: Miki --- .../common/dashboard_sample_data_spec.js | 74 ++++++++++++++++++- .../apps/home/section.spec.js | 49 ++++++++++++ ...hboard_sample_data_with_datasource_spec.js | 25 +++++++ 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/home/section.spec.js diff --git a/cypress/integration/common/dashboard_sample_data_spec.js b/cypress/integration/common/dashboard_sample_data_spec.js index 7d7afa310..666afa553 100644 --- a/cypress/integration/common/dashboard_sample_data_spec.js +++ b/cypress/integration/common/dashboard_sample_data_spec.js @@ -42,8 +42,80 @@ export function dashboardSanityTests() { ); }); + it('checking sections display', () => { + // Check that we have two homepageSection + commonUI.checkElementExists(`[data-test-subj="homepageSection"]`, 2); + }); + + it('checking tutorial_directory display', () => { + // Check that tutorial_directory is visable + commonUI.checkElementExists( + `a[href="${path}/app/home#/tutorial_directory"]`, + 2 + ); + }); + + it('checking management display', () => { + // Check that management is visable + commonUI.checkElementExists(`a[href="${path}/app/management"]`, 1); + }); + + it('checking dev_tools display', () => { + // Check that dev_tools is visable + commonUI.checkElementExists( + `a[href="${path}/app/dev_tools#/console"]`, + 1 + ); + }); + + it('settings display', () => { + // Check that settings is visable + commonUI.checkElementExists( + `a[href="${path}/app/management/opensearch-dashboards/settings#defaultRoute"]`, + 1 + ); + }); + + it('checking feature_directory display', () => { + // Check that feature_directory is visable + commonUI.checkElementExists( + `a[href="${path}/app/home#/feature_directory"]`, + 1 + ); + }); + + it('checking navigation display', () => { + // Check that navigation is visable + commonUI.checkElementExists( + 'button[data-test-subj="toggleNavButton"]', + 1 + ); + }); + + it('checking Help menu display', () => { + // Check that Help menu is visable + commonUI.checkElementExists('button[aria-label="Help menu"]', 1); + }); + }); + + describe('checking legacy home page', () => { + before(() => { + // Go to the home page + miscUtils.visitPage('app/home#/legacy'); + cy.window().then((win) => + win.localStorage.setItem('home:welcome:show', false) + ); + cy.reload(true); + }); + + after(() => { + cy.window().then((win) => + win.localStorage.removeItem('home:welcome:show') + ); + }); + it('checking opensearch_dashboards_overview display', () => { - // Check that opensearch_dashboards_overview is visable + // Check that opensearch_dashboards_overview is visible commonUI.checkElementExists( `a[href="${path}/app/opensearch_dashboards_overview"]`, 1 diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/home/section.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/home/section.spec.js new file mode 100644 index 000000000..093da7d4c --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/home/section.spec.js @@ -0,0 +1,49 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); + +describe('home sections', { scrollBehavior: false }, () => { + before(() => { + // Go to the home page + miscUtils.visitPage('app/home#'); + }); + + it('should all appear expanded', function () { + cy.getElementsByTestIds('homepageSection').each((element) => { + const $content = element.find( + '[data-test-subj="homepageSectionContent"]' + ); + expect($content).to.have.length(1); + }); + }); + + it('should toggle correctly', function () { + cy.getElementsByTestIds('homepageSection').each((element) => { + const $button = element.find('button').first(); + + const $preClick1 = element.find( + '[data-test-subj="homepageSectionContent"]' + ); + expect($preClick1).to.have.length(1); + + $button.trigger('click'); + + const $postClick1 = element.find( + '[data-test-subj="homepageSectionContent"]' + ); + expect($postClick1).to.have.length(0); + + $button.trigger('click'); + + const $postClick2 = element.find( + '[data-test-subj="homepageSectionContent"]' + ); + expect($postClick2).to.have.length(1); + }); + }); +}); diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/dashboard_sample_data_with_datasource_spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/dashboard_sample_data_with_datasource_spec.js index 0056a537e..8e4ac9d4f 100644 --- a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/dashboard_sample_data_with_datasource_spec.js +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/dashboard_sample_data_with_datasource_spec.js @@ -45,6 +45,31 @@ if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { }); }); + describe('checking legacy home page', () => { + before(() => { + // Go to the home page + miscUtils.visitPage('app/home#/legacy'); + cy.window().then((win) => + win.localStorage.setItem('home:welcome:show', false) + ); + cy.reload(true); + }); + + after(() => { + cy.window().then((win) => + win.localStorage.removeItem('home:welcome:show') + ); + }); + + it('checking tutorial_directory display', () => { + // Check that tutorial_directory is visible + commonUI.checkElementExists( + `a[href="${path}/app/home#/tutorial_directory"]`, + 2 + ); + }); + }); + describe('adding sample data', () => { before(() => { miscUtils.addSampleData();