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

test("Chunked Markdown resolves references immediately after an HTML comment", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("markdown-links", {
    "links.md": `[Docs][docs]\n\n${"a ".repeat(2500)}\n\n## More\n\n<!-- Links -->\n[docs]: https://example.com\n[ci]: https://example.com/ci\n`,
  });
  const thread = await t3.thread({ project, title: "Markdown reference links", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Files F").tap();
  await screen.getByRole("treeitem", "links.md").tap();
  await screen.getByRole("button", "Show rendered markdown").tap();
  await screen.getByRole("heading", "More").waitFor();
  await app.screenshot("rendered-reference-link");
  await expect(screen.getByRole("link", "Docs", { exact: true })).toHaveAttribute("href", "https://example.com");
});
