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

test("Quoted Hindi title search requires complete words", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("demo");
  const threads = [];
  for (const title of ["Open किताबें", "Open किताब", "Open शक्\u200Dति", "Open शक्"]) {
    threads.push(await t3.thread({ project, title, model: "default", messages: ["Hello"] }));
  }
  await t3.open(threads[1]);
  await screen.getByText("Syncing messages…", { exact: true }).waitFor({ state: "hidden" });
  const search = screen.getByRole("combobox", "Search threads");
  const results = screen.getByRole("listbox", "Thread search results");
  try {
    await search.fill('"open किताब"');
    await results.getByRole("option").first().waitFor();
    await app.screenshot("quoted-hindi-vowel-sign");
    await expect(results.getByRole("option")).toHaveCount(1);
    await expect(results).toContainText("Open किताब");
  } finally {
    await search.fill('"open शक्"');
    await results.getByRole("option").first().waitFor();
    await app.screenshot("quoted-hindi-joiner");
    await expect(results.getByRole("option")).toHaveCount(1);
    await expect(results).toContainText("Open शक्");
  }
});
