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

test("Project content search explains the 256-character query limit", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Search demo", { "sample.txt": "A small searchable project.\n" });
  await t3.open();
  await screen.getByText("Search demo", { exact: true }).first().tap({ timeout: 120_000 });
  await browser.keyboard.press("Control+Shift+F");
  const input = screen.getByRole("combobox");
  await input.fill("a".repeat(256));
  await expect(screen.getByText("0 results in 0 files", { exact: true })).toBeVisible();
  await app.screenshot("256-characters");
  await browser.keyboard.press("End");
  await browser.keyboard.type("a");
  await expect(screen.getByText(/Schema validation failed|Search is limited to 256 characters\./)).toBeVisible();
  await app.screenshot("257-characters");
  await expect(screen.getByText("Search is limited to 256 characters.", { exact: true })).toBeVisible();
  await browser.keyboard.press("Backspace");
  await expect(screen.getByText("0 results in 0 files", { exact: true })).toBeVisible();
  await app.screenshot("shortened-to-256");
});
