import { expect, test } from "@playwright/test"; test.beforeEach(async ({ page }) => { await page.goto("/editor-lazy.html?path=main.ts"); await page.click("#mount"); await page.click("#mount-second"); }); const editorOf = (page: import("@playwright/test").Page, hostId: string) => page.locator(hostId).getByRole("textbox", { name: "main.ts" }); test("two panels open on the same path share a live doc: typing in one appears in the other", async ({ page }) => { const first = editorOf(page, "#host"); const second = editorOf(page, "#host2"); await expect(first).toBeVisible(); await expect(second).toBeVisible(); await first.click(); await page.keyboard.press("End"); await page.keyboard.type(" // from the first panel"); await expect(second).toContainText("// from the first panel"); await second.click(); await page.keyboard.press("End"); await page.keyboard.type(" and the second"); await expect(first).toContainText("// from the first panel and the second"); await expect.poll(() => page.evaluate(() => (globalThis as any).files.read("main.ts"))).toContain( "// from the first panel and the second", ); }); test("Mod+f opens CodeMirror's search panel", async ({ page }) => { const first = editorOf(page, "#host"); await first.click(); await expect(page.locator(".cm-panel.cm-search")).toHaveCount(0); await page.keyboard.press("ControlOrMeta+f"); await expect(page.locator(".cm-panel.cm-search")).toBeVisible(); }); test("Mod+z undoes a typed edit", async ({ page }) => { const first = editorOf(page, "#host"); const text = () => first.evaluate((contentEl) => ((contentEl.getRootNode() as ShadowRoot).host as any).view.state.doc.toString()); const before = await text(); await first.click(); await page.keyboard.press("End"); await page.keyboard.type("ZZZ"); await expect.poll(text).toBe(before + "ZZZ"); await page.keyboard.press("ControlOrMeta+z"); await expect.poll(text).toBe(before); });