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

test("Branch labels keep vowel signs and accents with their base letter", WEB, async ({t3, app, browser, screen}) => {
  await browser.setViewport({width:1280,height:800});
  const cases = [
    {name:"Devanagari branch", branch:"t3/परीक्षणशाखानयापेजबदलावक"},
    {name:"Latin accent branch", branch:"t3/abcdefghijklmnopqrstuvwxye\u0301abcdefghi"},
  ];
  const seeded = [];
  for (const item of cases) {
    const project = await t3.project(item.name);
    await runPromise(run("git", ["checkout","-b",item.branch], {cwd:project}));
    const thread = await t3.thread({project,title:item.name,messages:["first"]});
    seeded.push({...item,thread});
  }
  const tails: string[] = [];
  for (const item of seeded) {
    await t3.open(item.thread);
    const label = browser.locator(`span[title="${item.branch}"]`).first();
    await label.waitFor();
    await screen.getByText("first fixture turn complete", {exact:true}).waitFor();
    await app.screenshot(item.name);
    tails.push(await browser.locator(`span[title="${item.branch}"] > span:last-child`).first().textContent() ?? "");
  }
  expect(tails.map(tail => /^\p{M}/u.test(tail))).toEqual([false, false]);
});
