-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathsketches_management.spec.ts
More file actions
160 lines (136 loc) · 5.16 KB
/
Copy pathsketches_management.spec.ts
File metadata and controls
160 lines (136 loc) · 5.16 KB
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
import type { Page } from '@playwright/test';
import { test, expect } from '../fixtures';
import { dismissCookieBanner } from '../helpers/cookie-banner';
import { createTestUser, loginAs, TestUser } from '../helpers/auth';
test.describe.serial('sketch lifecycle', () => {
let testUser: TestUser;
let page: Page;
let sketchName: string;
test.beforeAll(async ({ browser, request }) => {
testUser = await createTestUser(request);
// A single page shared across this describe.serial block (instead of the
// per-test `page` fixture) so each test below can build on the previous
// one's state (same sketch, still logged in).
page = await browser.newPage();
await page.addInitScript(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).__REDUX_DEVTOOLS_EXTENSION__ = () => {};
});
await page.goto('/login');
await dismissCookieBanner(page);
await loginAs(page, testUser);
});
test.afterAll(async () => {
await page.close();
});
const editor = () => page.locator('.editor-holder');
test('can save a sketch', async () => {
const initialCode = [
'function setup() {',
' createCanvas(400, 400);',
'}',
'',
'function draw() {',
' background(220);',
" console.log('initial log');",
' noLoop();',
'}'
].join('');
await editor().click();
await page.keyboard.press('ControlOrMeta+A');
await page.keyboard.type(initialCode, { delay: 5 });
await page.locator('#play-sketch').click({ force: true });
await expect(
page.locator('iframe[title="sketch preview"]')
).toHaveAttribute('src', /9002/, { timeout: 10_000 });
await expect(
page.locator('.preview-console__messages')
).toContainText('initial log', { timeout: 10_000 });
const name = await page
.locator('button.editable-input__label')
.textContent();
expect(name).toBeTruthy();
sketchName = name ?? '';
await editor().click();
await page.keyboard.press('Control+S');
await expect(page.getByText('Sketch saved.')).toBeVisible({
timeout: 10_000
});
});
test('can reopen and edit a saved sketch', async () => {
// Using page.goto() directly rather than the nav dropdown — the dropdown
// sometimes does not respond to clicks consistently.
await page.goto(`/${testUser.username}/sketches`);
await page.locator('table.sketches-table').getByText(sketchName).click();
// Confirm we're back on the right sketch
await expect(
page.locator('button.editable-input__label')
).toContainText(sketchName, { timeout: 10_000 });
const updatedCode = [
'function setup() {',
' createCanvas(400, 400);',
'}',
'',
'function draw() {',
' background(220);',
" console.log('updated log');",
' noLoop();',
'}'
].join('');
await editor().click();
await page.keyboard.press('ControlOrMeta+A');
await page.keyboard.type(updatedCode, { delay: 5 });
// Wait for the unsaved changes indicator to appear, then save the sketch.
await expect(
page.getByRole('img', { name: 'Sketch has unsaved changes' })
).toBeVisible();
await page.keyboard.press('Control+S');
await expect(page.getByText('Sketch saved.')).toBeVisible({
timeout: 10_000
});
});
test('can rename a sketch and the update persists', async () => {
await page.locator('button.editable-input__label').click();
await page.locator('input.editable-input__input').fill('renamed-sketch');
await page.locator('input.editable-input__input').press('Enter');
await expect(page.getByText('Sketch saved.')).toBeVisible({
timeout: 10_000
});
// Navigate away and come back via the sketches page
await page.goto(`/${testUser.username}/sketches`);
// Confirm renamed sketch appears in the table
await expect(
page.locator('table.sketches-table').getByText('renamed-sketch')
).toBeVisible({ timeout: 10_000 });
await page
.locator('table.sketches-table')
.getByText('renamed-sketch')
.click();
// Confirm the reopened sketch has actually loaded before playing it
await expect(
page.locator('button.editable-input__label')
).toContainText('renamed-sketch', { timeout: 10_000 });
// Run the renamed sketch and verify the edited code persisted
await page.locator('#play-sketch').click({ force: true });
await expect(
page.locator('iframe[title="sketch preview"]')
).toHaveAttribute('src', /9002/, { timeout: 10_000 });
await expect(
page.locator('.preview-console__messages')
).toContainText('updated log', { timeout: 10_000 });
});
test('can delete a sketch', async () => {
await page.goto(`/${testUser.username}/sketches`);
await expect(page.locator('table.sketches-table')).toBeVisible({
timeout: 10_000
});
page.on('dialog', (dialog) => dialog.accept());
await page
.locator('[aria-label="Toggle Open/Close Sketch Options"]')
.click();
await page.getByRole('menuitem').filter({ hasText: 'Delete' }).click();
await expect(page.locator('text=No Sketches')).toBeVisible({
timeout: 5_000
});
});
});