williaster commented on a change in pull request #5974: [cypress] add SQL lab
tests
URL:
https://github.com/apache/incubator-superset/pull/5974#discussion_r223463668
##########
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:
I have the `cy.get(...)` below this line (which just looks for the run query
button), and it fails because because it doesn't load in time/times out.
Thanks for the `wait` suggestion tho, I'll try naming the route and see if that
helps at all.
----------------------------------------------------------------
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]