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

test("Thread seed titles retain whole Thai and Lao AM syllables", WEB, async ({ t3, app, screen }) => {
  await t3.project("demo");
  await t3.open();
  const observed: string[] = [];
  const cases = [
    { label: "thai-cutoff", count: 49, syllable: "กำ" },
    { label: "lao-cutoff", count: 49, syllable: "ກຳ" },
    { label: "thai-fits-control", count: 48, syllable: "กำ" },
  ];
  for (const [index, item] of cases.entries()) {
    if (index > 0) await screen.getByRole("button", "New thread in demo", { exact: true }).tap();
    const prefix = "a".repeat(item.count);
    const composer = screen.getByRole("textbox");
    await composer.fill(`${prefix}${item.syllable} notes`);
    await composer.press("Enter");
    const title = screen.getByRole("heading", new RegExp(`^${prefix}`));
    await title.waitFor();
    observed.push(await title.textContent() ?? "");
    await app.screenshot(item.label);
  }
  expect(observed).toEqual([
    `${"a".repeat(49)}...`,
    `${"a".repeat(49)}...`,
    `${"a".repeat(48)}กำ...`,
  ]);
});
