You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/08/31 14:01:31 UTC
[superset] 01/02: Seed/clean up dashboards
This is an automated email from the ASF dual-hosted git repository.
diegopucci pushed a commit to branch chore/cypress-runtime-enhancements
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 18641150c40dac1655fa99aff024a5cd8eafb50d
Author: geido <di...@gmail.com>
AuthorDate: Wed Aug 31 16:14:31 2022 +0300
Seed/clean up dashboards
---
.../cypress-base/cypress/fixtures/dashboards.json | 14 +++
.../dashboard_list/dashboard_list.helper.ts | 19 ----
.../dashboardlist.applitools.test.ts | 2 +-
.../integration/dashboard_list/list.test.ts | 116 ++++++++++++++-------
.../cypress-base/cypress/support/index.d.ts | 16 ++-
.../cypress-base/cypress/support/index.ts | 71 +++++++------
6 files changed, 149 insertions(+), 89 deletions(-)
diff --git a/superset-frontend/cypress-base/cypress/fixtures/dashboards.json b/superset-frontend/cypress-base/cypress/fixtures/dashboards.json
new file mode 100644
index 0000000000..6972cb0552
--- /dev/null
+++ b/superset-frontend/cypress-base/cypress/fixtures/dashboards.json
@@ -0,0 +1,14 @@
+[
+ {
+ "dashboard_title": "1 - Sample dashboard"
+ },
+ {
+ "dashboard_title": "2 - Sample dashboard"
+ },
+ {
+ "dashboard_title": "3 - Sample dashboard"
+ },
+ {
+ "dashboard_title": "4 - Sample dashboard"
+ }
+]
\ No newline at end of file
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboard_list.helper.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboard_list.helper.ts
deleted file mode 100644
index 5ccb39432c..0000000000
--- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboard_list.helper.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-export const DASHBOARD_LIST = '/dashboard/list/';
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboardlist.applitools.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboardlist.applitools.test.ts
index d85d9b11ae..c4c62e6c6c 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboardlist.applitools.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard_list/dashboardlist.applitools.test.ts
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { DASHBOARD_LIST } from './dashboard_list.helper';
+ import { DASHBOARD_LIST } from 'cypress/utils/urls';
describe('dashboard list view', () => {
beforeEach(() => {
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
index d8dc3285ec..8378370ba6 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
@@ -18,20 +18,6 @@
*/
import { DASHBOARD_LIST } from 'cypress/utils/urls';
-function refresh() {
- cy.loginGoTo(DASHBOARD_LIST);
-}
-
-function revertChanges() {
- cy.deleteDashboardByName('0 - Sample dashboard');
- cy.deleteDashboardByName('1 - Sample dashboard');
- cy.deleteDashboardByName('0 - Sample dashboard | EDITED');
-}
-
-function ensureAuth() {
- cy.login();
-}
-
function toggleBulkSelect() {
cy.getBySel("bulk-select").click();
}
@@ -45,15 +31,32 @@ function orderAlphabetical() {
cy.get('[title="Alphabetical"]').click();
}
+function openProperties() {
+ cy.get('[aria-label="more-vert"]').first().click();
+ cy.getBySel('dashboard-card-option-edit-button').click();
+}
+
+function openMenu() {
+ cy.get('[aria-label="more-vert"]').first().click();
+}
+
+function confirmDelete() {
+ cy.getBySel('delete-modal-input').type('DELETE');
+ cy.getBySel('modal-confirm-button').click();
+}
+
describe('Dashboards list', () => {
+ before(() => {
+ cy.login();
+ });
+
beforeEach(() => {
- ensureAuth();
- revertChanges();
+ cy.preserveLogin();
});
describe('list mode', () => {
before(() => {
- refresh()
+ cy.visit(DASHBOARD_LIST);
setGridMode('list');
});
@@ -96,7 +99,7 @@ describe('Dashboards list', () => {
describe('card mode', () => {
before(() => {
- refresh();
+ cy.visit(DASHBOARD_LIST);
setGridMode('card');
});
@@ -126,18 +129,18 @@ describe('Dashboards list', () => {
describe('common actions', () => {
beforeEach(() => {
- cy.createDashboard('0 - Sample dashboard');
- cy.createDashboard('1 - Sample dashboard');
- refresh();
- setGridMode('card');
- orderAlphabetical();
+ cy.createSampleDashboards();
+ cy.visit(DASHBOARD_LIST);
});
it('should allow to favorite/unfavorite dashboard', () => {
cy.intercept(`/superset/favstar/Dashboard/*/select/`).as('select');
cy.intercept(`/superset/favstar/Dashboard/*/unselect/`).as('unselect');
- cy.getBySel('styled-card').first().contains('0 - Sample dashboard')
+ setGridMode('card');
+ orderAlphabetical();
+
+ cy.getBySel('styled-card').first().contains('1 - Sample dashboard')
cy.getBySel('styled-card').first().find("[aria-label='favorite-unselected']")
.click();
cy.wait('@select');
@@ -153,32 +156,67 @@ describe('Dashboards list', () => {
it('should bulk delete correctly', () => {
toggleBulkSelect();
- cy.getBySel("styled-card").eq(0).contains('0 - Sample dashboard').click();
- cy.getBySel("styled-card").eq(1).contains('1 - Sample dashboard').click();
+ // bulk deletes in card-view
+ setGridMode('card');
+ orderAlphabetical();
+
+ cy.getBySel("styled-card").eq(0).contains('1 - Sample dashboard').click();
+ cy.getBySel("styled-card").eq(1).contains('2 - Sample dashboard').click();
cy.getBySel("bulk-select-action").eq(0).contains('Delete').click();
- cy.getBySel('delete-modal-input').type('DELETE');
- cy.getBySel('modal-confirm-button').click();
- cy.getBySel("styled-card").eq(0).should('not.contain', '0 - Sample dashboard');
- cy.getBySel("styled-card").eq(1).should('not.contain', '1 - Sample dashboard');
+ confirmDelete();
+ cy.getBySel("styled-card").eq(0).should('not.contain', '1 - Sample dashboard');
+ cy.getBySel("styled-card").eq(1).should('not.contain', '2 - Sample dashboard');
+ // bulk deletes in list-view
+ setGridMode('list');
+ cy.getBySel("table-row").eq(0).contains('3 - Sample dashboard');
+ cy.getBySel("table-row").eq(1).contains('4 - Sample dashboard');
+ cy.get('[data-test="table-row"] input[type="checkbox"]').eq(0).click();
+ cy.get('[data-test="table-row"] input[type="checkbox"]').eq(1).click();
+ cy.getBySel("bulk-select-action").eq(0).contains('Delete').click();
+ confirmDelete();
+ cy.getBySel("table-row").eq(0).should('not.contain', '3 - Sample dashboard');
+ cy.getBySel("table-row").eq(1).should('not.contain', '4 - Sample dashboard');
});
it('should delete correctly', () => {
- cy.getBySel("styled-card").eq(0).contains('0 - Sample dashboard');
- cy.get('[aria-label="more-vert"]').first().click();
+ // deletes in card-view
+ setGridMode('card');
+ orderAlphabetical();
+
+ cy.getBySel("styled-card").eq(0).contains('1 - Sample dashboard');
+ openMenu();
cy.getBySel('dashboard-card-option-delete-button').click();
- cy.getBySel('delete-modal-input').type('DELETE');
- cy.getBySel('modal-confirm-button').click();
- cy.getBySel("styled-card").eq(0).should('not.contain', '0 - Sample dashboard');
+ confirmDelete();
+ cy.getBySel("styled-card").eq(0).should('not.contain', '1 - Sample dashboard');
+
+ // deletes in list-view
+ setGridMode('list');
+ cy.getBySel("table-row").eq(0).contains('2 - Sample dashboard');
+ cy.getBySel("dashboard-list-trash-icon").eq(0).click();
+ confirmDelete();
+ cy.getBySel("table-row").eq(0).should('not.contain', '2 - Sample dashboard');
+
});
it('should edit correctly', () => {
- cy.getBySel("styled-card").eq(0).contains('0 - Sample dashboard');
- cy.get('[aria-label="more-vert"]').first().click();
- cy.getBySel('dashboard-card-option-edit-button').click();
+ // edits in card-view
+ setGridMode('card');
+ orderAlphabetical();
+ cy.getBySel("styled-card").eq(0).contains('1 - Sample dashboard');
+
+ // change title
+ openProperties();
cy.getBySel('dashboard-title-input').type(' | EDITED');
cy.get('button:contains("Save")').click();
- cy.getBySel("styled-card").eq(0).contains('0 - Sample dashboard | EDITED');
+ cy.getBySel("styled-card").eq(0).contains('1 - Sample dashboard | EDITED');
+
+ // edits in list-view
+ setGridMode('list');
+ cy.getBySel("edit-alt").eq(0).click();
+ cy.getBySel('dashboard-title-input').clear().type('1 - Sample dashboard');
+ cy.get('button:contains("Save")').click();
+ cy.getBySel("table-row").eq(0).contains('1 - Sample dashboard');
});
});
});
diff --git a/superset-frontend/cypress-base/cypress/support/index.d.ts b/superset-frontend/cypress-base/cypress/support/index.d.ts
index eca68a7ced..edb9a9c18b 100644
--- a/superset-frontend/cypress-base/cypress/support/index.d.ts
+++ b/superset-frontend/cypress-base/cypress/support/index.d.ts
@@ -29,6 +29,15 @@ declare namespace Cypress {
* Login test user.
*/
login(): void;
+ preserveLogin(): void;
+
+ /**
+ *
+ * Utils
+ */
+
+ getBySel(selector: string): cy;
+ getBySelLike(selector: string): cy;
visitChartByParams(params: string | Record<string, unknown>): cy;
visitChartByName(name: string): cy;
@@ -54,11 +63,16 @@ declare namespace Cypress {
getDashboards(): cy;
getCharts(): cy;
+ /**
+ * Create
+ */
+ createSampleDashboards(): void;
+
/**
* Delete
*/
deleteDashboard(id: number): cy;
- deleteDashboardByName(name: string): cy;
+ deleteDashboardByName(dashboardName: string): cy;
deleteChartByName(name: string): cy;
deleteChart(id: number): cy;
}
diff --git a/superset-frontend/cypress-base/cypress/support/index.ts b/superset-frontend/cypress-base/cypress/support/index.ts
index 782490b250..90442649a2 100644
--- a/superset-frontend/cypress-base/cypress/support/index.ts
+++ b/superset-frontend/cypress-base/cypress/support/index.ts
@@ -19,10 +19,22 @@
import '@cypress/code-coverage/support';
import '@applitools/eyes-cypress/commands';
+require('cy-verify-downloads').addCustomCommand();
+
const BASE_EXPLORE_URL = '/explore/?form_data=';
const TokenName = Cypress.env('TOKEN_NAME');
-require('cy-verify-downloads').addCustomCommand();
+function resetSamples() {
+ cy.fixture('dashboards.json').then((dashboards) => {
+ dashboards.forEach((d: { dashboard_title: string }) => {
+ cy.deleteDashboardByName(d.dashboard_title);
+ });
+ });
+}
+
+beforeEach(() => {
+ resetSamples();
+});
Cypress.Commands.add('getBySel', (selector, ...args) => {
return cy.get(`[data-test=${selector}]`, ...args)
@@ -53,9 +65,8 @@ Cypress.Commands.add('login', () => {
});
});
-Cypress.Commands.add('loginGoTo', url => {
- cy.login();
- cy.visit(url);
+Cypress.Commands.add('preserveLogin', () => {
+ Cypress.Cookies.preserveOnce('session');
});
Cypress.Commands.add('visitChartByName', name => {
@@ -154,35 +165,37 @@ Cypress.Commands.add(
},
);
-Cypress.Commands.add('createDashboard', (dashboardName: string) =>
- cy
- .request({
- method: 'POST',
- url: `/api/v1/dashboard/`,
- body: {
- dashboard_title: dashboardName,
- },
- headers: {
- Cookie: `csrf_access_token=${window.localStorage.getItem(
- 'access_token',
- )}`,
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${TokenName}`,
- 'X-CSRFToken': `${window.localStorage.getItem('access_token')}`,
- Referer: `${Cypress.config().baseUrl}/`,
- },
+Cypress.Commands.add('createSampleDashboards', () =>
+ cy.fixture('dashboards.json').then((dashboards) => {
+ dashboards.forEach((d: { dashboard_title: string }) => {
+ cy
+ .request({
+ method: 'POST',
+ url: `/api/v1/dashboard/`,
+ body: {
+ dashboard_title: d.dashboard_title,
+ },
+ headers: {
+ Cookie: `csrf_access_token=${window.localStorage.getItem(
+ 'access_token',
+ )}`,
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${TokenName}`,
+ 'X-CSRFToken': `${window.localStorage.getItem('access_token')}`,
+ Referer: `${Cypress.config().baseUrl}/`,
+ },
+ })
+ .then(resp => resp);
+ });
})
- .then(resp => resp),
);
-Cypress.Commands.add('deleteDashboardByName', (name: string) =>
+Cypress.Commands.add('deleteDashboardByName', (dashboardName: string) =>
cy.getDashboards().then((dashboards: any) => {
- dashboards?.forEach((element: any) => {
- if (element.dashboard_title === name) {
- const elementId = element.id;
- cy.deleteDashboard(elementId);
- }
- });
+ const dashboard = dashboards.find(d => d.dashboard_title === dashboardName);
+ if (dashboard) {
+ cy.deleteDashboard(dashboard.id);
+ }
}),
);