forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn.spec.ts
73 lines (56 loc) · 2.19 KB
/
learn.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 words from '../client/i18n/locales/english/motivation.json';
test.describe('Learn - Unauthenticated user', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('the page should render correctly', async ({ page }) => {
await page.goto('/learn');
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);
await expect(
page.getByRole('heading', {
level: 1,
name: "Welcome to freeCodeCamp's curriculum."
})
).toBeVisible();
// Advice for new learners
const learnReadThisSection = page.getByTestId('learn-read-this-section');
await expect(learnReadThisSection).toBeVisible();
const learnReadThisSectionHeading = page.getByTestId(
'learn-read-this-heading'
);
await expect(learnReadThisSectionHeading).toBeVisible();
const learnReadThisSectionParagraphs =
page.getByTestId('learn-read-this-p');
await expect(learnReadThisSectionParagraphs).toHaveCount(10);
for (const paragraph of await learnReadThisSectionParagraphs.all()) {
await expect(paragraph).toBeVisible();
}
await expect(
page.getByRole('link', { name: 'Sign in to save your progress' })
).toBeVisible();
});
});
test.describe('Learn - Authenticated user)', () => {
test('the page should render correctly', async ({ page }) => {
await page.goto('/learn');
await expect(page).toHaveTitle(
'Learn to Code — For Free — Coding Courses for Busy People'
);
await expect(
page.getByRole('heading', {
level: 1,
name: 'Welcome back, Full Stack User.'
})
).toBeVisible();
const shownQuote = await page.getByTestId('random-quote').textContent();
const shownAuthorText = await page
.getByTestId('random-author')
.textContent();
const shownAuthor = shownAuthorText?.replace('- ', '');
const allMotivationalQuotes = words.motivationalQuotes.map(mq => mq.quote);
const allAuthors = words.motivationalQuotes.map(mq => mq.author);
expect(allMotivationalQuotes).toContain(shownQuote);
expect(allAuthors).toContain(shownAuthor);
});
});