forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion-modal.spec.ts
188 lines (172 loc) · 6.17 KB
/
completion-modal.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
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { authedRequest } from './utils/request';
const nextChallengeURL =
'/learn/data-analysis-with-python/data-analysis-with-python-projects/demographic-data-analyzer';
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/data-analysis-with-python/data-analysis-with-python-projects/mean-variance-standard-deviation-calculator'
);
await page.getByLabel('Solution Link').fill('https://example.com');
await page
.getByRole('button', { name: "I've completed this challenge" })
.click();
});
test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('should render the modal correctly', async ({ page }) => {
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
await expect(page.getByTestId('completion-success-icon')).toBeVisible();
await expect(page.getByTestId('progress-bar-container')).toBeVisible();
await expect(
page.getByRole('link', { name: translations.learn['sign-in-save'] })
).toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons['go-to-next'] })
).toBeVisible();
});
test('should close the modal after user click on close', async ({ page }) => {
await page.getByRole('button', { name: 'close' }).click();
await expect(page.getByTestId('completion-success-icon')).not.toBeVisible();
});
test('should close the modal after user presses escape', async ({ page }) => {
await expect(page.getByRole('dialog')).toBeVisible();
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).not.toBeVisible();
});
test('should display the text of go to next challenge button accordingly based on device type', async ({
page,
isMobile,
browserName
}) => {
if (isMobile) {
await expect(
page.getByRole('button', {
name: 'Go to next challenge',
exact: true
})
).toBeVisible();
} else if (browserName === 'webkit') {
await expect(
page.getByRole('button', {
name: 'Go to next challenge (Command + Enter)'
})
).toBeVisible();
} else {
await expect(
page.getByRole('button', {
name: 'Go to next challenge (Ctrl + Enter)'
})
).toBeVisible();
}
});
test('should redirect to /learn after sign in', async ({ page }) => {
await page
.getByRole('link', { name: translations.learn['sign-in-save'] })
.click();
await expect(page).toHaveURL(/.*\/learn\/?$/);
});
test('should redirect to next challenge', async ({ page }) => {
await page
.getByRole('button', { name: translations.buttons['go-to-next'] })
.click();
await expect(page).toHaveURL(nextChallengeURL);
});
});
test.describe('Challenge Completion Modal Tests (Signed In)', () => {
test('should render the modal correctly', async ({ page }) => {
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
await expect(page.getByTestId('completion-success-icon')).toBeVisible();
await expect(page.getByTestId('progress-bar-container')).toBeVisible();
await expect(
page.getByRole('link', { name: translations.learn['sign-in-save'] })
).not.toBeVisible();
await expect(
page.getByRole('button', { name: translations.buttons['submit-and-go'] })
).toBeVisible();
});
test('should close the modal after user click on close', async ({ page }) => {
await page.getByRole('button', { name: 'close' }).click();
await expect(page.getByTestId('completion-success-icon')).not.toBeVisible();
});
test('should close the modal after user presses escape while having keyboard shortcuts disabled', async ({
page,
request
}) => {
await authedRequest({
request,
endpoint: 'update-my-keyboard-shortcuts',
method: 'put',
data: {
keyboardShortcuts: false
}
});
await expect(page.getByRole('dialog')).toBeVisible();
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).not.toBeVisible();
});
test('should close the modal after user presses escape while having keyboard shortcuts enabled', async ({
page,
request
}) => {
await authedRequest({
request,
endpoint: 'update-my-keyboard-shortcuts',
method: 'put',
data: {
keyboardShortcuts: true
}
});
await expect(page.getByRole('dialog')).toBeVisible();
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).toBeVisible();
});
test('should display the text of go to next challenge button accordingly based on device type', async ({
page,
isMobile,
browserName
}) => {
if (isMobile) {
await expect(
page.getByRole('button', {
name: 'Submit and go to next challenge',
exact: true
})
).toBeVisible();
} else if (browserName === 'webkit') {
await expect(
page.getByRole('button', {
name: 'Submit and go to next challenge (Command + Enter)'
})
).toBeVisible();
} else {
await expect(
page.getByRole('button', {
name: 'Submit and go to next challenge (Ctrl + Enter)'
})
).toBeVisible();
}
});
test('should submit and go to the next challenge when the user clicks the submit button', async ({
page
}) => {
await page
.getByRole('button', { name: translations.buttons['submit-and-go'] })
.click();
await expect(page).toHaveURL(nextChallengeURL);
});
test('should submit and go to the next challenge when the user presses Ctrl + Enter', async ({
page
}) => {
await page.keyboard.press('Control+Enter');
await expect(page).toHaveURL(nextChallengeURL);
});
test('should submit and go to the next challenge when the user presses Command + Enter', async ({
page
}) => {
await page.keyboard.press('Meta+Enter');
await expect(page).toHaveURL(nextChallengeURL);
});
});