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

test("Markdown resolves a reference immediately after an equals-sign Setext heading", WEB, async ({ t3, app, screen, browser }) => {
  const markdown = "Read [guide]. " + "filler ".repeat(600) + "\n\nNotes\n===\n[guide]: https://example.com/guide\n";
  const project = await t3.project("documentation", { "links.md": markdown });
  const thread = await t3.thread({ project, title: "Markdown preview", model: "default", 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", "Notes", { exact: true }).waitFor();
  await app.screenshot("setext-reference");
  await expect(browser.locator('a[href="https://example.com/guide"]')).toHaveCount(1);
});
