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 3ea671e4c343e7741cd63df7465a052bec4fa6a3 Author: geido <[email protected]> AuthorDate: Fri Sep 2 19:10:35 2022 +0300 Improve cleanup samples data --- .../cypress/integration/chart_list/filter.test.ts | 1 - .../cypress/integration/chart_list/list.test.ts | 4 - .../cypress/integration/dashboard/editsave.test.ts | 28 +++--- .../cypress/integration/dashboard/utils.ts | 4 + .../integration/dashboard_list/filter.test.ts | 1 - .../integration/dashboard_list/list.test.ts | 4 - .../cypress-base/cypress/support/index.d.ts | 6 +- .../cypress-base/cypress/support/index.ts | 100 ++++++++++++++++----- 8 files changed, 101 insertions(+), 47 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts b/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts index c5308a87f9..0418afd3ff 100644 --- a/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/chart_list/filter.test.ts @@ -22,7 +22,6 @@ describe('Charts filters', () => { before(() => { - cy.login(); cy.visit(CHART_LIST); }); 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 966725e921..e3837445d9 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 @@ -44,10 +44,6 @@ function confirmDelete() { } describe('Charts list', () => { - before(() => { - cy.login(); - }); - beforeEach(() => { cy.preserveLogin(); }); diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/editsave.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/editsave.test.ts index f456d9473a..1fd94413c6 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard/editsave.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard/editsave.test.ts @@ -19,6 +19,7 @@ import { SAMPLE_DASHBOARD_1 } from 'cypress/utils/urls'; import { drag } from 'cypress/utils'; import { + interceptGet, interceptUpdate, } from './utils'; import * as ace from 'brace'; @@ -64,9 +65,13 @@ function discardChanges() { function visitEdit() { interceptCharts(); + interceptGet(); + cy.visit(SAMPLE_DASHBOARD_1); + cy.wait('@get'); editDashboard(); cy.wait('@filtering'); + cy.wait(500); } function selectColorScheme(color: string) { @@ -98,7 +103,8 @@ function assertMetadata(text: string) { }); } function clearAll(input: string) { - return cy.get(input).type('{selectall}{backspace}'); + cy.get(input).type('{selectall}{backspace}'); + return cy.wait(500); } describe('Dashboard edit', () => { @@ -133,6 +139,13 @@ describe('Dashboard edit', () => { cy.getBySel('dashboard-charts-filter-search-input').clear(); }); + it('should disable the Save button when undoing', () => { + dragChart(); + cy.getBySel('header-save-button').should('be.enabled'); + discardChanges(); + cy.getBySel('header-save-button').should('be.disabled'); + }); + }); describe('Components', () => { @@ -245,22 +258,11 @@ describe('Dashboard edit', () => { }); describe('Save', () => { - before(() => { + beforeEach(() => { cy.createSampleDashboards(); visitEdit(); }); - beforeEach(() => { - discardChanges(); - }) - - it('should disable saving when undoing', () => { - dragChart(); - cy.getBySel('header-save-button').should('be.enabled'); - discardChanges(); - cy.getBySel('header-save-button').should('be.disabled'); - }); - it('should save', () => { dragChart(); cy.getBySel('header-save-button').should('be.enabled'); diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts index b4d2dd3100..072a190314 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts @@ -30,6 +30,10 @@ { name: 'Box plot', viz: 'box_plot' }, ] as const; +export function interceptGet() { +cy.intercept('/api/v1/dashboard/*').as('get'); +} + export function interceptFiltering() { cy.intercept('GET', `/api/v1/dashboard/?q=*`).as('filtering'); } diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts index c33a8fe948..8c70ff7a88 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard_list/filter.test.ts @@ -22,7 +22,6 @@ import { setFilter } from '../dashboard/utils'; describe('Dashboards filters', () => { before(() => { - cy.login(); cy.visit(DASHBOARD_LIST); }); 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 adfb0ea13d..da9d7a4bfc 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 @@ -44,10 +44,6 @@ function confirmDelete() { } describe('Dashboards list', () => { - before(() => { - cy.login(); - }); - beforeEach(() => { cy.preserveLogin(); }); diff --git a/superset-frontend/cypress-base/cypress/support/index.d.ts b/superset-frontend/cypress-base/cypress/support/index.d.ts index a5011090ee..a7e0f6836a 100644 --- a/superset-frontend/cypress-base/cypress/support/index.d.ts +++ b/superset-frontend/cypress-base/cypress/support/index.d.ts @@ -39,8 +39,10 @@ declare namespace Cypress { getBySel(selector: string): cy; getBySelLike(selector: string): cy; getSampleData(): void; - cleanCharts(): void; - cleanDashboards(): void; + cleanCharts(): cy; + cleanDashboards(): cy; + loadChartFixtures(): cy; + loadDashboardFixtures(): cy; visitChartByParams(params: string | Record<string, unknown>): cy; visitChartByName(name: string): cy; diff --git a/superset-frontend/cypress-base/cypress/support/index.ts b/superset-frontend/cypress-base/cypress/support/index.ts index 3c24d167c3..6116feef9c 100644 --- a/superset-frontend/cypress-base/cypress/support/index.ts +++ b/superset-frontend/cypress-base/cypress/support/index.ts @@ -25,37 +25,91 @@ const BASE_EXPLORE_URL = '/explore/?form_data='; const TokenName = Cypress.env('TOKEN_NAME'); let SAMPLE_DASHBOARDS: Record<string, any>[] = []; let SAMPLE_CHARTS: Record<string, any>[] = []; +let DASHBOARD_FIXTURES: Record<string, any>[] = []; +let CHART_FIXTURES: Record<string, any>[] = []; -Cypress.Commands.add('getSampleData', () => - cy.getCharts().then((slices: any) => { - SAMPLE_CHARTS = slices; - cy.getDashboards().then((dashboards: any) => { - SAMPLE_DASHBOARDS = dashboards; - }); +Cypress.Commands.add('loadChartFixtures', () => + cy.fixture('charts.json').then(charts => { + CHART_FIXTURES = charts }) ); -Cypress.Commands.add('cleanDashboards', () => +Cypress.Commands.add('loadDashboardFixtures', () => cy.fixture('dashboards.json').then(dashboards => { - for (let i = 0; i < dashboards.length; i += 1) { - cy.deleteDashboardByName(dashboards[i].dashboard_title, false) - } - }) -); - -Cypress.Commands.add('cleanCharts', () => - cy.fixture('charts.json').then(charts => { - for (let i = 0; i < charts.length; i += 1) { - cy.deleteChartByName(charts[i].slice_name, false) - } + DASHBOARD_FIXTURES = dashboards }) ); before(() => { cy.login(); + cy.loadChartFixtures(); + cy.loadDashboardFixtures(); + cy.getSampleData(); cy.cleanDashboards(); cy.cleanCharts(); - cy.getSampleData(); +}); + +Cypress.Commands.add('getSampleData', () => { + cy.getCharts().then((slices: any) => { + SAMPLE_CHARTS = slices; + }); + cy.getDashboards().then((dashboards: any) => { + SAMPLE_DASHBOARDS = dashboards; + }); +}); + +Cypress.Commands.add('cleanDashboards', () => +{ + const deletableDashboards = []; + for (let i = 0; i < DASHBOARD_FIXTURES.length; i += 1) { + const isInDb = SAMPLE_DASHBOARDS.find(d => d.dashboard_title === DASHBOARD_FIXTURES[i].dashboard_title); + if (isInDb) { + deletableDashboards.push(isInDb.id); + } + } + return cy + .request({ + failOnStatusCode: false, + method: 'DELETE', + url: `api/v1/dashboard/?q=!(${deletableDashboards.join(',')})`, + 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) +}); + +Cypress.Commands.add('cleanCharts', () => +{ + const deletableCharts = []; + for (let i = 0; i < CHART_FIXTURES.length; i += 1) { + const isInDb = SAMPLE_CHARTS.find(c => c.slice_name === CHART_FIXTURES[i].slice_name); + if (isInDb) { + deletableCharts.push(isInDb.id); + } + } + return cy + .request({ + failOnStatusCode: false, + method: 'DELETE', + url: `api/v1/chart/?q=!(${deletableCharts.join(',')})`, + 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) }); Cypress.Commands.add('getBySel', (selector, ...args) => @@ -197,6 +251,7 @@ Cypress.Commands.add('createSampleDashboards', () => { method: 'POST', url: `/api/v1/dashboard/`, body: dashboards[i], + failOnStatusCode: false, headers: { Cookie: `csrf_access_token=${window.localStorage.getItem( 'access_token', @@ -214,8 +269,8 @@ Cypress.Commands.add('createSampleDashboards', () => { }); Cypress.Commands.add('createSampleCharts', () => { - cy.cleanCharts(); const requests: any = []; + cy.cleanCharts(); return cy.fixture('charts.json').then(charts => { for (let i = 0; i < charts.length; i += 1) { requests.push( @@ -223,6 +278,7 @@ Cypress.Commands.add('createSampleCharts', () => { method: 'POST', url: `/api/v1/chart/`, body: charts[i], + failOnStatusCode: false, headers: { Cookie: `csrf_access_token=${window.localStorage.getItem( 'access_token', @@ -251,7 +307,7 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add('deleteDashboard', (id: number, failOnStatusCode = true) => +Cypress.Commands.add('deleteDashboard', (id: number, failOnStatusCode = false) => cy .request({ failOnStatusCode, @@ -283,7 +339,7 @@ Cypress.Commands.add('getDashboards', () => .then(resp => resp.body.result), ); -Cypress.Commands.add('deleteChart', (id: number, failOnStatusCode = true) => +Cypress.Commands.add('deleteChart', (id: number, failOnStatusCode = false) => cy .request({ failOnStatusCode,
