import { expect } from "e2e";

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

test(
  "A long Markdown preview resolves a tab-indented footnote in a list item",
  WEB,
  async ({ t3, app, browser, screen }) => {
    const markdown = [
      "See the source[^source].",
      "",
      "Background paragraph. ".repeat(220),
      "",
      "## Sources",
      "",
      "10. Source details",
      "",
      "\t[^source]: Numbered source note.",
      "",
    ].join("\n");
    const project = await t3.project("documentation", { "sources.md": markdown });
    const thread = await t3.thread({
      project,
      title: "Source notes",
      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.", { exact: false }).waitFor();
    await app.screenshot("tab-indented-footnote-definition");
    expect(await browser.locator("a[data-footnote-ref]").count()).toBe(1);
    await expect(browser.locator("section[data-footnotes]")).toContainText("Numbered source note.");
  },
);
