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

test("GitHub note anchors reveal the pull request description", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("anchor-demo");
  const seed = { project, title: "GitHub description anchor", messages: ["Start"] };
  const thread = await t3.thread({ ...seed, model: "multi-turn" }).catch((error) => {
    if (!String(error).includes("Advertised models: default")) throw error;
    return t3.thread({ ...seed, model: "default" }).catch((nextError) => {
      if (!String(nextError).includes("Model default is not advertised")) throw nextError;
      return t3.thread({ ...seed, model: "multi-turn" });
    });
  });
  await browser.setViewport({ width: 1280, height: 800 });
  await t3.open(thread);
  await screen.getByTestId("composer-editor").fill("https://github.com/HaujetZhao/QuickCut/pull/15#note_1");
  await screen.getByRole("button", "Submit message", { exact: true }).tap();
  await browser.locator('a[href="https://github.com/HaujetZhao/QuickCut/pull/15#note_1"]').first().click();
  await screen.getByRole("button", "Summary", { exact: true }).waitFor({ timeout: 60_000 });
  await browser.locator('text=/The linked item is not in the loaded activity.|magick identify/').first().waitFor({ timeout: 60_000 });
  await app.screenshot("github-note-description");
  await expect(screen.getByRole("button", "Summary", { exact: true })).toHaveAttribute("aria-pressed", "true");
  expect(await browser.locator('[id="user-content-note_1"]').isVisible(), "The description anchor is revealed").toBe(true);
});
