import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Opening a TypeScript file focuses its editor for Find", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("editor-demo", {
    "src/greeting.ts": 'export function greeting(name: string): string {\n  return `Hello, ${name}!`;\n}\n\nexport const message = greeting("world");\n',
  });
  await t3.thread({ project, title: "Editor focus demo", messages: ["Ready to edit"] });
  await t3.open();
  await screen.getByTestId("sidebar-row-card").filter({ hasText: "Editor focus demo" }).tap();
  await screen.getByRole("button", "Toggle right panel").tap();
  await browser.keyboard.press("Control+p");
  await screen.getByPlaceholder("Search files…").fill("greeting.ts");
  await screen.getByRole("option").first().waitFor({ state: "visible" });
  await browser.keyboard.press("Enter");
  await browser.locator("[data-line]").first().waitFor({ state: "visible" });
  await browser.keyboard.press("Control+f");
  await app.screenshot("immediate-find");
  await expect.soft(browser.locator("input[data-search]")).toBeVisible();
  await browser.keyboard.press("Escape");
  await browser.locator("[data-line]").first().tap();
  await browser.keyboard.press("Control+f");
  await app.screenshot("find-after-click");
  await expect(browser.locator("input[data-search]")).toBeVisible();
});
