kristw commented on a change in pull request #5974: [cypress] add SQL lab tests
URL:
https://github.com/apache/incubator-superset/pull/5974#discussion_r220641931
##########
File path: superset/assets/cypress/integration/sqllab/query.js
##########
@@ -0,0 +1,125 @@
+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];
+
+ cy.get('#js-sql-toolbar button')
+ .eq(1) // save query
+ .click()
+ .then(() => {
+ // Enter name + save into modal
+ cy.get('.modal-sm input')
Review comment:
some of these nested `then` clause may not needed to be nested.
Cypress does some magic to apply `.then` for you under the hood.
```js
cy.get('a').click()
cy.get('b').click() // will wait for the statement above to resolve
```
https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Promises
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]