Repository: freeCodeCamp/freeCodeCamp
File: e2e/academic-honesty.spec.ts (TypeScript)

Code before:
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p6)
    ).toBeVisible();
    const agreeButton = page.getByRole('button', {
      name: translations.buttons['agree-honesty']
    });
    await expect(agreeButton).toBeVisible();
    await agreeButton.click();

    await expect(
      page.getByRole('button', {
        name: translations.buttons['accepted-honesty']
      })
    ).toBeVisible();
  });
});

test.describe('When the user has not accepted the honesty policy and tries to claim a certification', () => {
  test.use({ storageState: 'playwright/.auth/development-user.json' });

  test.beforeAll(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user');
  });

  test.afterAll(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
  });

  test('Should show an error message', async ({ page }) => {
    await page.goto('/settings#cert-responsive-web-design');
    await page.getByTestId('btn-for-responsive-web-design').click();

    await expect(page.getByTestId('flash-message')).toContainText(
      translations.flash['honest-first']
    );

    const agreeButton = page.getByRole('button', {
      name: translations.buttons['agree-honesty']
    });
    await agreeButton.click();

    await page.reload();


Review comment (suggestion):
This would make more sense as a test, not a block. i.e. the tests should read

* When the user has not accepted the Academic Honesty Policy
* they cannot claim a certification

To handle this, it's enough to make the `beforeAll` a `beforeEach` (I'll add a comment above)

Code after:
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p6)
    ).toBeVisible();
    const agreeButton = page.getByRole('button', {
      name: translations.buttons['agree-honesty']
    });
    await agreeButton.click();

    await expect(
      page.getByRole('button', {
        name: translations.buttons['accepted-honesty']
      })
    ).toBeVisible();
  });

  test('Should show an error message', async ({ page }) => {
    await page.goto('/settings#cert-responsive-web-design');
    await page.getByTestId('btn-for-responsive-web-design').click();

    await expect(page.getByTestId('flash-message')).toContainText(
      translations.flash['honest-first']
    );

    const agreeButton = page.getByRole('button', {
      name: translations.buttons['agree-honesty']
    });
    await agreeButton.click();

    await page.reload();

    await page.getByTestId('btn-for-responsive-web-design').click();

    await expect(page.getByTestId('flash-message')).toContainText(
      /It looks like you have not completed the necessary steps. Please complete the required projects to claim the Responsive Web Design Certification./
    );
  });

  test.afterAll(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
  });
});