From a99d795eaf546222af57ed35a53b2a2ac111f7e2 Mon Sep 17 00:00:00 2001 From: adam-stasiak-polidea Date: Tue, 27 Oct 2020 21:01:45 +0100 Subject: [PATCH] chore: cypress selectors refactor in explore module (#11309) * cypress selectors refactor in explore module * added delay to typing to make test more stable * fixed missing click --- .../integration/explore/AdhocFilters.test.ts | 7 ++- .../integration/explore/control.test.ts | 20 ++++--- .../cypress/integration/explore/link.test.js | 58 +++++++++---------- .../src/CRUD/CollectionTable.tsx | 3 +- .../src/datasource/DatasourceEditor.jsx | 1 + .../src/explore/components/SaveModal.jsx | 2 +- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/explore/AdhocFilters.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/AdhocFilters.test.ts index 1880f7fc08..6522555aca 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/AdhocFilters.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/AdhocFilters.test.ts @@ -73,9 +73,10 @@ describe('AdhocFilters', () => { .click(); cy.get('[data-test=adhoc_filters] input[type=text]') .focus() - .type('name{enter}'); - cy.get('.adhoc-filter-option').click(); - + .type('name{enter}', { delay: 20 }); + cy.get('[data-test="adhoc_filters"]').within(() => { + cy.contains('name = ').should('be.visible').click(); + }); cy.wait('@filterValues'); cy.get('#filter-edit-popover #adhoc-filter-edit-tabs-tab-SQL').click(); diff --git a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts index 70acb8d95d..1fd517b639 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts @@ -46,18 +46,20 @@ describe('Datasource control', () => { cy.get('script').then(nodes => { expect(nodes.length).to.greaterThan(numScripts); }); - - // create new metric - cy.get('.modal-content').within(() => { - cy.get('a[role="tab"]').contains('Metrics').click(); + cy.get('[data-test="edit-dataset-tabs"]').within(() => { + cy.contains('Metrics').click(); }); - cy.get('button').contains('Add Item', { timeout: 10000 }).click(); - cy.get('input[value=""]').click(); - cy.get('input[value=""]') + // create new metric + cy.get('[data-test="crud-add-table-item"]', { timeout: 10000 }).click(); + cy.get('[data-test="table-content-rows"]') + .find('input[value=""]') + .click(); + cy.get('[data-test="table-content-rows"]') + .find('input[value=""]') .focus() .clear() .type(`${newMetricName}{enter}`); - cy.get('.modal-footer button').contains('Save').click(); + cy.get('[data-test="datasource-modal-save"]').click(); cy.get('.modal-footer button').contains('OK').click(); // select new metric cy.get('[data-test=metrics]') @@ -74,7 +76,7 @@ describe('Datasource control', () => { .closest('tr') .find('.fa-trash') .click(); - cy.get('.modal-footer button').contains('Save').click(); + cy.get('[data-test="datasource-modal-save"]').click(); cy.get('.modal-footer button').contains('OK').click(); cy.get('.Select__multi-value__label') .contains(newMetricName) diff --git a/superset-frontend/cypress-base/cypress/integration/explore/link.test.js b/superset-frontend/cypress-base/cypress/integration/explore/link.test.js index 8b0bbb227e..029527ffcb 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/link.test.js +++ b/superset-frontend/cypress-base/cypress/integration/explore/link.test.js @@ -91,21 +91,17 @@ describe('Test explore links', () => { cy.visitChartByParams(JSON.stringify(formData)); cy.verifySliceSuccess({ waitAlias: '@postJson' }); cy.url().then(() => { - cy.get('button[data-target="#save_modal"]').click(); - cy.get('.modal-content').within(() => { - cy.get('#saveas-radio').check(); - cy.get('input[name=new_slice_name]').type(newChartName); - cy.get('button#btn_modal_save').click(); - }); + cy.get('[data-test="query-save-button"]').click(); + cy.get('[data-test="saveas-radio"]').check(); + cy.get('[data-test="new-chart-name"]').type(newChartName); + cy.get('[data-test="btn-modal-save"]').click(); cy.verifySliceSuccess({ waitAlias: '@postJson' }); cy.visitChartByName(newChartName); // Overwriting! - cy.get('button[data-target="#save_modal"]').click(); - cy.get('.modal-content').within(() => { - cy.get('#overwrite-radio').check(); - cy.get('button#btn_modal_save').click(); - }); + cy.get('[data-test="query-save-button"]').click(); + cy.get('[data-test="save-overwrite-radio"]').check(); + cy.get('[data-test="btn-modal-save"]').click(); cy.verifySliceSuccess({ waitAlias: '@postJson' }); const query = { filters: [ @@ -131,16 +127,15 @@ describe('Test explore links', () => { cy.visitChartByName(chartName); cy.verifySliceSuccess({ waitAlias: '@postJson' }); - cy.get('button[data-target="#save_modal"]').click(); - cy.get('.modal-content').within(() => { - cy.get('#saveas-radio').check(); - cy.get('input[name=new_slice_name]').click().clear().type(newChartName); - // Add a new option using the "CreatableSelect" feature - cy.get('#dashboard-creatable-select').type( - `${dashboardTitle}{enter}{enter}`, - ); - cy.get('button#btn_modal_save').click(); - }); + cy.get('[data-test="query-save-button"]').click(); + cy.get('[data-test="saveas-radio"]').check(); + cy.get('[data-test="new-chart-name"]').click().clear().type(newChartName); + // Add a new option using the "CreatableSelect" feature + cy.get('[data-test="save-chart-modal-select-dashboard-form"]') + .find('#dashboard-creatable-select') + .type(`${dashboardTitle}{enter}{enter}`); + + cy.get('[data-test="btn-modal-save"]').click(); cy.verifySliceSuccess({ waitAlias: '@postJson' }); let query = { filters: [ @@ -158,17 +153,16 @@ describe('Test explore links', () => { cy.visitChartByName(newChartName); cy.verifySliceSuccess({ waitAlias: '@postJson' }); - cy.get('button[data-target="#save_modal"]').click(); - cy.get('.modal-content').within(() => { - cy.get('#overwrite-radio').check(); - cy.get('input[name=new_slice_name]').click().clear().type(newChartName); - // This time around, typing the same dashboard name - // will select the existing one - cy.get('#dashboard-creatable-select').type( - `${dashboardTitle}{enter}{enter}`, - ); - cy.get('button#btn_modal_save').click(); - }); + cy.get('[data-test="query-save-button"]').click(); + cy.get('[data-test="save-overwrite-radio"]').check(); + cy.get('[data-test="new-chart-name"]').click().clear().type(newChartName); + // This time around, typing the same dashboard name + // will select the existing one + cy.get('[data-test="save-chart-modal-select-dashboard-form"]') + .find('#dashboard-creatable-select') + .type(`${dashboardTitle}{enter}{enter}`); + + cy.get('[data-test="btn-modal-save"]').click(); cy.verifySliceSuccess({ waitAlias: '@postJson' }); query = { filters: [ diff --git a/superset-frontend/src/CRUD/CollectionTable.tsx b/superset-frontend/src/CRUD/CollectionTable.tsx index 0572146e31..72370c83ca 100644 --- a/superset-frontend/src/CRUD/CollectionTable.tsx +++ b/superset-frontend/src/CRUD/CollectionTable.tsx @@ -290,7 +290,8 @@ export default class CRUDCollection extends React.PureComponent< onClick={this.onAddItem} data-test="add-item-button" > - {t('Add Item')} + {' '} + {t('Add Item')} )} diff --git a/superset-frontend/src/datasource/DatasourceEditor.jsx b/superset-frontend/src/datasource/DatasourceEditor.jsx index 56bc58a9d2..a1c9a122bf 100644 --- a/superset-frontend/src/datasource/DatasourceEditor.jsx +++ b/superset-frontend/src/datasource/DatasourceEditor.jsx @@ -887,6 +887,7 @@ class DatasourceEditor extends React.PureComponent { diff --git a/superset-frontend/src/explore/components/SaveModal.jsx b/superset-frontend/src/explore/components/SaveModal.jsx index b76d2609d2..40afd289c9 100644 --- a/superset-frontend/src/explore/components/SaveModal.jsx +++ b/superset-frontend/src/explore/components/SaveModal.jsx @@ -185,7 +185,7 @@ class SaveModal extends React.Component { data-test="new-chart-name" /> - + {t('Add to dashboard')}