-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcode-editing-and-ast-interaction.test.ts
More file actions
133 lines (111 loc) · 3.6 KB
/
code-editing-and-ast-interaction.test.ts
File metadata and controls
133 lines (111 loc) · 3.6 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
/**
* @fileoverview Tests for code editing functionality and AST tool interaction.
*/
//-----------------------------------------------------------------------------
// Imports
//-----------------------------------------------------------------------------
import { expect, test } from "@playwright/test";
//-----------------------------------------------------------------------------
// Type Definitions
//-----------------------------------------------------------------------------
type HighlightSamplesState = {
intervalId: number;
samples: string[];
};
declare global {
interface Window {
__highlightSamples?: HighlightSamplesState;
}
}
//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------
/**
* This test verifies that:
* - Users can edit code in the editor
* - The AST updates in response to code changes
* - ESQuery selectors correctly highlight matching code and AST nodes
* - AST node expansion functionality works properly
*/
test(`should change code, then highlight code and AST nodes matching ESQuery selector`, async ({
page,
}) => {
await page.goto("/");
await page
.getByRole("textbox", { name: "Code Editor", exact: true })
.fill("console.log('Hello, World!');");
// add an ESQuery selector
await page.getByRole("textbox", { name: "ESQuery Selector" }).click();
await page.keyboard.type("CallExpression");
// wait for the debounced update of the AST to happen
await expect(
page
.getByRole("listitem")
.filter({ hasText: "end" })
.filter({ hasText: "29" }),
).toBeVisible();
// expand AST nodes for ExpressionStatement and CallExpression
await page
.getByRole("region", { name: "Program" })
.getByRole("listitem")
.filter({ hasText: "bodyArray[1 element]" })
.getByRole("button", { name: "Toggle Property" })
.click();
await page.getByRole("button", { name: "ExpressionStatement" }).click();
await page
.getByRole("region", { name: "Program" })
.getByRole("listitem")
.filter({ hasText: "expressionCallExpression{type" })
.getByRole("button", { name: "Toggle Property" })
.click();
});
test(`should keep ESQuery highlights aligned while typing before a matching literal`, async ({
page,
}) => {
await page.goto("/");
const codeEditor = page.getByRole("textbox", {
name: "Code Editor",
exact: true,
});
const highlight = codeEditor.locator(".bg-editorHighlightedRangeColor");
await codeEditor.fill("42;");
await page
.getByRole("textbox", { name: "ESQuery Selector" })
.fill("Literal");
await expect(highlight).toHaveText(["42"]);
await codeEditor.click();
await codeEditor.press("Home");
await page.evaluate(() => {
window.__highlightSamples = {
intervalId: window.setInterval(() => {
window.__highlightSamples?.samples.push(
Array.from(
document.querySelectorAll(
".bg-editorHighlightedRangeColor",
),
)
.map(node => node.textContent ?? "")
.join(""),
);
}, 20),
samples: [],
};
});
await codeEditor.pressSequentially("+ + + +", { delay: 50 });
const highlightSamples = await page.evaluate(() => {
const highlightSamples = window.__highlightSamples?.samples ?? [];
if (window.__highlightSamples) {
window.clearInterval(window.__highlightSamples.intervalId);
delete window.__highlightSamples;
}
return highlightSamples;
});
expect(highlightSamples.length).toBeGreaterThan(0);
expect(
highlightSamples.every(highlightText => highlightText === "42"),
).toBe(true);
await expect(highlight).toHaveText(["42"]);
});
test.describe("AST node expansion", () => {
// TODO
});