forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.spec.ts
323 lines (299 loc) · 10.2 KB
/
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { alertToBeVisible } from './utils/alerts';
const settingsTestIds = {
settingsHeading: 'settings-heading',
portfolioItems: 'portfolio-items'
};
const settingsObject = {
email: '[email protected]',
userNamePlaceholder: '{{username}}',
certifiedUsername: 'certifieduser',
testEmail: '[email protected]',
pageTitle: `${translations.buttons.settings} | freeCodeCamp.org`,
private: 'Private',
public: 'Public',
supportEmail: '[email protected]',
supportEmailPlaceholder: '<0>{{email}}</0>'
};
const certifications = [
translations.certification.title['responsive-web-design'],
translations.certification.title[
'javascript-algorithms-and-data-structures-v8'
],
translations.certification.title['front-end-development-libraries'],
translations.certification.title['data-visualization'],
translations.certification.title['relational-database-v8'],
translations.certification.title['back-end-development-and-apis'],
translations.certification.title['quality-assurance-v7'],
translations.certification.title['scientific-computing-with-python-v7'],
translations.certification.title['data-analysis-with-python-v7'],
translations.certification.title['information-security-v7'],
translations.certification.title['machine-learning-with-python-v7'],
translations.certification.title['college-algebra-with-python-v8'],
translations.certification.title['foundational-c-sharp-with-microsoft']
];
const legacyCertifications = [
translations.certification.title['legacy-front-end'],
translations.certification.title['legacy-back-end'],
translations.certification.title['legacy-data-visualization'],
translations.certification.title['information-security-and-quality-assurance']
];
test.describe('Settings - Certified User', () => {
test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto('/settings');
});
test('Should render correctly', async ({ page }) => {
// Title
await expect(page).toHaveTitle(settingsObject.pageTitle);
// Header
const header = page.getByTestId(settingsTestIds.settingsHeading);
await expect(header).toBeVisible();
await expect(header).toContainText(
`${translations.settings.for.replace(
settingsObject.userNamePlaceholder,
settingsObject.certifiedUsername
)}`
);
// Privacy Settings
await expect(
page.getByRole('heading', {
name: translations.settings.headings.privacy
})
).toBeVisible();
await expect(page.getByText(translations.settings.privacy)).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-profile']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-profile'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-name']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-name'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-about']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-about'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-points']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-points'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-certs']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-certs'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-donations']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-donations'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-heatmap']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-heatmap'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-location']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-location'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-timeline']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-timeline'] })
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['my-portfolio']
})
.locator('p')
.filter({ hasText: translations.settings.labels['my-portfolio'] })
).toBeVisible();
await expect(
page.getByText(settingsObject.private, { exact: true })
).toHaveCount(10);
await expect(
page.getByText(settingsObject.public, { exact: true })
).toHaveCount(10);
const saveButton = page.getByRole('button', {
name: translations.settings.headings.privacy
});
await expect(saveButton).toBeVisible();
await expect(page.getByText(translations.settings.data)).toBeVisible();
const downloadButton = page.getByRole('link', {
name: translations.buttons['download-data']
});
await expect(downloadButton).toBeVisible();
await expect(page.locator('#legendsound')).toBeVisible();
await expect(
page.getByText(translations.settings['sound-volume'])
).toBeVisible();
await expect(
page
.getByRole('group', {
name: translations.settings.labels['keyboard-shortcuts']
})
.locator('p')
.first()
).toBeVisible();
await expect(
page.getByText(translations.settings['scrollbar-width'])
).toBeVisible();
// Certifications
await expect(
page.getByRole('heading', {
name: translations.settings.headings.certs,
exact: true
})
).toBeVisible();
for (let i = 0; i < certifications.length; i++) {
await expect(
page.getByRole('heading', {
name: certifications[i],
exact: true
})
).toBeVisible();
await expect(
page.getByRole('link', {
name: `${translations.buttons['show-cert']} ${certifications[i]}`
})
).toBeVisible();
}
// Legacy Certifications
await expect(
page.getByRole('heading', {
name: translations.settings.headings['legacy-certs'],
exact: true
})
).toBeVisible();
for (let i = 0; i < legacyCertifications.length; i++) {
await expect(
page.getByRole('heading', {
name: legacyCertifications[i],
exact: true
})
).toBeVisible();
await expect(
page.getByRole('link', {
name: `${translations.buttons['show-cert']} ${legacyCertifications[i]}`,
exact: true
})
).toBeVisible();
}
// Danger Zone
await expect(page.getByText('Danger Zone')).toBeVisible();
await expect(
page.getByText(
'Please be careful. Changes in this section are permanent.'
)
).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Reset all of my progress'
})
).toBeVisible();
await expect(
page.getByRole('button', {
name: 'Delete my account'
})
).toBeVisible();
});
});
// In order to claim the Full Stack cert, the user needs to complete 6 certs.
// Instead of simulating 6 cert claim flows,
// we use the data of Certified User but remove the Full Stack cert.
test.describe('Settings - Certified User without Full Stack Certification', () => {
test.beforeEach(async ({ page }) => {
execSync(
'node ./tools/scripts/seed/seed-demo-user --certified-user --set-false isFullStackCert'
);
await page.goto('/settings');
});
test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
test('should allow claiming Full Stack cert if the user has completed all requirements', async ({
page
}) => {
const claimButton = page.getByRole('button', {
name: 'Claim Certification Legacy Full Stack'
});
const showButton = page.getByRole('link', {
name: 'Show Certification Legacy Full Stack'
});
await expect(claimButton).toBeVisible();
await expect(claimButton).toBeEnabled();
await claimButton.click();
await alertToBeVisible(
page,
'@certifieduser, you have successfully claimed the Legacy Full Stack Certification! Congratulations on behalf of the freeCodeCamp.org team!'
);
await expect(claimButton).toBeHidden();
await expect(showButton).toBeVisible();
await expect(showButton).toHaveAttribute(
'href',
'/certification/certifieduser/full-stack'
);
});
});
test.describe('Settings - New User', () => {
test.use({ storageState: 'playwright/.auth/development-user.json' });
test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user');
await page.goto('/settings');
});
test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
test('should not allow claiming Full Stack cert if the user has not completed all the required certs', async ({
page
}) => {
const claimFullStackCertButton = page.getByRole('button', {
name: 'Claim Certification Legacy Full Stack'
});
const claimRwdCertButton = page.getByRole('button', {
name: 'Claim Certification Responsive Web Design'
});
// Buttons for normal certs are enabled
await expect(claimRwdCertButton).toBeVisible();
await expect(claimRwdCertButton).toBeEnabled();
// Button for full stack cert is disabled if the user hasn't claimed the required certs
await expect(claimFullStackCertButton).toBeVisible();
await expect(claimFullStackCertButton).toBeDisabled();
});
});