forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlower-jaw.spec.ts
245 lines (208 loc) · 7.3 KB
/
lower-jaw.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
import { test, expect } from '@playwright/test';
import { clearEditor, focusEditor, getEditors } from './utils/editor';
import { signout } from './utils/logout';
test('Check the initial states of submit button and "check your code" button', async ({
page
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const checkButton = page.getByTestId('lowerJaw-check-button');
const submitButton = page.getByTestId('lowerJaw-submit-button');
const checkButtonState = await checkButton.getAttribute('aria-hidden');
const submitButtonState = await submitButton.getAttribute('aria-hidden');
expect(checkButtonState).toBe(null);
expect(submitButtonState).toBe('true');
});
test('Click on the "check your code" button', async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
await checkButton.click();
const failing = page.getByTestId('lowerJaw-failing-test-feedback');
const hint = page.getByTestId('lowerJaw-failing-hint');
await expect(failing).toBeVisible();
await expect(hint).toBeVisible();
});
test('Resets the lower jaw when prompted', async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
await checkButton.click();
const failing = page.getByTestId('lowerJaw-failing-test-feedback');
const hint = page.getByTestId('lowerJaw-failing-hint');
await expect(failing).toBeVisible();
await expect(hint).toBeVisible();
await page.getByRole('button', { name: 'Reset' }).click();
await expect(
page.getByRole('dialog', { name: 'Reset this lesson?' })
).toBeVisible();
await page.getByRole('button', { name: 'Reset this lesson' }).click();
await expect(failing).not.toBeVisible();
await expect(hint).not.toBeVisible();
await expect(checkButton).toBeVisible();
});
test('Checks hotkeys when instruction is focused', async ({
page,
browserName
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const editor = getEditors(page);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
const description = page.locator('#description');
await editor.fill(
'<h2>Cat Photos</h2>\n<p>Everyone loves cute cats online!</p>'
);
await description.click();
if (browserName === 'webkit') {
await page.keyboard.press('Meta+Enter');
} else {
await page.keyboard.press('Control+Enter');
}
await expect(checkButton).not.toBeFocused();
});
test('Focuses on the submit button after tests passed', async ({
page,
browserName,
isMobile
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const editor = getEditors(page);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
const submitButton = page.getByRole('button', {
name: 'Submit and go to next challenge'
});
await focusEditor({ page, isMobile });
await clearEditor({ page, browserName });
await editor.fill(
'<h2>Cat Photos</h2>\n<p>Everyone loves cute cats online!</p>'
);
await checkButton.click();
await expect(submitButton).toBeFocused();
});
test('Prompts unauthenticated user to sign in to save progress', async ({
page,
browserName,
isMobile
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
await signout(page);
await page.reload();
const editor = getEditors(page);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
const loginButton = page.getByRole('link', {
name: 'Sign in to save your progress'
});
await focusEditor({ page, isMobile });
await clearEditor({ page, browserName });
await editor.fill(
'<h2>Cat Photos</h2>\n<p>Everyone loves cute cats online!</p>'
);
await checkButton.click();
await expect(loginButton).toBeVisible();
await loginButton.click();
await page.goBack();
await expect(loginButton).not.toBeVisible();
});
test('Should render UI correctly', async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const codeCheckButton = page.getByRole('button', {
name: 'Check Your Code'
});
const lowerJawTips = page.getByTestId('failing-test-feedback');
await expect(codeCheckButton).toBeVisible();
await expect(lowerJawTips).toHaveCount(0);
});
test('Should display the text of the check code button accordingly based on device type and screen size', async ({
page,
isMobile,
browserName
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
if (isMobile) {
await expect(
page.getByRole('button', { name: 'Check Your Code', exact: true })
).toBeVisible();
} else if (browserName === 'webkit') {
await expect(
page.getByRole('button', { name: 'Check Your Code (Command + Enter)' })
).toBeVisible();
} else {
await expect(
page.getByRole('button', { name: 'Check Your Code (Ctrl + Enter)' })
).toBeVisible();
}
});
test('should display the text of submit and go to next challenge button accordingly based on device type', async ({
page,
isMobile,
browserName
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
const editor = getEditors(page);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
await focusEditor({ page, isMobile });
await clearEditor({ page, browserName });
await editor.fill(
'<h2>Cat Photos</h2>\n<p>Everyone loves cute cats online!</p>'
);
await checkButton.click();
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('Hint text should not contain placeholders `fcc-expected`', async ({
page,
isMobile,
browserName
}) => {
await page.goto(
'learn/2022/responsive-web-design/learn-css-transforms-by-building-a-penguin/step-4'
);
const editor = getEditors(page);
const checkButton = page.getByRole('button', { name: 'Check Your Code' });
await focusEditor({ page, isMobile });
await clearEditor({ page, browserName });
await editor.fill(
'body{background:linear-gradient(45deg, rgb(118, 201, 255), rgb(247, 255, 222));margin:0;padding:0;width:5%;height:100vh}'
);
await checkButton.click();
const failingHint = page.getByTestId('lowerJaw-failing-hint');
const hintDescriptionElement = failingHint.locator('.hint-description');
const hintDescription = hintDescriptionElement.locator('p');
await expect(hintDescription).toContainText(
'You should give body a width of 100%, but found 5%',
{ useInnerText: true }
);
});