From a36ab71a2793bd9dc51f3234b502ab43b0d304a0 Mon Sep 17 00:00:00 2001 From: Geido <60598000+geido@users.noreply.github.com> Date: Mon, 24 Oct 2022 18:25:36 +0300 Subject: [PATCH] fix: Ensure data cleanup in Cypress (#21921) --- .../integration/chart_list/list.test.ts | 5 +---- .../integration/dashboard/editmode.test.ts | 13 ++++++------- .../dashboard/nativeFilters.test.ts | 15 ++++++++------- .../cypress/integration/explore/chart.test.js | 7 ++----- .../cypress-base/cypress/support/index.ts | 19 ++++++++++++------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts b/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts index 9891b09be778..faaf00ddf51e 100644 --- a/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts @@ -60,12 +60,9 @@ describe('Charts list', () => { describe('Cross-referenced dashboards', () => { beforeEach(() => { - visitChartList(); - }); - - before(() => { cy.createSampleDashboards([0, 1, 2, 3]); cy.createSampleCharts([0]); + visitChartList(); }); it('should show the cross-referenced dashboards in the table cell', () => { diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts index 6ed1ec4ee09a..9f05f2fc290b 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts @@ -75,6 +75,10 @@ function visitEdit(sampleDashboard = SAMPLE_DASHBOARD_1) { interceptCharts(); interceptGet(); + if (sampleDashboard === SAMPLE_DASHBOARD_1) { + cy.createSampleDashboards([0]); + } + cy.visit(sampleDashboard); cy.wait('@get'); editDashboard(); @@ -648,11 +652,11 @@ describe('Dashboard edit', () => { describe('Edit properties', () => { before(() => { - cy.createSampleDashboards([0]); visitEdit(); }); beforeEach(() => { + cy.createSampleDashboards([0]); openProperties(); }); @@ -700,11 +704,11 @@ describe('Dashboard edit', () => { describe('Edit mode', () => { before(() => { - cy.createSampleDashboards([0]); visitEdit(); }); beforeEach(() => { + cy.createSampleDashboards([0]); discardChanges(); }); @@ -736,10 +740,6 @@ describe('Dashboard edit', () => { }); describe('Components', () => { - before(() => { - cy.createSampleDashboards([0]); - }); - beforeEach(() => { visitEdit(); }); @@ -787,7 +787,6 @@ describe('Dashboard edit', () => { describe('Save', () => { beforeEach(() => { - cy.createSampleDashboards(); visitEdit(); }); diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts index 3f643cc32ec1..3a869000356d 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts @@ -55,11 +55,15 @@ import { const SAMPLE_CHART = { name: 'Most Populated Countries', viz: 'table' }; -function visitDashboard() { +function visitDashboard(createSample = true) { interceptCharts(); interceptGet(); interceptDatasets(); + if (createSample) { + cy.createSampleDashboards([0]); + } + cy.visit(SAMPLE_DASHBOARD_1); cy.wait('@get'); cy.wait('@getCharts'); @@ -70,6 +74,7 @@ function visitDashboard() { function prepareDashboardFilters( filters: { name: string; column: string; datasetId: number }[], ) { + cy.createSampleDashboards([0]); cy.request({ method: 'GET', url: `api/v1/dashboard/1-sample-dashboard`, @@ -169,7 +174,7 @@ function prepareDashboardFilters( json_metadata: JSON.stringify(jsonMetadata), }, }) - .then(() => visitDashboard()); + .then(() => visitDashboard(false)); } return cy; }); @@ -379,11 +384,11 @@ describe('Native filters', () => { describe('Nativefilters basic interactions', () => { before(() => { - cy.createSampleDashboards([0]); visitDashboard(); }); beforeEach(() => { + cy.createSampleDashboards([0]); closeFilterModal(); }); @@ -436,10 +441,6 @@ describe('Native filters', () => { }); describe('Nativefilters initial state not required', () => { - beforeEach(() => { - cy.createSampleDashboards([0]); - }); - it("User can check 'Filter has default value'", () => { prepareDashboardFilters([ { name: 'country_name', column: 'country_name', datasetId: 2 }, 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 0dfc9bd46ba5..c89b1b22e0c6 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js +++ b/superset-frontend/cypress-base/cypress/integration/explore/chart.test.js @@ -91,13 +91,10 @@ describe('Cross-referenced dashboards', () => { interceptFiltering(); cy.preserveLogin(); - cy.visit(CHART_LIST); - cy.wait('@filtering'); - }); - - before(() => { cy.createSampleDashboards(SAMPLE_DASHBOARDS_INDEXES); cy.createSampleCharts([0]); + cy.visit(CHART_LIST); + cy.wait('@filtering'); }); it('should show the cross-referenced dashboards', () => { diff --git a/superset-frontend/cypress-base/cypress/support/index.ts b/superset-frontend/cypress-base/cypress/support/index.ts index aa2b168e2d02..9d9b764e5639 100644 --- a/superset-frontend/cypress-base/cypress/support/index.ts +++ b/superset-frontend/cypress-base/cypress/support/index.ts @@ -42,11 +42,15 @@ before(() => { cy.login(); cy.loadChartFixtures(); cy.loadDashboardFixtures(); +}); + +beforeEach(() => { cy.cleanDashboards(); cy.cleanCharts(); }); -Cypress.Commands.add('cleanDashboards', () => +Cypress.Commands.add('cleanDashboards', () => { + cy.login(); cy.getDashboards().then((sampleDashboards?: Record[]) => { const deletableDashboards = []; for (let i = 0; i < DASHBOARD_FIXTURES.length; i += 1) { @@ -74,10 +78,11 @@ Cypress.Commands.add('cleanDashboards', () => }, }).then(resp => resp); } - }), -); + }); +}); -Cypress.Commands.add('cleanCharts', () => +Cypress.Commands.add('cleanCharts', () => { + cy.login(); cy.getCharts().then((sampleCharts?: Record[]) => { const deletableCharts = []; for (let i = 0; i < CHART_FIXTURES.length; i += 1) { @@ -89,7 +94,7 @@ Cypress.Commands.add('cleanCharts', () => deletableCharts.push(isInDb.id); } } - if (deletableCharts) { + if (deletableCharts.length) { cy.request({ failOnStatusCode: false, method: 'DELETE', @@ -105,8 +110,8 @@ Cypress.Commands.add('cleanCharts', () => }, }).then(resp => resp); } - }), -); + }); +}); Cypress.Commands.add('getBySel', (selector, ...args) => cy.get(`[data-test=${selector}]`, ...args),