-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
cy.wait('@events').then((interception) => { | ||
avneet-raj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const responseBody = interception.request.body; | ||
const responseData1 = responseBody[0].data; | ||
const responseData2 = responseBody[1].data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if("experience_level" in responseData1){ | ||
expect(responseData1.experience_level).equal(experience_val); | ||
}; | ||
if("experience_level" in responseData2){ | ||
expect(responseData2.experience_level).equal(experience_val); | ||
}; | ||
}); | ||
}; | ||
|
||
it( 'Check if events API call being made after radio buttons are clicked', () => { | ||
let radioCount = 0; | ||
const className = '.components-radio-control__option'; | ||
const arr = cy.get( className ); | ||
arr.each( () => { | ||
cy.reload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed reload. |
||
cy.wait(2000); | ||
cy.get( '[type="radio"]' ) | ||
.eq( radioCount ) | ||
.click( { force: true } ) | ||
if(radioCount==0){ | ||
EventsAPI("novice"); | ||
arunshenoy99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
if(radioCount==1){ | ||
EventsAPI("intermediate"); | ||
}; | ||
if(radioCount>1){ | ||
cy.wait(5000); | ||
EventsAPI("expert"); | ||
}; | ||
radioCount += 1; | ||
} ); | ||
} ); | ||
|
||
it( 'Checks if Continue Setup Button is Enabled after the Radio Button is Checked.', () => { | ||
cy.get( '[type=radio]:checked' ).should( | ||
'have.css', | ||
|
There was a problem hiding this comment.
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-RegExpThere was a problem hiding this comment.
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.