Skip to content

Commit

Permalink
refactor: replace hardcoded quiz option selectors with a reusable com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
acabreragnz committed Oct 1, 2024
1 parent 21bdab9 commit 873bb59
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cypress/e2e/ArticleQuiz/GuestEarnCredits.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ describe('GuestEarnCredits', { tags: ['@article-quiz', '@guest', '@business:medi
cy.contains('Agree and start').click();
cy.contains('Take quiz').click();

let firstOptionSelector = '.v-input--radio-group__input > :nth-child(1)';
for (let i = 0; i < 4; i++) {
cy.get(firstOptionSelector).click();
cy.getQuizOptionByIndex(0).click();
cy.contains('Next question').click();
}
// the last question does not have a "Next question" button
cy.get(firstOptionSelector).click();
cy.getQuizOptionByIndex(0).click();

if (!isLastArticle) {
cy.contains('Go to feed').click();
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/ArticleQuiz/UserTakeQuizz.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('UserTakeQuiz', { tags: ['@article-quiz', '@business:critical'] }, () =

function answerQuestion({ failedAnswerNumber }) {
// select a choice
// TODO: we need a test-id here as we cannot get it by text value
cy.get(`.v-input--radio-group__input > :nth-child(${answerIndex})`).click();
cy.getQuizOptionByIndex(answerIndex).click();

cy.wait('@answerQuestion').then((interception) => {
const responseBody = interception.response.body;
const isCorrectAnswer = responseBody.success === 1;
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/Referrals/FreeReferral.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ describe('Free referred E2E Test', { tags: ['@referral', '@free-plan', '@low-lik

function answerQuestion({ failedAnswerNumber }) {
// select a choice
// TODO: we need a test-id here as we cannot get it by text value
cy.get(`.v-input--radio-group__input > :nth-child(${answerIndex})`).click();
cy.getQuizOptionByIndex(answerIndex).click();

cy.wait('@answerQuestion').then((interception) => {
const responseBody = interception.response.body;
const isCorrectAnswer = responseBody.success === 1;
Expand Down
4 changes: 4 additions & 0 deletions cypress/support/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ Cypress.Commands.add('selectDate', ({ year, month, day }) => {
cy.get('.v-date-picker-months').contains(month).click();
cy.get('.v-date-picker-month').contains(day).click();
});

Cypress.Commands.add('getQuizOptionByIndex', (index) => {
cy.get(`.v-selection-control-group > :nth-child(${index + 1})`);
});

0 comments on commit 873bb59

Please sign in to comment.