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

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