Skip to content

Commit

Permalink
fix: Ensure data cleanup in Cypress (#21921)
Browse files Browse the repository at this point in the history
  • Loading branch information
geido committed Oct 24, 2022
1 parent f5977ca commit a36ab71
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -648,11 +652,11 @@ describe('Dashboard edit', () => {

describe('Edit properties', () => {
before(() => {
cy.createSampleDashboards([0]);
visitEdit();
});

beforeEach(() => {
cy.createSampleDashboards([0]);
openProperties();
});

Expand Down Expand Up @@ -700,11 +704,11 @@ describe('Dashboard edit', () => {

describe('Edit mode', () => {
before(() => {
cy.createSampleDashboards([0]);
visitEdit();
});

beforeEach(() => {
cy.createSampleDashboards([0]);
discardChanges();
});

Expand Down Expand Up @@ -736,10 +740,6 @@ describe('Dashboard edit', () => {
});

describe('Components', () => {
before(() => {
cy.createSampleDashboards([0]);
});

beforeEach(() => {
visitEdit();
});
Expand Down Expand Up @@ -787,7 +787,6 @@ describe('Dashboard edit', () => {

describe('Save', () => {
beforeEach(() => {
cy.createSampleDashboards();
visitEdit();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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`,
Expand Down Expand Up @@ -169,7 +174,7 @@ function prepareDashboardFilters(
json_metadata: JSON.stringify(jsonMetadata),
},
})
.then(() => visitDashboard());
.then(() => visitDashboard(false));
}
return cy;
});
Expand Down Expand Up @@ -379,11 +384,11 @@ describe('Native filters', () => {

describe('Nativefilters basic interactions', () => {
before(() => {
cy.createSampleDashboards([0]);
visitDashboard();
});

beforeEach(() => {
cy.createSampleDashboards([0]);
closeFilterModal();
});

Expand Down Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
19 changes: 12 additions & 7 deletions superset-frontend/cypress-base/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>[]) => {
const deletableDashboards = [];
for (let i = 0; i < DASHBOARD_FIXTURES.length; i += 1) {
Expand Down Expand Up @@ -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<string, any>[]) => {
const deletableCharts = [];
for (let i = 0; i < CHART_FIXTURES.length; i += 1) {
Expand All @@ -89,7 +94,7 @@ Cypress.Commands.add('cleanCharts', () =>
deletableCharts.push(isInDb.id);
}
}
if (deletableCharts) {
if (deletableCharts.length) {
cy.request({
failOnStatusCode: false,
method: 'DELETE',
Expand All @@ -105,8 +110,8 @@ Cypress.Commands.add('cleanCharts', () =>
},
}).then(resp => resp);
}
}),
);
});
});

Cypress.Commands.add('getBySel', (selector, ...args) =>
cy.get(`[data-test=${selector}]`, ...args),
Expand Down

0 comments on commit a36ab71

Please sign in to comment.