import type { Page } from "@playwright/test"; import { expect, test } from "./fixtures"; async function openFile(page: Page, path: string, text: string) { await page.evaluate( async ([path, text]) => { const backendPath = "/src/editor/core/backend.ts"; const servicePath = "/src/workbench/contributions.ts"; const { docBackend } = await import(backendPath); const { editorService } = await import(servicePath); docBackend().files.set(path, text); await editorService().openFile(path); }, [path, text], ); } const PEOPLE = "name,city\nZhang Wei,Beijing\nLi Na,Shanghai\nWang Fang,Shenzhen\n"; test("⌘F in a CSV file's Data tab searches the table, not the hidden text", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/people.csv", PEOPLE); await page.getByRole("tab", { name: "Data", exact: true }).click(); const table = page.getByRole("grid", { name: "Table view of the file" }); await table.getByText("Shanghai", { exact: true }).click(); await page.keyboard.press("Meta+f"); const search = page.getByRole("search", { name: "Search in results" }); const field = search.getByRole("textbox", { name: "Search in results" }); await expect(field).toBeFocused(); await expect(page.getByRole("search", { name: "Find in file" })).toHaveCount(0); await field.fill("Li Na"); await expect(search.locator("[aria-live]")).toHaveText("1/1"); await field.press("Escape"); await expect(search).toBeHidden(); await table.getByText("Shanghai", { exact: true }).click(); await page.keyboard.press("Meta+f"); await expect(field).toBeFocused(); await page.keyboard.type("Beijing"); await expect(field).toHaveValue("Beijing"); await table.getByText("Beijing", { exact: true }).click(); await page.keyboard.press("Meta+f"); await expect(field).toBeFocused(); await expect(field).toHaveValue("Beijing"); await page.getByRole("tab", { name: "Text", exact: true }).click(); await page.locator(".cm-content").click(); await page.keyboard.press("Meta+f"); await expect(page.getByRole("search", { name: "Find in file" })).toBeVisible(); }); test("⌘F right after choosing the Data tab opens the table search", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/people.csv", PEOPLE); await page.getByRole("tab", { name: "Data", exact: true }).click(); await expect(page.getByRole("grid", { name: "Table view of the file" })).toBeVisible(); await page.keyboard.press("Meta+f"); await expect(page.getByRole("textbox", { name: "Search in results" })).toBeFocused(); }); test("⌘G and ⇧⌘G step through the table's matches", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/people.csv", PEOPLE + "Zhao Lei,Shanghai\n"); await page.getByRole("tab", { name: "Data", exact: true }).click(); const table = page.getByRole("grid", { name: "Table view of the file" }); await table.getByText("Beijing", { exact: true }).click(); await page.keyboard.press("Meta+f"); const search = page.getByRole("search", { name: "Search in results" }); await search.getByRole("textbox").fill("Shanghai"); const count = search.locator("[aria-live]"); await expect(count).toHaveText("1/2"); await page.keyboard.press("Meta+g"); await expect(count).toHaveText("2/2"); await table.getByText("Beijing", { exact: true }).click(); await page.keyboard.press("Meta+Shift+g"); await expect(count).toHaveText("1/2"); await expect(page.getByRole("search", { name: "Find in file" })).toHaveCount(0); }); test("⌘G in a Find bar left open on the text still steps through the text", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/people.csv", PEOPLE + "Zhao Lei,Shanghai\n"); await page.locator(".cm-content").click(); await page.keyboard.press("Meta+f"); const editorFind = page.getByRole("search", { name: "Find in file" }); const editorField = editorFind.getByRole("textbox").first(); await editorField.fill("Shanghai"); const editorCount = editorFind.locator("[aria-live]"); await expect(editorCount).toHaveText("1/2"); await page.getByRole("tab", { name: "Data", exact: true }).click(); await page.getByRole("grid", { name: "Table view of the file" }).getByText("Beijing", { exact: true }).click(); await page.keyboard.press("Meta+f"); const search = page.getByRole("search", { name: "Search in results" }); await search.getByRole("textbox").fill("Shanghai"); const count = search.locator("[aria-live]"); await expect(count).toHaveText("1/2"); await editorField.click(); await page.keyboard.press("Meta+g"); await expect(editorCount).toHaveText("2/2"); await expect(count).toHaveText("1/2"); }); test("⌘F in the Value panel still searches the value", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/payloads.csv", 'id,payload\n1,"{""name"":""Ada""}"\n'); await page.getByRole("tab", { name: "Data", exact: true }).click(); const cell = page.getByRole("grid", { name: "Table view of the file" }).getByText('{"name":"Ada"}', { exact: true }); await cell.click({ button: "right" }); await page.getByText("Open in Value Editor", { exact: true }).click(); const panel = page.getByRole("complementary", { name: "Value panel" }); await panel.locator(".cm-content").click(); await page.keyboard.press("Meta+f"); await expect(panel.locator(".cm-search")).toBeVisible(); await expect(page.getByRole("search", { name: "Search in results" })).toHaveCount(0); }); test("⌘F in another pane still opens that editor's Find bar", async ({ workbench: page }) => { await openFile(page, "/dev/acme-api/people.csv", PEOPLE); await page.getByRole("tab", { name: "Data", exact: true }).click(); await expect(page.getByRole("grid", { name: "Table view of the file" })).toBeVisible(); await page.evaluate(async () => { const path = "/src/platform/actions.ts"; await (await import(/* @vite-ignore */ path)).executeAction("editor.splitRight"); }); const panes = page.locator("[data-pane-id]"); await expect(panes).toHaveCount(2); await openFile(page, "/dev/acme-api/notes.txt", "Li Na lives in Shanghai\n"); await panes.last().locator(".cm-content").click(); await page.keyboard.press("Meta+f"); await expect(panes.last().getByRole("search", { name: "Find in file" })).toBeVisible(); await expect(page.getByRole("search", { name: "Search in results" })).toHaveCount(0); });