forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignout-modal.spec.ts
75 lines (61 loc) · 2.34 KB
/
signout-modal.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
74
75
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
test.describe('Signout Modal component', () => {
test('renders the modal correctly', async ({ page }) => {
await page.getByRole('button', { name: translations.buttons.menu }).click();
await page
.getByRole('button', { name: translations.buttons['sign-out'] })
.click();
await expect(
page.getByRole('dialog', { name: translations.signout.heading })
).toBeVisible();
await expect(page.getByText(translations.signout.p1)).toBeVisible();
await expect(page.getByText(translations.signout.p2)).toBeVisible();
await expect(
page.getByRole('button', { name: translations.signout.nevermind })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.signout.certain })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons.close })
).toBeVisible();
});
test('signs out and redirects to /learn after user confirms they want to sign out', async ({
page
}) => {
await page.getByRole('button', { name: translations.buttons.menu }).click();
await page
.getByRole('button', { name: translations.buttons['sign-out'] })
.click();
await expect(
page.getByRole('dialog', { name: translations.signout.heading })
).toBeVisible();
await page
.getByRole('button', { name: translations.signout.certain })
.click();
await expect(
page.getByRole('dialog', { name: translations.signout.heading })
).not.toBeVisible();
await expect(page).toHaveURL(/.*\/learn\/?$/);
});
test('closes modal after user cancels signing out', async ({ page }) => {
await page.getByRole('button', { name: translations.buttons.menu }).click();
await page
.getByRole('button', { name: translations.buttons['sign-out'] })
.click();
await expect(
page.getByRole('dialog', { name: translations.signout.heading })
).toBeVisible();
await page
.getByRole('button', { name: translations.signout.nevermind })
.click();
await expect(
page.getByRole('dialog', { name: translations.signout.heading })
).not.toBeVisible();
await expect(page).toHaveURL('/');
});
});