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

[TESTING] Survey view testing #4802

Merged
merged 10 commits into from
Nov 27, 2023
Merged

[TESTING] Survey view testing #4802

merged 10 commits into from
Nov 27, 2023

Conversation

Annelein
Copy link
Collaborator

Fixes #4782

Tests:

  • Fill in one answer
  • Fill in remaining 3 answers
  • Click skip button
  • Click remind me tomorrow button

It would be nice to only test classes that have students, anyone knows how to do that?

@Annelein Annelein self-assigned this Nov 24, 2023
@ghost
Copy link

ghost commented Nov 24, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@Annelein Annelein marked this pull request as ready for review November 24, 2023 11:29
cy.wait(500);

cy.get(".view_class").first().click()
cy.get("body").then(surveyView).then(survey => {
Copy link
Member

Choose a reason for hiding this comment

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

This works, but is not really the Cypress way of doing it. You don't need to target the body and then find the survey, cy.get can select any element of the page, so doing cy.get('#survey') will do the job. Look at how we target elements on the other tests for some guidance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thing is, if a class doesn't contain students, there is no survey view, so cy.get('#survey') fails. So I was looking for a workaround and found this in other tests.

Copy link
Member

Choose a reason for hiding this comment

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

Ohh I get it. CLASS1 in the database has some students, so maybe targetting that class is the way to go. Otherwise, you might create a new class, add some students and then run this test to guarantee that the survey will be shown.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good one! Will do that thanks.

loginForTeacher();

cy.get(".view_class").first().click()
cy.get("body").then(surveyView).then(survey => {
Copy link
Member

Choose a reason for hiding this comment

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

These tests are dependent on one another. This is not advisable unless on specific circumstances where we want to save some time, but we should avoid them as much as possible. Our philosophy with Cypress is making the tests independent from one another. See here: https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Test-Isolation

Copy link
Member

@jpelay jpelay left a comment

Choose a reason for hiding this comment

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

Hi, Annelein! Good job with the testing, but I think we can improve them a bit:

  • As I told you in the comment, we don't need to target body to get an element, just as you can do in JQuery or Javascript you can target an element by its id. We also have a function, called cy.getBySel where we don't even target by id, but an specefic target dedicated for testing. You can see an example of that in action in the class_customization.cy.js file.

  • It's preferable for the tests to be independent on one another. This can take a hit in our performance and make the test suite longer, but I think is best we stick with this for now. What does this mean for this particular PR? For example, if you're checking if by only answering one question, the next time you come to the class you'll be shown three question, you do that in a single test.
    For this you can for example create a new class before each tests, with a beforeEach hook.

I recommend you take a quick peek to Cypress documentation to know a little bit about the framework: https://docs.cypress.io/guides/core-concepts/introduction-to-cypress

@Annelein
Copy link
Collaborator Author

@jpelay let me know if this is better!

Copy link
Member

@jpelay jpelay left a comment

Choose a reason for hiding this comment

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

Thanks for these tests, Annelein 😄! Great work!

Copy link
Contributor

mergify bot commented Nov 27, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 1b47854 into main Nov 27, 2023
11 checks passed
@mergify mergify bot deleted the survey-view-testing branch November 27, 2023 17:20
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.

[TESTING] Survey view needs testing
2 participants