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

test("A list fenced code sample does not define an outside reference", WEB, async ({ t3, app, screen }) => {
  const exact = "- ```md\n\n  [fake]: /wrong\n  ```\n\n[fake]";
  const project = await t3.project("markdown-samples", {
    "exact.md": exact,
    "example.md": exact + "\n\n[real]: /right\n\n[real]\n",
  });
  const thread = await t3.thread({ project, title: "Markdown samples", messages: ['See :codex-file-citation{path="exact.md"} and :codex-file-citation{path="example.md"}'] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent See/).waitFor();
  await screen.getByRole("button", /^Agent See/).tap();
  await screen.getByRole("link", /^exact\.md/).tap();
  await screen.getByRole("button", "Show rendered markdown").tap();
  await screen.getByText("[fake]: /wrong", { exact: true }).waitFor();
  await app.screenshot("exact-preview");
  await screen.getByRole("link", /^example\.md/).tap();
  await screen.getByRole("link", "real", { exact: true }).waitFor();
  await app.screenshot("example-preview");
  await expect(screen.getByRole("link", "fake", { exact: true })).not.toBeVisible();
  await expect(screen.getByRole("link", "real", { exact: true })).toBeVisible();
  await screen.getByRole("link", /^exact\.md/).tap();
  await expect(screen.getByRole("link", "fake", { exact: true })).not.toBeVisible();
});
