Repository: freeCodeCamp/freeCodeCamp
File: e2e/exam-started-show.spec.ts (TypeScript)

Code before:
    });
    for (let i = 1; i < 6; i++) {
      await expect(headerTitle).toBeVisible();
      await expect(headerTitle).toContainText(
        intro['foundational-c-sharp-with-microsoft'].blocks[
          'foundational-c-sharp-with-microsoft-certification-exam'
        ].title
      );

      await expect(page.getByTestId('exam-show-question-time')).toContainText(
        translations.learn.exam.time.split(':')[0]
      );
      await expect(
        page.getByText('Question ' + String(i) + ' of 5')
      ).toBeVisible();

      await expect(prevQuestionBtn).toBeVisible();
      if (i != 1) {
        await expect(prevQuestionBtn).toBeEnabled();
      } else {
        await expect(prevQuestionBtn).not.toBeEnabled();
      }
      for (let j = 0; j < 5; j++) {
        // 4 answers
        await page.getByTestId('exam-answer-label-' + String(j)).check();
      }
      await expect(exitButton).toBeVisible();
      await expect(exitButton).toBeEnabled();
      if (i < 5) {
        await expect(finishExamBtn).not.toBeVisible();
        await expect(nextBtn).toBeVisible();
        await nextBtn.click();
      } else {
        await expect(finishExamBtn).toBeEnabled();
        await expect(finishExamBtn).toBeVisible();
        await expect(nextBtn).not.toBeVisible();
      }
    }
  });

  test('The page has correct navigation back flow', async () => {
    const headerTitle = page.getByTestId('exam-show-title');
    await expect(headerTitle).toBeVisible();
    await expect(headerTitle).toContainText(
      intro['foundational-c-sharp-with-microsoft'].blocks[
        'foundational-c-sharp-with-microsoft-certification-exam'
      ].title
    );
    await expect(page.getByTestId('exam-show-question-time')).toContainText(
      translations.learn.exam.time.split(':')[0]
    );

Review comment (suggestion):
Similar to https://github.com/freeCodeCamp/freeCodeCamp/pull/51798#discussion_r1356508858, we could query the radio button instead of having to construct the test ID.

Also, we don't need to start a new loop of the quiz answer. We can just use the same loop to assert the display of the content and the user interaction (see my comment above). 

Code after:

      await expect(page.getByTestId('exam-show-question-time')).toContainText(
        translations.learn.exam.time.split(':')[0]
      );
      await expect(
        page.getByText(`Question ${i + 1} of ${QUESTION_COUNT}`)
      ).toBeVisible();
      await expect(prevQuestionBtn).toBeVisible();
      if (i != 0) {
        await expect(prevQuestionBtn).toBeEnabled();
      } else {
        await expect(prevQuestionBtn).not.toBeEnabled();
      }
      await page.getByRole('radio').first().check({ force: true });
      await expect(exitButton).toBeVisible();
      await expect(exitButton).toBeEnabled();
      if (i < QUESTION_COUNT - 1) {
        await expect(finishExamBtn).not.toBeVisible();
        await expect(nextBtn).toBeVisible();
        await nextBtn.click();
      } else {
        await expect(finishExamBtn).toBeEnabled();
        await expect(finishExamBtn).toBeVisible();
        await expect(nextBtn).not.toBeVisible();
      }
    }
  });

  test('The page has correct navigation back flow', async ({ page }) => {
    const headerTitle = page.getByTestId('exam-show-title');
    await expect(headerTitle).toBeVisible();
    await expect(headerTitle).toContainText(
      intro['foundational-c-sharp-with-microsoft'].blocks[
        'foundational-c-sharp-with-microsoft-certification-exam'
      ].title
    );
    await expect(page.getByTestId('exam-show-question-time')).toContainText(
      translations.learn.exam.time.split(':')[0]
    );

    await page.getByRole('radio').first().check({ force: true });
    await page
      .getByRole('button', { name: translations.buttons['next-question'] })
      .click();
    await expect(page.getByText('Question 2 of 5')).toBeVisible();
    await page
      .getByRole('button', { name: translations.buttons['previous-question'] })
      .click();
    await expect(page.getByText('Question 1 of 5')).toBeVisible();
  });
});