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

test("Long Markdown finds a quoted footnote definition", WEB, async ({ t3, app, screen, browser }) => {
  const body = "See the source[^source].\n\n" + "Background paragraph text for the long file. ".repeat(107) + "\n\n## Sources\n\n";
  const project = await t3.project("documentation", {
    "sources.md": body + "> [^source]: Quoted source note.\n",
    "plain.md": body + "[^source]: Plain source note.\n",
  });
  const thread = await t3.thread({ project, title: "Sources", messages: ['See :codex-file-citation{path="sources.md"}'] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent See/).tap();
  await screen.getByRole("link", /^sources\.md/).tap();
  await screen.getByRole("button", "Show rendered markdown").tap();
  await screen.getByText("Background paragraph text for the long file.", { exact: false }).waitFor();
  await app.screenshot("quoted-footnote");
  await screen.getByRole("heading", "Sources", { exact: true }).last().scrollIntoView();
  await app.screenshot("sources-and-footnotes");
  await expect(browser.locator("a[data-footnote-ref]")).toHaveCount(1);
  await expect(browser.locator("section[data-footnotes]")).toContainText("Quoted source note.");
});
