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

test("Plain-letter palette searches find stroke-letter thread titles", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Travel planning");
  const titles = ["Łódź trip", "København plan", "Đà Nẵng notes", "Ağrı map", "Café menu"];
  const threads = [];
  for (const title of titles) threads.push(await t3.thread({ project, title, messages: ["Start"] }));
  await t3.open(threads[0]!);
  await screen.getByText("Start", { exact: true }).waitFor({ timeout: 30_000 });
  await browser.keyboard.press("Control+k");
  const palette = screen.getByRole("dialog", "Command palette");
  const found: Record<string, boolean> = {};
  for (const [query, title] of [["cafe", "Café menu"], ["lodz", "Łódź trip"], ["da nang", "Đà Nẵng notes"], ["agri", "Ağrı map"], ["kobenhavn", "København plan"], ["trip", "Łódź trip"]]) {
    await palette.getByRole("combobox").fill(query!);
    await browser.locator('[data-slot="command-dialog-popup"] [data-slot="command-item"], [data-slot="command-dialog-popup"] div.text-center').first().waitFor();
    await palette.getByText(new RegExp(`${title}|No matching commands, projects, or threads`)).waitFor();
    await palette.getByText(/^Searching messages/).waitFor({ state: "hidden" });
    await app.screenshot(`palette-${query!.replaceAll(" ", "-")}`);
    found[query!] = await palette.getByText(title!, { exact: true }).isVisible();
  }
  expect(found).toEqual({ cafe: true, lodz: true, "da nang": true, agri: true, kobenhavn: true, trip: true });
});
