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

test("Automatic project monograms preserve plain and ZWJ Devanagari conjuncts", WEB, async ({ t3, app, browser, screen }) => {
  const names = ["क्षेत्र योजना", "क्‍षेत्र योजना"];
  const threads = [];
  for (const name of names) {
    const project = await t3.project(name);
    threads.push(await t3.thread({ project, title: name, messages: ["Start"] }));
  }
  await browser.setViewport({ width: 1440, height: 1000 });
  const actual = [];
  for (let i = 0; i < threads.length; i++) {
    await t3.open(threads[i]);
    await screen.getByRole("combobox", "Projects", { exact: true }).tap();
    await screen.getByRole("option", names[i], { exact: true }).waitFor();
    await app.screenshot(i === 0 ? "plain-project-picker" : "zwj-project-picker");
    actual.push(await browser.evaluate((name) => {
      const option = Array.from(document.querySelectorAll('[role="option"]')).find(el => el.textContent?.includes(name));
      return option?.querySelector('[data-slot="project-monogram"] text')?.textContent ?? null;
    }, names[i]));
    await browser.keyboard.press("Escape");
  }
  expect(actual, "Each automatic icon retains its complete initial conjunct, including ZWJ").toEqual(["क्षेयो", "क्‍षेयो"]);
});
