forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsubscribed.spec.ts
91 lines (73 loc) · 3.11 KB
/
unsubscribed.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import metaTags from '../client/i18n/locales/english/meta-tags.json';
test.describe('The unsubscribed page without unsubscribeId', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/unsubscribed');
});
test('The page renders with correct title', async ({ page }) => {
await expect(page).toHaveTitle(
`${metaTags['youre-unsubscribed']} | freeCodeCamp.org`
);
});
test('The page has correct main heading', async ({ page }) => {
const mainHeading = page.getByTestId('main-heading');
await expect(mainHeading).toBeVisible();
await expect(mainHeading).toContainText(translations.misc['unsubscribed']);
});
test('The page has correct motivation text', async ({ page }) => {
const motivationText = page.getByTestId('motivation-text');
await expect(motivationText).toBeVisible();
await expect(motivationText).toContainText(
translations.misc['keep-coding']
);
});
test('The page has no button to resubscribe', async ({ page }) => {
const resubscribeButton = page.getByRole('link', {
name: translations.buttons['resubscribe']
});
await expect(resubscribeButton).not.toBeVisible();
});
});
test.describe('The unsubscribed page with unsubscribeId', () => {
const encoded_url_text =
'?messages=success%5B0%5D%3DWe%2527ve%2520successfully%2520updated%2520your%2520email%2520preferences.%2520Thank%2520you%2520for%2520resubscribing.';
// This value is sourced from self/freeCodeCamp/tools/scripts/seed/certified-user-data.js
// The file certified-user-data.js is used to seed the database before running the tests.
const unsubscribeId = 'tBX8stC5jiustPBteF2mV';
test.beforeEach(async ({ page }) => {
await page.goto(`/unsubscribed/${unsubscribeId}`);
});
test('The page renders with correct title and other texts', async ({
page
}) => {
await expect(page).toHaveTitle(
`${metaTags['youre-unsubscribed']} | freeCodeCamp.org`
);
const mainHeading = page.getByTestId('main-heading');
await expect(mainHeading).toBeVisible();
await expect(mainHeading).toContainText(translations.misc['unsubscribed']);
const motivationText = page.getByTestId('motivation-text');
await expect(motivationText).toBeVisible();
await expect(motivationText).toContainText(
translations.misc['keep-coding']
);
});
test('Resubscribe and redirect to home with encoded text in the url', async ({
page
}) => {
const resubscribeButton = page.getByRole('link', {
name: translations.buttons['resubscribe']
});
await expect(resubscribeButton).toBeVisible();
const resubscribeButtonHref = await resubscribeButton.getAttribute('href');
expect(resubscribeButtonHref).toContain(`/resubscribe/${unsubscribeId}`);
await resubscribeButton.click();
await expect(page).toHaveURL(`${encoded_url_text}`);
await expect(
page.getByText(
"We've successfully updated your email preferences. Thank you for resubscribing."
)
).toBeVisible();
});
});