forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail-settings.spec.ts
170 lines (142 loc) · 5.01 KB
/
email-settings.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
const settingsPageElement = {
emailVerificationAlert: 'email-verification-alert',
emailVerificationLink: 'email-verification-link',
flashMessageAlert: 'flash-message',
newEmailValidation: 'new-email-validation',
confirmEmailValidation: 'confirm-email-validation'
} as const;
const originalEmail = '[email protected]';
const newEmail = '[email protected]';
test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto('/settings');
});
test.describe('Email Settings', () => {
test('should display the content correctly', async ({ page }) => {
await expect(
page.getByRole('heading', { name: translations.settings.email.heading })
).toBeVisible();
await expect(page.getByText(originalEmail)).toBeVisible();
await expect(
page.getByRole('button', {
name: `${translations.buttons.save} ${translations.settings.email.heading}`
})
).toBeDisabled();
await expect(
page
.getByRole('group', { name: translations.settings.email.weekly })
.locator('legend')
).toBeVisible();
await expect(
page.getByRole('button', {
name: translations.buttons['yes-please']
})
).toHaveAttribute('aria-pressed', 'false');
await expect(
page.getByRole('button', {
name: translations.buttons['no-thanks']
})
).toHaveAttribute('aria-pressed', 'true');
});
test('should display email verification alert after email update', async ({
page
}) => {
const flashMessageAlert = page.getByTestId(
settingsPageElement.flashMessageAlert
);
// Need exact match as there are "New email" and "Confirm new email" labels
await page
.getByLabel(translations.settings.email.new, { exact: true })
.fill(newEmail);
await page.getByLabel(translations.settings.email.confirm).fill(newEmail);
await page
.getByRole('button', {
name: `${translations.buttons.save} ${translations.settings.email.heading}`
})
.click();
await expect(flashMessageAlert).toBeVisible();
await expect(flashMessageAlert).toContainText(
'Check your email and click the link we sent you to confirm your new email address.'
);
await page.reload();
await expect(
page.getByTestId(settingsPageElement.emailVerificationAlert)
).toBeVisible();
const emailVerificationLink = page.getByTestId(
settingsPageElement.emailVerificationLink
);
await expect(emailVerificationLink).toHaveAttribute(
'href',
'/update-email'
);
});
test('should show the user error messages if the input is invalid', async ({
page
}) => {
const newEmailInput = page.getByLabel(translations.settings.email.new, {
exact: true
});
const confirmEmailInput = page.getByLabel(
translations.settings.email.confirm
);
const confirmValidation = page.getByTestId(
settingsPageElement.confirmEmailValidation
);
const newEmailValidation = page.getByTestId(
settingsPageElement.newEmailValidation
);
await newEmailInput.fill(newEmail);
await confirmEmailInput.fill(originalEmail);
await expect(confirmValidation).toBeVisible();
await expect(confirmValidation).toContainText(
translations.validation['email-mismatch']
);
await newEmailInput.fill(originalEmail);
await expect(newEmailValidation).toBeVisible();
await expect(newEmailValidation).toContainText(
translations.validation['same-email']
);
});
test('should toggle email subscription correctly', async ({ page }) => {
const yesPleaseButton = page.getByRole('button', {
name: translations.buttons['yes-please']
});
const noThanksButton = page.getByRole('button', {
name: translations.buttons['no-thanks']
});
await yesPleaseButton.click();
await expect(yesPleaseButton).toHaveAttribute('aria-pressed', 'true');
await expect(noThanksButton).toHaveAttribute('aria-pressed', 'false');
await noThanksButton.click();
await expect(yesPleaseButton).toHaveAttribute('aria-pressed', 'false');
await expect(noThanksButton).toHaveAttribute('aria-pressed', 'true');
});
test('should display flash message when email subscription is toggled', async ({
page
}) => {
await page
.getByRole('button', {
name: translations.buttons['yes-please']
})
.click();
await expect(
page.getByTestId(settingsPageElement.flashMessageAlert)
).toContainText("We have updated your subscription to Quincy's email");
// Undo subscription change
await Promise.all([
page.waitForResponse(
response =>
response.url().includes('update-my-quincy-email') &&
response.status() === 200
),
page
.getByRole('button', {
name: translations.buttons['no-thanks']
})
.click()
]);
});
});