/// <reference lib="dom" />
import { expect } from "e2e";
import { run } from "./shell.ts";
import { runPromise, test, WEB } from "./t3.ts";

test("A recording after a bare-CR code fence becomes a video attachment", WEB, async ({t3, app, browser, screen}) => {
  const repo = await t3.project("Recording proof");
  await runPromise(run("git", ["remote", "add", "origin", "https://t3code-factory-test@dev.azure.com/t3code-factory-test/t3-factory-test/_git/pr44798-cr-proof-20261128"], {cwd:repo}));
  await browser.setViewport({width:1280,height:900});
  await t3.open("/pull-requests");
  await screen.getByRole("button", /Recording after code fence \(bare CR\)/).tap();
  await screen.getByText("Done", {exact:true}).waitFor({timeout:60000});
  await screen.getByText("https://example.com/sample.mp4", {exact:true}).waitFor();
  await browser.evaluate(async () => {
    const deadline = Date.now() + 90000;
    while (document.querySelector("video") && Date.now() < deadline) {
      await new Promise(resolve => setTimeout(resolve, 100));
    }
    // Hide the shared test account identity in public evidence.
    for (const element of document.querySelectorAll("span")) {
      if (element.textContent?.includes("@") && element.children.length === 0) {
        element.textContent = "Test account";
      }
    }
  });
  await app.screenshot("bare-cr-recording-after-code-fence");
  await expect(screen.getByText(/Video unavailable · Pull request video/)).toBeVisible();
});
