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

test("Whitespace-heavy thread search preserves the rocket", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("demo");
  const thread = await t3.thread({ project, title: "Launch prep", messages: ["Start"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.fill("Rocket checklist needle" + " ".repeat(456) + "🚀 tail");
  await composer.press("Enter");
  await screen.getByText("second fixture turn complete", { exact: false }).waitFor({ state: "visible" });
  await browser.keyboard.press("Control+k");
  await screen.getByPlaceholder("Search commands, projects, and threads...").fill("needle");
  await screen.getByText("You: Rocket checklist needle", { exact: false }).waitFor({ state: "visible" });
  await app.screenshot("command-palette");
  await browser.keyboard.press("Escape");
  await screen.getByRole("combobox", "Search threads").fill("needle");
  const results = screen.getByRole("listbox", "Thread search results");
  await results.getByText("Rocket checklist needle", { exact: false }).waitFor({ state: "visible" });
  await app.screenshot("sidebar-search");
  await expect(results).toContainText("needle 🚀");
  await screen.getByRole("combobox", "Search threads").fill("");
  await browser.keyboard.press("Control+k");
  await screen.getByPlaceholder("Search commands, projects, and threads...").fill("needle");
  await expect(screen.getByText("You: Rocket checklist needle", { exact: false })).toContainText("needle 🚀");
});
