forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-email.spec.ts
73 lines (60 loc) · 2.52 KB
/
update-email.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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.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',
);
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('[email protected]');
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();
});
});