forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.spec.ts
195 lines (155 loc) · 6.68 KB
/
editor.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
import { expect, test } from '@playwright/test';
import { clearEditor, focusEditor } from './utils/editor';
test.describe('Editor Component', () => {
test('should allow the user to insert text', async ({
page,
isMobile,
browserName
}) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
await focusEditor({ page, isMobile, browserName });
await page.keyboard.insertText('<h2>FreeCodeCamp</h2>');
const text = page.getByText('<h2>FreeCodeCamp</h2>');
await expect(text).toBeVisible();
});
});
test.describe('Python Terminal', () => {
test('should display error message when the user enters invalid code', async ({
page,
isMobile,
browserName
}) => {
await page.goto(
'learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-2'
);
await focusEditor({ page, isMobile, browserName });
await clearEditor({ page, browserName });
// Then enter invalid code
await page.keyboard.insertText('def');
const preview = page.getByTestId('preview-pane');
// While it's displayed on multiple lines, the string itself has no newlines, hence:
const error = `Traceback (most recent call last): File "main.py", line 1 def ^SyntaxError: invalid syntax`;
// It shouldn't take this long, but the Python worker can be slow to respond.
await expect(preview).toContainText(error, { timeout: 15000 });
});
});
test.describe('Editor theme if the system theme is dark', () => {
test.use({ colorScheme: 'dark' });
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
});
test.describe('If the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test('should be in dark mode if the user selected theme is dark', async ({
page
}) => {
// Open the nav menu and toggle the theme
await page.getByRole('button', { name: 'Menu' }).click();
const toggle = page.getByRole('button', { name: 'Night Mode' });
await expect(toggle).toBeVisible();
const isDarkMode = await toggle.getAttribute('aria-pressed');
if (isDarkMode === 'false') {
const listItem = page.getByRole('listitem').filter({ has: toggle });
// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
// Ensure that the action is completed before checking the editor.
await expect(
page.getByText('We have updated your theme')
).toBeVisible();
}
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs-dark/);
});
test('should be in light mode if the user selected theme is light', async ({
page
}) => {
// Open the nav menu and toggle the theme
await page.getByRole('button', { name: 'Menu' }).click();
const toggle = page.getByRole('button', { name: 'Night Mode' });
await expect(toggle).toBeVisible();
const isDarkMode = await toggle.getAttribute('aria-pressed');
if (isDarkMode === 'true') {
const listItem = page.getByRole('listitem').filter({ has: toggle });
// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
// Ensure that the action is completed before checking the editor.
await expect(
page.getByText('We have updated your theme')
).toBeVisible();
}
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs(?!\w)/);
});
});
test.describe('If the user is signed out', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('should be in dark mode', async ({ page }) => {
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs-dark/);
});
});
});
test.describe('Editor theme if the system theme is light', () => {
test.use({ colorScheme: 'light' });
test.beforeEach(async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
);
});
test.describe('If the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test('should be in dark mode if the user selected theme is dark', async ({
page
}) => {
await page.getByRole('button', { name: 'Menu' }).click();
const toggle = page.getByRole('button', { name: 'Night Mode' });
await expect(toggle).toBeVisible();
const isDarkMode = await toggle.getAttribute('aria-pressed');
if (isDarkMode === 'false') {
const listItem = page.getByRole('listitem').filter({ has: toggle });
// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
// Ensure that the action is completed before checking the editor.
await expect(
page.getByText('We have updated your theme')
).toBeVisible();
}
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs-dark/);
});
test('should be in light mode if the user selected theme is light', async ({
page
}) => {
await page.getByRole('button', { name: 'Menu' }).click();
const toggle = page.getByRole('button', { name: 'Night Mode' });
await expect(toggle).toBeVisible();
const isDarkMode = await toggle.getAttribute('aria-pressed');
if (isDarkMode === 'true') {
const listItem = page.getByRole('listitem').filter({ has: toggle });
// The button's click event is intercepted by the `li`,
// so we need to click on the `li` to trigger the theme change action.
await listItem.click();
// Ensure that the action is completed before checking the editor.
await expect(
page.getByText('We have updated your theme')
).toBeVisible();
}
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs(?!\w)/);
});
});
test.describe('If the user is signed out', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('should be in light mode', async ({ page }) => {
const editor = page.locator("div[role='code'].monaco-editor");
await expect(editor).toHaveClass(/vs(?!\w)/);
});
});
});