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

test("Canonically equivalent file names and parent folders get distinct labels", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("demo", {
    "draft/Caf\u00e9.md": "Draft coffee\n",
    "published/Cafe\u0301.md": "Published coffee\n",
    "control-a/Tea.md": "Tea A\n",
    "control-b/Tea.md": "Tea B\n",
    "one/Caf\u00e9/notes/Notes.md": "Nested coffee one\n",
    "two/Cafe\u0301/notes/Notes.md": "Nested coffee two\n",
  });
  const thread = await t3.thread({ project, title: "Coffee notes", messages: [
    "Compare [Café.md](./draft/Caf%C3%A9.md) with [Café.md](./published/Cafe%CC%81.md).\n\nControl: [Tea.md](./control-a/Tea.md) and [Tea.md](./control-b/Tea.md).\n\nIntermediate folders: [Notes.md](./one/Caf%C3%A9/notes/Notes.md) and [Notes.md](./two/Cafe%CC%81/notes/Notes.md).",
  ] });
  await t3.open(thread);
  await screen.getByRole("button", "Compare", { exact: false }).tap();
  await screen.getByRole("link", "Tea.md · demo/control-a", { exact: true }).waitFor();
  await app.screenshot("accented-file-labels");
  const labels = await browser.evaluate(() => Array.from(document.querySelectorAll('[data-user-message-collapsed] a')).map(a => a.textContent));
  expect(labels).toContain("Café.md · demo/draft");
  expect(labels).toContain("Café.md · demo/published");
  expect(labels).toContain("Notes.md · one/Café/notes");
  expect(labels).toContain("Notes.md · two/Café/notes");
});
