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

test("Automatic project badges keep Sinhala conjuncts intact", WEB, async ({ t3, app, browser, screen }) => {
  const titles = ["ශ්‍රී ලංකා", "ප්‍රොජෙක්ට්", "ක්‍ෂේත්‍ර යෝජනා"];
  const threads = [];
  for (const title of titles) {
    const project = await t3.project(title);
    threads.push(await t3.thread({ project, title, messages: ["first"] }));
  }
  await browser.setViewport({ width: 1440, height: 1000 });
  await t3.open(threads[0]);
  await screen.getByText("first fixture turn complete", { exact: false }).waitFor();
  await browser.locator('[data-slot="project-monogram"]').first().waitFor();
  await browser.evaluate(async () => {
    await document.fonts.ready;
    document.documentElement.style.zoom = "1.5";
  });
  await screen.getByText("Syncing messages...", { exact: true }).waitFor({ state: "hidden" });
  await app.screenshot("sinhala-project-badges");
  const badges = await browser.evaluate(() => Array.from(document.querySelectorAll('[data-slot="project-monogram"]')).map(el => el.textContent));
  expect(badges, "Sidebar badges preserve joined Sinhala consonants and their vowel marks").toEqual(expect.arrayContaining(["ශ්‍රීලං", "ප්‍රොට්", "ක්‍ෂේයෝ"]));
});
