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

test("Automatic project monograms keep Myanmar and Balinese conjuncts", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Monogram sample");
  await t3.open("/settings/projects");
  await screen.getByRole("button", /^Monogram sample/).tap();
  const cases = [
    ["myanmar-multiword", "က္က Alpha", "က္ကA"],
    ["balinese-ssa-multiword", "ᬓ᭄ᬱ Alpha", "ᬓ᭄ᬱA"],
    ["balinese-ra-multiword", "ᬓ᭄ᬋ Alpha", "ᬓ᭄ᬋA"],
    ["myanmar-lone", "က္က", "က္က"],
    ["balinese-lone", "ᬓ᭄ᬱ", "ᬓ᭄ᬱ"],
    ["balinese-terminal-stacker", "ᬅ᭄", "ᬅ᭄ᬅ᭄"],
  ];
  const actual: string[] = [];
  for (const [label, name] of cases) {
    const input = screen.getByRole("textbox", "Project name", { exact: true });
    await input.fill(name!);
    await input.press("Enter");
    await browser.locator(`input[aria-label="Project name"][value="${name}"]`).waitFor();
    const path = await browser.evaluate(() => location.pathname + location.search);
    await t3.open(path);
    await browser.locator(`input[aria-label="Project name"][value="${name}"]`).waitFor();
    await screen.getByRole("button", "Choose a project icon").waitFor();
    await browser.evaluate(async () => { await document.fonts.ready; });
    await app.screenshot(label!);
    actual.push(await browser.locator('[data-slot="project-monogram"] text').last().textContent() ?? "");
  }
  expect(actual).toEqual(cases.map((c) => c[2]));
});
