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

test("Reference links resolve after indented code fences", WEB, async ({ t3, app, screen }) => {
  const files = Object.fromEntries([2, 3].map((n) => {
    const indent = " ".repeat(n);
    return [`release-${n}.md`, "[Release notes][release]\n\n" +
      "Background for this release. ".repeat(200) +
      `\n\n## Appendix\n\n${indent}\`\`\`text\n${indent}[fake]: /inside-the-fence\n${indent}\`\`\`\n[release]: https://example.com/releases\n`];
  }));
  const project = await t3.project("release-documentation", files);
  const thread = await t3.thread({ project, title: "Review release notes", messages: [
    'See :codex-file-citation{path="release-2.md"} and :codex-file-citation{path="release-3.md"}'
  ] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent See/).tap();
  for (const n of [2, 3]) {
    await screen.getByRole("link", new RegExp(`^release-${n}\\.md`)).tap();
    if (n === 2) await screen.getByRole("button", "Show rendered markdown").tap();
    await app.screenshot(`indented-${n}-reference`);
  }
  await expect(screen.getByRole("link", "Release notes")).toHaveAttribute("href", "https://example.com/releases");
});
