|
3 | 3 | */ |
4 | 4 | import { expect, test } from "@playwright/test"; |
5 | 5 |
|
| 6 | +type HighlightSamplesState = { |
| 7 | + intervalId: number; |
| 8 | + samples: string[]; |
| 9 | +}; |
| 10 | + |
| 11 | +declare global { |
| 12 | + interface Window { |
| 13 | + __highlightSamples?: HighlightSamplesState; |
| 14 | + } |
| 15 | +} |
| 16 | + |
6 | 17 | /** |
7 | 18 | * This test verifies that: |
8 | 19 | * - Users can edit code in the editor |
@@ -56,3 +67,63 @@ test(`should change code, then highlight code and AST nodes matching ESQuery sel |
56 | 67 | .getByRole("button", { name: "Toggle Property" }) |
57 | 68 | .click(); |
58 | 69 | }); |
| 70 | + |
| 71 | +test(`should keep ESQuery highlights aligned while typing before a matching literal`, async ({ |
| 72 | + page, |
| 73 | +}) => { |
| 74 | + await page.goto("/"); |
| 75 | + |
| 76 | + const codeEditor = page |
| 77 | + .getByRole("region", { name: "Code Editor Panel" }) |
| 78 | + .getByRole("textbox") |
| 79 | + .nth(1); |
| 80 | + const highlight = page.locator(".bg-editorHighlightedRangeColor"); |
| 81 | + |
| 82 | + await codeEditor.click(); |
| 83 | + await codeEditor.press("ControlOrMeta+KeyA"); |
| 84 | + await codeEditor.press("Backspace"); |
| 85 | + await codeEditor.pressSequentially("42;"); |
| 86 | + |
| 87 | + await page |
| 88 | + .getByRole("textbox", { name: "ESQuery Selector" }) |
| 89 | + .fill("Literal"); |
| 90 | + |
| 91 | + await expect(highlight).toHaveText("42"); |
| 92 | + |
| 93 | + await codeEditor.click(); |
| 94 | + await codeEditor.press("Home"); |
| 95 | + await page.evaluate(() => { |
| 96 | + window.__highlightSamples = { |
| 97 | + intervalId: window.setInterval(() => { |
| 98 | + window.__highlightSamples?.samples.push( |
| 99 | + Array.from( |
| 100 | + document.querySelectorAll( |
| 101 | + ".bg-editorHighlightedRangeColor", |
| 102 | + ), |
| 103 | + ) |
| 104 | + .map(node => node.textContent ?? "") |
| 105 | + .join(""), |
| 106 | + ); |
| 107 | + }, 20), |
| 108 | + samples: [], |
| 109 | + }; |
| 110 | + }); |
| 111 | + await codeEditor.pressSequentially("+ + + +", { delay: 50 }); |
| 112 | + |
| 113 | + const highlightSamples = await page.evaluate(() => { |
| 114 | + const highlightSamples = window.__highlightSamples?.samples ?? []; |
| 115 | + |
| 116 | + if (window.__highlightSamples) { |
| 117 | + window.clearInterval(window.__highlightSamples.intervalId); |
| 118 | + delete window.__highlightSamples; |
| 119 | + } |
| 120 | + |
| 121 | + return highlightSamples; |
| 122 | + }); |
| 123 | + |
| 124 | + expect(highlightSamples.length).toBeGreaterThan(0); |
| 125 | + expect( |
| 126 | + highlightSamples.every(highlightText => highlightText === "42"), |
| 127 | + ).toBe(true); |
| 128 | + await expect(highlight).toHaveText("42"); |
| 129 | +}); |
0 commit comments