This is an automated email from the ASF dual-hosted git repository. diegopucci pushed a commit to branch chore/e2e-cross-references in repository https://gitbox.apache.org/repos/asf/superset.git
commit f67ea62fbd6a014bbf825a896fa608af335b1389 Author: geido <[email protected]> AuthorDate: Thu Oct 13 19:25:23 2022 +0300 Test dashboards --- .../cypress-base/cypress/fixtures/dashboards.json | 28 +++++++ .../cypress/integration/explore/chart.test.js | 96 +++++++++++++--------- .../cypress/integration/explore/utils.ts | 12 +++ 3 files changed, 96 insertions(+), 40 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/fixtures/dashboards.json b/superset-frontend/cypress-base/cypress/fixtures/dashboards.json index 083d7647b9..e4bd57971a 100644 --- a/superset-frontend/cypress-base/cypress/fixtures/dashboards.json +++ b/superset-frontend/cypress-base/cypress/fixtures/dashboards.json @@ -14,5 +14,33 @@ { "dashboard_title": "4 - Sample dashboard", "slug": "4-sample-dashboard" + }, + { + "dashboard_title": "5 - Sample dashboard", + "slug": "5-sample-dashboard" + }, + { + "dashboard_title": "6 - Sample dashboard", + "slug": "6-sample-dashboard" + }, + { + "dashboard_title": "7 - Sample dashboard", + "slug": "7-sample-dashboard" + }, + { + "dashboard_title": "8 - Sample dashboard", + "slug": "8-sample-dashboard" + }, + { + "dashboard_title": "9 - Sample dashboard", + "slug": "9-sample-dashboard" + }, + { + "dashboard_title": "10 - Sample dashboard", + "slug": "10-sample-dashboard" + }, + { + "dashboard_title": "11 - Sample dashboard", + "slug": "11-sample-dashboard" } ] diff --git a/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js b/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js index dc185b790d..3661d9070d 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js +++ b/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js @@ -19,40 +19,62 @@ import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper'; import { CHART_LIST } from 'cypress/utils/urls'; import {interceptFiltering} from './utils'; +import { saveChartToDashboard } from './utils'; +import { interceptGet as interceptDashboardGet } from 'cypress/integration/dashboard/utils'; + +// SEARCH_THRESHOLD is 10. We need to add at least 11 dashboards to show search +const SAMPLE_DASHBOARDS_INDEXES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; function visitSampleChart(id) { cy.getBySel('table-row').first().contains(`${id} - Sample chart`).click(); cy.intercept('POST', '/superset/explore_json/**').as('getJson'); } -function selectDashboard(dashboardName) { - cy.get( - '[data-test="save-chart-modal-select-dashboard-form"] [aria-label="Select a dashboard"]', - ) - .first() - .click(); - cy.get(`.ant-select-item-option[title="${dashboardName}"]`).click(); +function openDashboardsAddedTo() { + cy.getBySel("actions-trigger").click(); + cy.get(".ant-dropdown-menu-submenu-title").contains("Dashboards added to").trigger("mouseover"); } -function saveToDashboard(dashboardName) { - cy.getBySel("query-save-button").click(); - selectDashboard(dashboardName); - cy.getBySel("btn-modal-save").click(); +function closeDashboardsAddedTo() { + cy.get(".ant-dropdown-menu-submenu-title").contains("Dashboards added to").trigger("mouseout"); + cy.getBySel("actions-trigger").click(); } -function openDashboardsAddedTo() { - cy.getBySel("actions-trigger").click(); - cy.get(".ant-dropdown-menu-submenu-title").first().trigger("mouseover"); +function verifyDashboardsSubmenuItem(dashboardName) { + cy.get(".ant-dropdown-menu-submenu-popup").contains(dashboardName); + closeDashboardsAddedTo(); +} + +function verifyDashboardSearch() { + openDashboardsAddedTo(); + cy.get(".ant-dropdown-menu-submenu-popup").trigger("mouseover"); + cy.get(".ant-dropdown-menu-submenu-popup").find('input[placeholder="Search"]').type("1"); + cy.get(".ant-dropdown-menu-submenu-popup").contains("1 - Sample dashboard"); + cy.get(".ant-dropdown-menu-submenu-popup").find('input[placeholder="Search"]').type("Blahblah"); + cy.get(".ant-dropdown-menu-submenu-popup").contains("No results found"); + cy.get(".ant-dropdown-menu-submenu-popup").find('[aria-label="close-circle"]').click(); + closeDashboardsAddedTo(); } -function verifySubmenuItem(itemName) { - cy.get(".ant-dropdown-menu-submenu-popup").contains(itemName).trigger("mouseout"); +function verifyDashboardLink() { + interceptDashboardGet(); + openDashboardsAddedTo(); + cy.get(".ant-dropdown-menu-submenu-popup").trigger("mouseover"); + cy.get('.ant-dropdown-menu-submenu-popup a').first().invoke('removeAttr', 'target').click(); + cy.wait("@get"); } function verifyMetabar(text) { cy.getBySel("metadata-bar").contains(text); } +function saveAndVerifyDashboard(number) { + saveChartToDashboard(`${number} - Sample dashboard`); + verifyMetabar(`Added to ${number} dashboard(s)`); + openDashboardsAddedTo(); + verifyDashboardsSubmenuItem(`${number} - Sample dashboard`); +} + describe('Cross-referenced dashboards', () => { beforeEach(() => { interceptFiltering(); @@ -63,8 +85,8 @@ describe('Cross-referenced dashboards', () => { }); before(() => { - cy.createSampleDashboards(); - cy.createSampleCharts(); + cy.createSampleDashboards(SAMPLE_DASHBOARDS_INDEXES); + cy.createSampleCharts([3]); }); it('Shows the cross referenced dashboards', () => { @@ -72,28 +94,22 @@ describe('Cross-referenced dashboards', () => { cy.getBySel("metadata-bar").contains("Not added to any dashboard"); openDashboardsAddedTo(); - verifySubmenuItem("None"); - - saveToDashboard("1 - Sample dashboard"); - verifyMetabar("Added to 1 dashboard(s)"); - openDashboardsAddedTo(); - verifySubmenuItem("1 - Sample dashboard"); - - saveToDashboard("2 - Sample dashboard"); - verifyMetabar("Added to 2 dashboard(s)"); - openDashboardsAddedTo(); - verifySubmenuItem("2 - Sample dashboard"); - - saveToDashboard("3 - Sample dashboard"); - verifyMetabar("Added to 3 dashboard(s)"); - openDashboardsAddedTo(); - verifySubmenuItem("3 - Sample dashboard"); - - saveToDashboard("4 - Sample dashboard"); - verifyMetabar("Added to 4 dashboard(s)"); - openDashboardsAddedTo(); - verifySubmenuItem("4 - Sample dashboard"); - + verifyDashboardsSubmenuItem("None"); + + saveAndVerifyDashboard("1"); + saveAndVerifyDashboard("2"); + saveAndVerifyDashboard("3"); + saveAndVerifyDashboard("4"); + saveAndVerifyDashboard("5"); + saveAndVerifyDashboard("6"); + saveAndVerifyDashboard("7"); + saveAndVerifyDashboard("8"); + saveAndVerifyDashboard("9"); + saveAndVerifyDashboard("10"); + saveAndVerifyDashboard("11"); + + verifyDashboardSearch(); + verifyDashboardLink(); }); }); diff --git a/superset-frontend/cypress-base/cypress/integration/explore/utils.ts b/superset-frontend/cypress-base/cypress/integration/explore/utils.ts index 0972bac552..8598a56734 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/utils.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/utils.ts @@ -45,3 +45,15 @@ export function setFilter(filter: string, option: string) { cy.wait('@filtering'); } + +export function saveChartToDashboard(dashboardName: string) { + cy.getBySel("query-save-button").click(); + cy.get( + '[data-test="save-chart-modal-select-dashboard-form"] [aria-label="Select a dashboard"]', + ) + .first() + .click(); + cy.get('.ant-select-selection-search-input[aria-label="Select a dashboard"]').type(dashboardName); + cy.get(`.ant-select-item-option[title="${dashboardName}"]`).click(); + cy.getBySel("btn-modal-save").click(); +} \ No newline at end of file
