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

test("Dotted capital I searches highlight the message word and quoted phrase", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Travel notes");
  const thread = await t3.thread({ project, title: "Spring trip planning", messages: ["Start"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("Add the İstanbul guide notes for the spring trip");
  await composer.press("Enter");
  await screen.getByText("second fixture turn complete", { exact: false }).waitFor();
  await browser.keyboard.press("Control+k");
  const search = screen.getByRole("combobox");
  const highlights: string[][] = [];
  for (const [query, label] of [["İstanbul", "dotted-I-word"], ['"İstanbul guide"', "dotted-I-phrase"]]) {
    await search.fill(query);
    await screen.getByRole("option").filter({ hasText: "You: Add the İstanbul guide notes for the spring trip" }).waitFor();
    await app.screenshot(label);
    highlights.push(await browser.evaluate(() => Array.from(document.querySelectorAll('[role="option"] mark'), node => node.textContent ?? "")));
  }
  expect(highlights).toEqual([["İstanbul"], ["İstanbul guide"]]);
});
