You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/10/06 00:23:27 UTC

[GitHub] michellethomas commented on a change in pull request #5974: [cypress] add SQL lab tests

michellethomas commented on a change in pull request #5974: [cypress] add SQL lab tests
URL: https://github.com/apache/incubator-superset/pull/5974#discussion_r223164642
 
 

 ##########
 File path: superset/assets/cypress/integration/sqllab/_query.js
 ##########
 @@ -0,0 +1,97 @@
+import shortid from 'shortid';
+import { selectResultsTab, assertSQLLabResultsAreEqual } from './sqllab.helper';
+
+export default () => {
+  describe('SqlLab query panel', () => {
+    beforeEach(() => {
+      cy.login();
+      cy.server();
+      cy.visit('/superset/sqllab');
+    });
+
+    it('supports entering and running a query', () => {
+      // row limit has to be < ~10 for us to be able to determine how many rows
+      // are fetched 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 },
+      );
+      cy.get('#js-sql-toolbar button')
+        .eq(0)
+        .click();
+
+      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();
+
+      // ctrl + r also runs query
+      cy.get('#brace-editor textarea').type('{ctrl}r', { force: true });
+
+      // Save results to check agains below
+      selectResultsTab().then((resultsA) => {
+        initialResultsTable = resultsA[0];
+      });
+
+      cy.get('#js-sql-toolbar button')
+        .eq(1) // save query
+        .click();
+
+      // Enter name + save into modal
+      cy.get('.modal-sm input').type(`{selectall}{backspace}${savedQueryTitle}`, {
+        force: true,
+      });
+
+      cy.get('.modal-sm .modal-body button')
+        .eq(0) // save
+        .click();
+
+      // visit saved queries
+      cy.visit('/sqllab/my_queries/');
+
+      // first row contains most recent link, follow back to SqlLab
+      // cy.get('table tr:first-child a[href*="savedQueryId"').click();
+
+      cy.get('table tr:first-child a[href*="savedQueryId"')
+        .should('have.attr', 'href')
+        .then((href) => {
+          cy.visit(href).then(() => {
+            cy.wait(1000);
 
 Review comment:
   is there some route you could [wait](https://docs.cypress.io/guides/guides/network-requests.html#Waiting) for or is it just the frontend that takes a long time to load? A `get` will [retry](https://docs.cypress.io/api/commands/get.html#Assertions) until the element exists in the dom, could you get another element that's critical for the page as a way to wait for the page to load?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org