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

test("Quoted searches respect accented word and camelCase boundaries", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("demo");
  await t3.open("/");
  await screen.getByRole("button", "New thread in demo", { exact: true }).first().waitFor();
  const titles = ["Open Cafe today", "Open Cafe\u0301 today", "Open Cafe\u0301teria", "Open Caf\u00e9teria composed", "Open Cafe\u0301Tools", "Open Caf\u00e9Tools composed"];
  const threads = [];
  for (const title of titles) threads.push(await t3.thread({ project, title, messages: ["Start"] }));
  await t3.open(threads[0]);
  await screen.getByText("first fixture turn complete").waitFor();
  await browser.keyboard.press("Control+k");
  const palette = screen.getByRole("dialog", "Command palette");
  const search = palette.getByRole("combobox");
  await search.fill("open cafe");
  await palette.getByText(titles[2], { exact: true }).waitFor();
  await palette.getByText("Searching messages…", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("unquoted-open-cafe");
  await search.fill('"open cafe"');
  await palette.getByText(titles[0], { exact: true }).waitFor();
  await palette.getByText("Searching messages…", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("quoted-open-cafe");
  await search.fill('"tools"');
  await palette.getByText(titles[5], { exact: true }).waitFor();
  await palette.getByText("Searching messages…", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("quoted-tools-camelcase");
  await expect(palette.getByText(titles[4], { exact: true })).toBeVisible();
  await search.fill('"open cafe"');
  await palette.getByText(titles[0], { exact: true }).waitFor();
  await expect(palette.getByText(titles[1], { exact: true })).toBeVisible();
  await expect(palette.getByText(titles[2], { exact: true })).toHaveCount(0);
  await expect(palette.getByText(titles[3], { exact: true })).toHaveCount(0);
});
