This is an automated email from the ASF dual-hosted git repository. ccwilliams pushed a commit to branch chris--sqllab-cypress in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 98c4dd972897de2e36818fbab9dd0e62441b723f Author: Chris Williams <[email protected]> AuthorDate: Tue Sep 25 22:05:17 2018 -0700 [cypress] add tests for SQL Lab query panel --- .../assets/cypress/integration/sqllab/query.js | 126 +++++++++++++++++++++ .../cypress/integration/sqllab/sourcePanel.js | 7 +- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/superset/assets/cypress/integration/sqllab/query.js b/superset/assets/cypress/integration/sqllab/query.js new file mode 100644 index 0000000..73d71bb --- /dev/null +++ b/superset/assets/cypress/integration/sqllab/query.js @@ -0,0 +1,126 @@ +import shortid from 'shortid'; +import { selectResultsTab } from '../../selectors'; + +// this function asserts that the result set for two SQL lab table results are equal +const assertSQLLabResultsAreEqual = (resultsA, resultsB) => { + const [headerA, bodyWrapperA] = resultsA.childNodes; + const bodyA = bodyWrapperA.childNodes[0]; + + const [headerB, bodyWrapperB] = resultsB.childNodes; + const bodyB = bodyWrapperB.childNodes[0]; + + expect(headerA.childNodes.length).to.equal(headerB.childNodes.length); + expect(bodyA.childNodes.length).to.equal(bodyB.childNodes.length); + + bodyA.childNodes.forEach((rowA, rowIndex) => { + const rowB = bodyB.childNodes[rowIndex]; + + rowA.childNodes.forEach((cellA, columnIndex) => { + const cellB = rowB.childNodes[columnIndex]; + expect(cellA.innerText).to.equal(cellB.innerText); + }); + }); +}; + +describe('SqlLab query panel', () => { + beforeEach(() => { + cy.login(); + cy.server(); + cy.visit('/superset/sqllab'); + }); + + // it('supports entering and running a query', () => { + // // note that the limit has to be < ~10 for us to be able to determine + // // how many rows are below (because React _Virtualized_ does not render all rows) + // const rowLimit = 3; + // + // cy.get('#brace-editor textarea') + // .type( + // `{selectall}{backspace}SELECT ds, gender, name, num FROM main.birth_names LIMIT ${rowLimit}`, + // { force: true }, + // ) + // .then(() => { + // cy.get('#js-sql-toolbar button') + // .eq(0) + // .click() + // .then(() => { + // cy.get('.SouthPane .ReactVirtualized__Table') + // .eq(0) // ensures results tab in case preview tab exists + // .then((tableNodes) => { + // const [header, bodyWrapper] = tableNodes[0].childNodes; + // const body = bodyWrapper.childNodes[0]; + // const expectedColCount = header.childNodes.length; + // const expectedRowCount = body.childNodes.length; + // expect(expectedColCount).to.equal(4); + // expect(expectedRowCount).to.equal(rowLimit); + // }); + // }); + // }); + // }); + + it('successfully saves a query', () => { + const query = 'SELECT ds, gender, name, num FROM main.birth_names ORDER BY name LIMIT 3'; + const savedQueryTitle = `CYPRESS TEST QUERY ${shortid.generate()}`; + + // we will assert that the results of the query we save, and the saved query are the same + let initialResultsTable = null; + let savedQueryResultsTable = null; + + cy.get('#brace-editor textarea') + .type(`{selectall}{backspace}${query}`, { force: true }) + .focus() // focus => blur is required for updating the query that is to be saved + .blur() + .then(() => { + // ctrl + r also runs query + cy.get('#brace-editor textarea') + .type('{ctrl}r', { force: true }) + .then(() => { + selectResultsTab().then((resultsA) => { + // Save results to check agains below + initialResultsTable = resultsA[0]; + console.log('initialResultsTable', initialResultsTable); + + cy.get('#js-sql-toolbar button') + .eq(1) // save query + .click() + .then(() => { + // Enter name + save into modal + cy.get('.modal-sm input') + .type(`{selectall}{backspace}${savedQueryTitle}`, { + force: true, + }) + .then(() => { + cy.get('.modal-sm .modal-body button') + .eq(0) + .click() + .then(() => { + // visit saved queries + cy.visit('/sqllab/my_queries/').then(() => { + // first row contains most recent link + // visit saved query page + cy.get('table tr:first-child a[href*="savedQueryId"') + .click() + .then(() => { + cy.get('#js-sql-toolbar button') + .eq(0) // Run query + .click() + .then(() => { + selectResultsTab().then((resultsB) => { + savedQueryResultsTable = resultsB[0]; + + assertSQLLabResultsAreEqual( + initialResultsTable, + savedQueryResultsTable, + ); + }); + }); + }); + }); + }); + }); + }); + }); + }); // run query + }); + }); +}); diff --git a/superset/assets/cypress/integration/sqllab/sourcePanel.js b/superset/assets/cypress/integration/sqllab/sourcePanel.js index 5bfa3ba..b0bf69e 100644 --- a/superset/assets/cypress/integration/sqllab/sourcePanel.js +++ b/superset/assets/cypress/integration/sqllab/sourcePanel.js @@ -1,3 +1,5 @@ +import { selectResultsTab } from '../../selectors'; + describe('SqlLab datasource panel', () => { beforeEach(() => { cy.login(); @@ -18,6 +20,7 @@ describe('SqlLab datasource panel', () => { cy.get('.sql-toolbar .Select') .eq(0) .within(() => { + // note: we have to set force: true because the input is invisible / cypress throws cy.get('input').type('main{enter}', { force: true }); }) .then(() => { @@ -36,7 +39,7 @@ describe('SqlLab datasource panel', () => { }) .then(() => { cy.get('.sql-toolbar .table-schema').should('have.length', 1); - cy.get('.SouthPane .tab-content .filterable-table-container').should('have.length', 1); + selectResultsTab().should('have.length', 1); }) .then(() => { cy.get('.sql-toolbar .Select') @@ -47,7 +50,7 @@ describe('SqlLab datasource panel', () => { }) .then(() => { cy.get('.sql-toolbar .table-schema').should('have.length', 2); - cy.get('.SouthPane .tab-content .filterable-table-container').should('have.length', 2); + selectResultsTab().should('have.length', 2); }); }); });
