/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Automatic project monograms retain combining marks", WEB, async ({ t3, app, browser, screen }) => {
  const names = ["ΐδέα", "Alpha ǰava", "สวัสดี", "server"];
  const projects = [];
  for (const name of names) projects.push(await t3.project(name));
  const thread = await t3.thread({ project: projects[2]!, title: "Monogram check", messages: ["hello"] });
  await t3.open(thread);
  await screen.getByRole("combobox", "Projects", { exact: true }).tap();
  await screen.getByPlaceholder("Search projects...").waitFor();
  for (const name of names) await browser.locator('[role="option"]').filter({ hasText: name }).waitFor();
  await app.screenshot("automatic-project-monograms");
  const monograms = await browser.evaluate((names) => names.map((name) => {
    const row = Array.from(document.querySelectorAll('[role="option"]')).find((node) => Array.from(node.querySelectorAll('span')).some((span) => span.textContent === name));
    return row?.querySelector('[data-slot="project-monogram"] text')?.textContent ?? null;
  }), names);
  expect(monograms).toEqual(["Ι\u0308\u0301Α", "AJ\u030c", "สดี", "SR"]);
});
