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

test("PR Code tab expands a PNG into a visible image", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("t3code", { ".git/config": '[core]\nrepositoryformatversion = 0\nbare = false\n[remote "origin"]\nurl = https://github.com/pingdotgg/t3code.git\nfetch = +refs/heads/*:refs/remotes/origin/*\n' });
  await t3.open("/pull-requests?state=merged&repository=pingdotgg%2Ft3code&number=30420");
  await screen.getByRole("button", "Maximize panel", { exact: true }).tap();
  await screen.getByRole("button", "Code", { exact: true }).tap();
  await screen.getByText("apps/web/public/icon-192x192.png", { exact: true }).last().tap();
  try {
  await expect(screen.getByRole("img", "apps/web/public/icon-192x192.png", { exact: true })).toBeVisible();
  await expect.poll(async () => browser.evaluate(() => {
    const image = document.querySelector('img[alt="apps/web/public/icon-192x192.png"]') as HTMLImageElement | null;
    return !!image && image.complete && image.naturalWidth > 0;
  })).toBe(true);
  } finally {
    await app.screenshot("expanded-png");
  }
});
