From 70a50fc70d2b0495a421f28d9413e73698d24615 Mon Sep 17 00:00:00 2001 From: Sem Bauke Date: Mon, 3 Jun 2024 10:13:12 +0200 Subject: [PATCH] feat: convert academic honstey tests to Playwright (#54855) Co-authored-by: Oliver Eyton-Williams --- .../src/components/settings/certification.tsx | 1 + .../e2e/default/settings/certifications.ts | 40 ---------- e2e/academic-honesty.spec.ts | 74 +++++++++++++++++++ e2e/settings.spec.ts | 42 ----------- 4 files changed, 75 insertions(+), 82 deletions(-) delete mode 100644 cypress/e2e/default/settings/certifications.ts create mode 100644 e2e/academic-honesty.spec.ts diff --git a/client/src/components/settings/certification.tsx b/client/src/components/settings/certification.tsx index 48e5e90475b..859d35a6697 100644 --- a/client/src/components/settings/certification.tsx +++ b/client/src/components/settings/certification.tsx @@ -399,6 +399,7 @@ function CertificationSettings(props: CertificationSettingsProps) { block={true} variant='primary' href={certLocation} + data-playwright-test-label={`btn-for-${certSlug}`} // This floating promise is acceptable // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick={clickHandler} diff --git a/cypress/e2e/default/settings/certifications.ts b/cypress/e2e/default/settings/certifications.ts deleted file mode 100644 index 6380937f5f9..00000000000 --- a/cypress/e2e/default/settings/certifications.ts +++ /dev/null @@ -1,40 +0,0 @@ -import '@testing-library/cypress/add-commands'; - -describe('Settings certifications area', () => { - describe('initially', () => { - before(() => { - cy.task('seed'); - cy.login(); - }); - - it('Should render the default settings page', () => { - cy.visit('/settings'); - cy.findAllByText('Claim Certification').should($btns => { - expect($btns).to.have.length(19); - }); - cy.findByText('Show Certification').should('not.exist'); - cy.contains(`I agree to freeCodeCamp's Academic Honesty Policy.`); - cy.contains('Claim Certification').click(); - cy.contains( - 'To claim a certification, you must first agree to our academic honesty policy' - ); - }); - }); - - describe('after isHonest', () => { - before(() => { - cy.task('seed'); - cy.login(); - }); - - it('Should update the user as they try to claim their certifications', () => { - cy.visit('/settings'); - cy.contains(`I agree to freeCodeCamp's Academic Honesty Policy.`).click(); - cy.contains('You have agreed to our Academic Honesty Policy.'); - cy.contains('Claim Certification').click(); - cy.contains( - 'It looks like you have not completed the necessary steps. Please complete the required projects to claim the Responsive Web Design Certification' - ); - }); - }); -}); diff --git a/e2e/academic-honesty.spec.ts b/e2e/academic-honesty.spec.ts new file mode 100644 index 00000000000..88a3f23a428 --- /dev/null +++ b/e2e/academic-honesty.spec.ts @@ -0,0 +1,74 @@ +import { execSync } from 'child_process'; +import { test, expect } from '@playwright/test'; +import translations from '../client/i18n/locales/english/translations.json'; + +test.describe('When the user has not accepted the Academic Honesty Policy', () => { + test.use({ storageState: 'playwright/.auth/development-user.json' }); + + test.beforeEach(() => { + execSync('node ./tools/scripts/seed/seed-demo-user'); + }); + + test('they should be able to accept it', async ({ page }) => { + await page.goto('/settings'); + await expect( + page.getByRole('heading', { + name: translations.settings.headings.honesty + }) + ).toBeVisible(); + await expect( + page.getByText(translations.settings.honesty.p1) + ).toBeVisible(); + await expect( + page.getByText(translations.settings.honesty.p2) + ).toBeVisible(); + await expect( + 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'); + }); +}); diff --git a/e2e/settings.spec.ts b/e2e/settings.spec.ts index 38feac89c80..104dae861f7 100644 --- a/e2e/settings.spec.ts +++ b/e2e/settings.spec.ts @@ -237,48 +237,6 @@ test.describe('Settings', () => { ).toBeVisible(); }); - test('Should validate Academy Honesty Settings', async ({ page }) => { - await expect( - page.getByRole('heading', { - name: translations.settings.headings.honesty - }) - ).toBeVisible(); - await expect( - page.getByTestId(settingsTestIds.camperIdentity) - ).toBeVisible(); - const saveButton = page.getByRole('button', { - name: translations.settings.headings['personal-info'] - }); - await expect(saveButton).toBeVisible(); - await saveButton.press('Enter'); - await expect( - page.getByText(translations.settings.honesty.p1) - ).toBeVisible(); - await expect( - page.getByText(translations.settings.honesty.p2) - ).toBeVisible(); - await expect( - 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(); - await expect( - page.getByText( - translations.settings.honesty.p7.replace( - settingsObject.supportEmailPlaceholder, - settingsObject.supportEmail - ) - ) - ).toBeVisible(); - }); - test('Should validate Certification Settings', async ({ page }) => { await expect( page.getByRole('heading', {