forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz-challenge.spec.ts
135 lines (107 loc) · 4.31 KB
/
quiz-challenge.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
import { test, expect } from '@playwright/test';
test.describe('Quiz challenge', () => {
test.skip(
() => process.env.SHOW_UPCOMING_CHANGES !== 'true',
'The FSD superblock is not available if SHOW_UPCOMING_CHANGES is false'
);
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/full-stack-developer/quiz-basic-html/quiz-basic-html'
);
});
test('should display a list of unanswered questions if user has not answered all questions', async ({
page
}) => {
// Wait for the page content to render
await expect(page.getByRole('radiogroup')).toHaveCount(20);
for (let i = 0; i < 15; i++) {
const radioGroups = await page.getByRole('radiogroup').all();
await radioGroups[i].getByRole('radio').first().click();
}
await page.getByRole('button', { name: 'Finish the quiz' }).click();
await expect(
page.getByText(
'The following questions are unanswered: 16, 17, 18, 19, 20. You must answer all questions.'
)
).toBeVisible();
});
test('should show a confirm finish modal when user clicks the finish button, and disable the quiz once they have confirmed', async ({
page
}) => {
// Wait for the page content to render
await expect(page.getByRole('radiogroup')).toHaveCount(20);
const radioGroups = await page.getByRole('radiogroup').all();
for (const radioGroup of radioGroups) {
await radioGroup.getByRole('radio').first().click();
}
await page.getByRole('button', { name: 'Finish the quiz' }).click();
await expect(
page.getByRole('dialog', { name: 'Finish Quiz' })
).toBeVisible();
await page.getByRole('button', { name: 'Yes, I am finished' }).click();
await expect(
page.getByRole('dialog', { name: 'Finish Quiz' })
).toBeHidden();
const radios = await page.getByRole('radio').all();
for (const radio of radios) {
await expect(radio).toBeDisabled();
}
});
test('should show a confirm exit modal when user clicks on the exit button', async ({
page
}) => {
// Wait for the page content to render
await expect(page.getByRole('radiogroup')).toHaveCount(20);
await page.getByRole('button', { name: 'Exit the quiz' }).click();
// The navigation should be blocked, the user should stay on the same page
await expect(page).toHaveURL(
'/learn/front-end-development/quiz-basic-html/quiz-basic-html'
);
await expect(page.getByRole('dialog')).toBeVisible();
await expect(page.getByRole('dialog', { name: 'Exit Quiz' })).toBeVisible();
await page
.getByRole('button', { name: 'No, I would like to continue the quiz' })
.click();
await expect(page.getByRole('dialog', { name: 'Exit Quiz' })).toBeHidden();
await page.getByRole('button', { name: 'Exit the quiz' }).click();
await expect(page.getByRole('dialog', { name: 'Exit Quiz' })).toBeVisible();
await page
.getByRole('button', { name: 'Yes, I want to leave the quiz' })
.click();
await page.waitForURL('/learn/front-end-development/#quiz-basic-html');
await expect(
page.getByRole('heading', { level: 3, name: 'Basic HTML Quiz' })
).toBeVisible();
});
test('should show a confirm exit modal when user clicks on a link', async ({
page
}) => {
// Wait for the page content to render
await expect(page.getByRole('radiogroup')).toHaveCount(20);
await page.getByRole('link', { name: 'Basic HTML Quiz' }).click();
await expect(page.getByRole('dialog', { name: 'Exit Quiz' })).toBeVisible();
await page
.getByRole('button', { name: 'Yes, I want to leave the quiz' })
.click();
await page.waitForURL('/learn/front-end-development/#quiz-basic-html');
await expect(
page.getByRole('heading', { level: 3, name: 'Basic HTML Quiz' })
).toBeVisible();
});
test('should show a confirm exit modal when user closes the page', async ({
page,
browserName
}) => {
test.skip(
browserName === 'webkit' || browserName === 'chromium',
'This test is flaky on Chromium and WebKit'
);
// Wait for the page content to render
await expect(page.getByRole('radiogroup')).toHaveCount(20);
page.on('dialog', async dialog => {
expect(dialog.type()).toBe('beforeunload');
await dialog.dismiss();
});
await page.close({ runBeforeUnload: true });
});
});