// Evidence viewport: 1280 x 1100, configured on the web target in e2e.config.ts.
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

const body = "```npm test``` passes.\n\nhttps://example.com/demo.mp4\n\n```\nhttps://example.com/b.png\n```";

test("Inline triple backticks preserve PR media and the later fenced block", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("media-preview-proof", {
    ".git/config": '[core]\nrepositoryformatversion = 0\n[remote "origin"]\nurl = ' + process.env.PROOF_REPO_URL! + '\n',
  });
  const thread = await t3.thread({ project, title: "Media preview proof", messages: ["Prepare the preview fixture"] });
  await t3.open(thread);
  const url = new URL(process.env.PROOF_PR_URL!);
  const repository = url.pathname.split("/pullrequest/")[0]!.slice(1);
  const number = url.pathname.split("/").at(-1)!;
  await app.open("/pull-requests?host=dev.azure.com&repository=" + encodeURIComponent(repository) + "&number=" + number + "&selectedUrl=" + encodeURIComponent(url.href));
  await screen.getByRole("button", new RegExp("Open #" + number + " Inline code media preview proof")).tap();
  await screen.getByRole("button", "Edit description").tap();
  await screen.getByRole("textbox", "Pull request description").fill(body);
  console.log("Description input:", await browser.evaluate(() => document.querySelector<HTMLTextAreaElement>("textarea")?.value));
  await screen.getByRole("button", "Preview", { exact: true }).tap();
  try {
    await expect(browser.locator('video[aria-label="Pull request video"], [role="alert"]:has-text("Pull request video")')).toHaveCount(1);
    await expect(browser.locator("pre")).toHaveCount(1);
    await expect(browser.locator("pre")).toContainText("https://example.com/b.png");
    await expect(browser.locator("pre")).toBeVisible();
  } finally {
    await app.screenshot("inline-code-media-preview");
  }
});
