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 events API for get-experience page #329

Merged
merged 4 commits into from
Oct 20, 2023

Conversation

avneet-raj
Copy link
Contributor

@avneet-raj avneet-raj commented Oct 10, 2023

Added Cypress Tests for events API on get-started-experience step for different API calls being made at the time of different options selected based on experience level.

@avneet-raj avneet-raj self-assigned this Oct 10, 2023
@avneet-raj avneet-raj added the Code Review The PR is in Code Review label Oct 10, 2023
@@ -65,6 +65,45 @@ describe( 'Start Setup WP Experience Page', function () {
} );
} );

const EventsAPI = ( experience_val ) => {
cy.intercept('http://localhost:8882/index.php?rest_route=%2Fnewfold-onboarding%2Fv1%2Fevents%2Fbatch&flow=wp-setup&_locale=user').as('events');
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this URL into a common constant? Additionally, could we consider using a regex that matches events/batch instead of the entire URL? https://docs.cypress.io/api/commands/intercept#Icon-nameangle-right--url-String-Glob-RegExp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for now I have moved all the API in a single file. I'll do the regex that matches the URL also.

Comment on lines 72 to 73
const responseData1 = responseBody[0].data;
const responseData2 = responseBody[1].data;
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between responseData1 and responseData2? Do we require both of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed for the edge case, sometimes the experience _level comes into the second data and sometimes in the first. I've refined it more now so that, it doesn't fail. 90% of the time it'll come in the resposeData1.

const className = '.components-radio-control__option';
const arr = cy.get( className );
arr.each( () => {
cy.reload();
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to reload the page every time we click a radio button? That's not in line with how the user will be clicking the buttons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this'll be needed to clear the older network logs as every time when a radio button is clicked, the API call is overlapped on the earlier one (happening only on cypress). So, to eliminate this, we have to use reload before every radio button click.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed reload.

@arunshenoy99 arunshenoy99 merged commit 24759b1 into trunk Oct 20, 2023
@arunshenoy99 arunshenoy99 deleted the add/cypress-test-events-for-experience-page branch October 20, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Review The PR is in Code Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants