Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress tests for query parameters #3810

Merged
merged 7 commits into from
May 30, 2019
Merged

Conversation

gabrieldutra
Copy link
Member

@gabrieldutra gabrieldutra commented May 17, 2019

What type of PR is this? (check all applicable)

  • Other

Description

Following #3737 (and the bug #3803) I wanted to add a few tests to another important part of Redash: Query parameters 😁

Parameters:

  • Text
  • Number
  • Date
  • Date and time
    • Date selection
    • "Now" button
  • Dropdown
  • Use requests instead of UI to improve speed

Related Tickets & Documents

--

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

afterEach(() => {
cy.getByTestId('SaveButton').click();
cy.url().should('match', /\/queries\/\d+\/source/);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure this is needed? Can leave new query unsaved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either save the query or this workaround 😬

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right right!

@ranbena
Copy link
Contributor

ranbena commented May 17, 2019

Suggesting to add tests in Dashboard context.

@gabrieldutra
Copy link
Member Author

Suggesting to add tests in Dashboard context.

Mostly I want to test the Parameters component (the shared part), which seemed easier from the Query context. But I think it's good to add the "extra" part that dashboards have (global, local and static parameters).

--

Just to share some points I was thinking about:

  • It can be interesting to save the queries and name then according to the parameter type - so it's possible to access the server and its state well organized after the tests;
  • We could introduce Faker or any other library with the same purpose if we want some dynamic data (thought this after thinking about random numbers to put on tests 😅). I think this one is out of scope here, but I wanted to share it anyway (can be addressed as a GH issue).

@ranbena
Copy link
Contributor

ranbena commented May 18, 2019

Mostly I want to test the Parameters component (the shared part), which seemed easier from the Query context. But I think it's good to add the "extra" part that dashboards have (global, local and static parameters).

I mean specifically test the "apply" functionality in the dashboard context, that it triggers widget refresh.

  • It can be interesting to save the queries and name then according to the parameter type - so it's possible to access the server and its state well organized after the tests;

For what purpose? To db-seed these queries?

@arikfr
Copy link
Member

arikfr commented May 19, 2019

Great initiative!

@gabrieldutra
Copy link
Member Author

It seems that Cypress has an issue when it's necessary to click more than once on Antd's Date Calendar, the first click works, the following ones don't ^^. This affected creating specs for DateTime and DateRanges. I think my last test will be to trigger DateTime by clicking enter or clicking outside the panel.

I mean specifically test the "apply" functionality in the dashboard context, that it triggers widget refresh.

I thought about adding a smaller test just to make sure the behavior extends to the dashboard context, but this is sort of already happening with specs that rely on that behavior (e.g: "Height behavior on refresh"). Do you think we gain any value by having that separate?

For what purpose? To db-seed these queries?

🤔. I though more about development and unautomated tests. After running Cypress you'd get Redash with a basic set of organized data (in this case, queries that you could test each parameter). I'll think better about it, perhaps sth not for now as I don't really use Cypress data after it runs (and guessing nobody actually does it here).

Copy link
Member Author

@gabrieldutra gabrieldutra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to use requests instead of UI (reduced 30 seconds). Date parameters are still created through UI since Cypress showed similar clicking issues with it when the parameter was set in the request.

client/app/components/EditParameterSettingsDialog.jsx Outdated Show resolved Hide resolved
@@ -19,11 +19,11 @@ export function createQuery(data, shouldPublish = true) {
}, data);

// eslint-disable-next-line cypress/no-assigning-return-values
let request = cy.request('POST', '/api/queries', merged);
let request = cy.request('POST', '/api/queries', merged).then(({ body }) => body);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the shouldPublish = true changed it to return the body directly.

@gabrieldutra gabrieldutra marked this pull request as ready for review May 27, 2019 18:22
@gabrieldutra gabrieldutra self-assigned this May 27, 2019
@gabrieldutra gabrieldutra requested a review from ranbena May 28, 2019 14:09
Copy link
Contributor

@ranbena ranbena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the good times roll

@gabrieldutra gabrieldutra merged commit b27df21 into master May 30, 2019
@gabrieldutra gabrieldutra deleted the cypress-parameter-spec branch May 30, 2019 13:03
harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants