forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnot-found.spec.ts
82 lines (68 loc) · 2.63 KB
/
not-found.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
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import words from '../client/i18n/locales/english/motivation.json';
const pageElements = {
notFoundImage: 'not-found-image',
notFoundHeading: 'not-found-heading',
heresQuoteParagraph: 'heres-quote-paragraph',
quoteWrapper: 'quote-wrapper',
quoteContent: 'quote-content',
authorName: 'author-name',
viewCurriculumBtn: 'view-curriculum-btn'
};
test.beforeEach(async ({ page }) => {
await page.goto('/404');
});
test.describe('Not-Found Page Tests', () => {
test('should display correct page title', async ({ page }) => {
await expect(page).toHaveTitle(
`${translations[404]['page-not-found']} | freeCodeCamp.org`
);
});
test('should display 404 image', async ({ page }) => {
const notFoundImage = page.getByTestId(pageElements.notFoundImage);
await expect(notFoundImage).toBeVisible();
});
test('should display not found heading', async ({ page }) => {
const notFoundHeading = page.getByTestId(pageElements.notFoundHeading);
await expect(notFoundHeading).toHaveText(
`${translations[404]['page-not-found']}.`
);
});
test('should display heres a quote message', async ({ page }) => {
const heresQuoteParagraph = page.getByTestId(
pageElements.heresQuoteParagraph
);
await expect(heresQuoteParagraph).toHaveText(
translations[404]['heres-a-quote']
);
});
test('should load a quote component', async ({ page }) => {
const quoteWrapper = page.getByTestId(pageElements.quoteWrapper);
const quoteContent = page.getByTestId(pageElements.quoteContent);
const authorName = page.getByTestId(pageElements.authorName);
await expect(quoteWrapper).toBeVisible();
expect(quoteContent).not.toBeNull();
expect(authorName).not.toBeNull();
});
test('should display a random quote', async ({ page }) => {
const shownQuote = await page
.getByTestId(pageElements.quoteContent)
.textContent();
const shownAuthorText = await page
.getByTestId(pageElements.authorName)
.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);
});
test('should display view curriculum link', async ({ page }) => {
await expect(
page.getByRole('link', {
name: translations.buttons['view-curriculum']
})
).toBeVisible();
});
});