|
| 1 | +/** |
| 2 | + * Tests for code editing functionality and AST tool interaction. |
| 3 | + */ |
| 4 | +import test, { expect } from "@playwright/test"; |
| 5 | + |
| 6 | +/** |
| 7 | + * This test verifies that: |
| 8 | + * - Users can edit code in the editor |
| 9 | + * - The AST updates in response to code changes |
| 10 | + * - ESQuery selectors correctly highlight matching code and AST nodes |
| 11 | + * - AST node expansion functionality works properly |
| 12 | + */ |
| 13 | +test(`should change code, then highlight code and AST nodes matching ESQuery selector`, async ({ |
| 14 | + page, |
| 15 | +}) => { |
| 16 | + await page.goto("/"); |
| 17 | + |
| 18 | + // focus code editor textbox |
| 19 | + await page |
| 20 | + .getByRole("region", { name: "Code Editor Panel" }) |
| 21 | + .getByRole("textbox") |
| 22 | + .nth(1) |
| 23 | + .click(); |
| 24 | + |
| 25 | + // delete the default code |
| 26 | + await page.keyboard.press("ControlOrMeta+KeyA"); |
| 27 | + await page.keyboard.press("Backspace"); |
| 28 | + |
| 29 | + // add new code |
| 30 | + await page.keyboard.type("console.log('Hello, World!');"); |
| 31 | + |
| 32 | + // add an ESQuery selector |
| 33 | + await page.getByRole("textbox", { name: "ESQuery Selector" }).click(); |
| 34 | + await page.keyboard.type("CallExpression"); |
| 35 | + |
| 36 | + // wait for the debounced update of the AST to happen |
| 37 | + await expect( |
| 38 | + page |
| 39 | + .getByRole("listitem") |
| 40 | + .filter({ hasText: "end" }) |
| 41 | + .filter({ hasText: "29" }), |
| 42 | + ).toBeVisible(); |
| 43 | + |
| 44 | + // expand AST nodes for ExpressionStatement and CallExpression |
| 45 | + await page |
| 46 | + .getByRole("region", { name: "Program" }) |
| 47 | + .getByRole("listitem") |
| 48 | + .filter({ hasText: "bodyArray[1 element]" }) |
| 49 | + .getByLabel("Toggle Property") |
| 50 | + .click(); |
| 51 | + await page.getByRole("button", { name: "ExpressionStatement" }).click(); |
| 52 | + await page |
| 53 | + .getByRole("region", { name: "Program" }) |
| 54 | + .getByRole("listitem") |
| 55 | + .filter({ hasText: "expressionCallExpression{type" }) |
| 56 | + .getByLabel("Toggle Property") |
| 57 | + .click(); |
| 58 | +}); |
0 commit comments