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

test("whole-word search preserves four matches after discarding import/export hits", WEB, async ({ t3, app, screen, browser }) => {
  const files: Record<string, string> = {};
  for (let i = 0; i < 200; i++) {
    const filler = Array.from({ length: 4000 }, (_, n) => `export const imported${n} = "transport airport support";`).join("\n");
    files[`src/mod${String(i).padStart(3, "0")}/file${String(i).padStart(3, "0")}.ts`] = filler + ([0, 65, 130, 199].includes(i) ? '\nexport const marker = "port";\n' : '\n');
  }
  const project = await t3.project("Search fixture", files);
  const thread = await t3.thread({ project, title: "Workspace search proof", messages: ["Ready"] });
  await t3.open(thread);
  await screen.getByRole("textbox", "Message Workspace search proof").waitFor();
  await browser.keyboard.press("Control+Shift+f");
  await screen.getByRole("button", "Match whole word").tap();
  await screen.getByPlaceholder("Search in Search fixture").fill("port");
  await screen.getByText(/results in .* files/).waitFor({ state: "visible" });
  await app.screenshot("whole-word-port-results");
  await expect(screen.getByText("4 results in 4 files", { exact: true })).toBeVisible();
});
