Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure data cleanup in Cypress #21921

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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