Files
freeCodeCamp/e2e/update-email.spec.ts
Huyen Nguyen f8fa98ec3a fix(client): put /update-email behind authentication (#54128)
Co-authored-by: Just-A-Pixel <Raj.Anand0511@gmail.com>
Co-authored-by: sembauke <semboot699@gmail.com>
2024-07-02 17:08:52 +02:00

76 lines
2.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
test.describe('The update-email page when the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeEach(async ({ page }) => {
await page.goto('/update-email');
});
test('should display the content correctly', async ({ page }) => {
await expect(page).toHaveTitle(
'Update your email address | freeCodeCamp.org'
);
await expect(
page.getByRole('heading', { name: 'Update your email address here' })
).toBeVisible();
const form = page.getByTestId('update-email-form');
const emailInput = page.getByLabel('Email');
const submitButton = page.getByRole('button', { name: 'Update my Email' });
await expect(form).toBeVisible();
await expect(emailInput).toBeVisible();
await expect(emailInput).toHaveAttribute('type', 'email');
await expect(emailInput).toHaveAttribute(
'placeholder',
'camperbot@example.com'
);
await expect(submitButton).toBeVisible();
await expect(submitButton).toHaveAttribute('type', 'submit');
const signOutButton = page.getByRole('link', { name: 'Sign out' });
await expect(signOutButton).toBeVisible();
await expect(signOutButton).toHaveAttribute('href', '/signout');
});
test('should enable the submit button if the email input is valid', async ({
page
}) => {
const emailInput = page.getByLabel(translations.misc.email);
const submitButton = page.getByRole('button', { name: 'Update my Email' });
await expect(submitButton).toBeDisabled();
await emailInput.fill('123');
await expect(submitButton).toBeDisabled();
await emailInput.fill('123@gmail.com');
await expect(submitButton).toBeEnabled();
});
});
test.describe('The update-email page when the user is not signed in', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test.beforeEach(async ({ page }) => {
await page.goto('/update-email');
});
test('should sign the user in and redirect them to /learn', async ({
page,
browserName
}) => {
// The signin step involves multiple navigations, which results a network error in Firefox.
// The error is harmless but Playwright doesn't suppress it, causing the test to fail.
// Ref: https://github.com/microsoft/playwright/issues/20749
test.skip(browserName === 'firefox');
await page.waitForURL(/\/learn\/?/);
await expect(
page.getByRole('heading', { name: 'Welcome back, Full Stack User' })
).toBeVisible();
});
});