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

test("Quoted message search includes a separate accent mark", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Phrase search demo");
  await t3.open("/");
  await screen.getByRole("button", "New thread in Phrase search demo", { exact: true }).first().waitFor();
  const threads = [];
  for (const title of ["First notes", "Second notes", "Third notes"]) {
    threads.push(await t3.thread({ project, title, messages: ["Start"] }));
  }
  for (const [index, message] of ["Café install", "Café install", "Cafe\u0301 install"].entries()) {
    await t3.open(threads[index]!);
    await screen.getByText("first fixture turn complete", { exact: true }).waitFor();
    const composer = screen.getByRole("textbox");
    await composer.fill(message);
    await composer.press("Enter");
    await screen.getByText("second fixture turn complete", { exact: true }).waitFor();
  }
  await browser.keyboard.press("Control+k");
  const palette = screen.getByRole("dialog", "Command palette");
  const search = palette.getByRole("combobox");
  await search.fill("cafe install");
  await palette.getByText("Third notes", { exact: true }).waitFor();
  await search.fill('"cafe install"');
  await palette.getByText("First notes", { exact: true }).waitFor();
  await palette.getByText("Searching messages…", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("quoted-cafe-install-results");
  const unaccentedFound = await palette.getByText("Third notes", { exact: true }).isVisible();
  await search.fill('"café install"');
  await palette.getByText("First notes", { exact: true }).waitFor();
  await palette.getByText("Searching messages…", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("quoted-accented-cafe-install-results");
  expect(unaccentedFound, "Unaccented quoted search includes Third notes").toBe(true);
  await expect(palette).toContainText("Third notes");
});
