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

test("First content search includes a folder re-included by .ignore", WEB, async ({ t3, app, screen, browser }) => {
  const files: Record<string, string> = {
    ".gitignore": "notes/\n",
    ".ignore": "!notes/\n",
    "notes/standup.md": "needle\n",
    "top.ts": 'const x = "needle";\n',
  };
  const filler = "ordinary filler content without the search term\n".repeat(200);
  for (let dir = 0; dir < 300; dir++) {
    for (let file = 0; file < 200; file++) files[`filler/d${dir}/f${file}.txt`] = filler;
  }
  const project = await t3.project("Search warmup", files);
  const thread = await t3.thread({ project, title: "Search project", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByText("first fixture turn complete", { exact: false }).waitFor();
  await browser.keyboard.press("Control+Shift+f");
  await screen.getByPlaceholder("Search in Search warmup").fill("needle");
  await screen.getByText(/\d+ results in \d+ files/).waitFor({ timeout: 60_000 });
  await app.screenshot("first-content-search");
  await expect(screen.getByText("standup.md", { exact: true })).toBeVisible();
});
