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

test("Capped GitHub conversation discloses missing comments", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Rust", { ".git/config": '[remote "origin"]\n url = https://github.com/rust-lang/rust.git\n' });
  await t3.open("/pull-requests?repository=rust-lang/rust&number=112050&selectedUrl=https%3A%2F%2Fgithub.com%2Frust-lang%2Frust%2Fpull%2F112050");
  await screen.getByText(/^Comments \([1-9][0-9]+\)$/).waitFor({ state: "visible", timeout: 180000 });
  await screen.getByText(/Loading pull requests/).waitFor({ state: "hidden", timeout: 180000 });
  await app.screenshot("below-cap-conversation");
  await expect(screen.getByText(/This conversation is only partially loaded/)).not.toBeVisible();
  await t3.open("/pull-requests?repository=rust-lang/rust&number=112049&selectedUrl=https%3A%2F%2Fgithub.com%2Frust-lang%2Frust%2Fpull%2F112049");
  await screen.getByText(/^Comments \([1-9][0-9]+\)$/).waitFor({ state: "visible", timeout: 180000 });
  await browser.evaluate(() => {
    const heading = [...document.querySelectorAll("*")].find(el => el.children.length === 0 && /^Comments \([1-9][0-9]+\)$/.test(el.textContent ?? ""));
    heading?.scrollIntoView({ block: "start" });
  });
  await screen.getByText(/Loading pull requests/).waitFor({ state: "hidden", timeout: 180000 });
  await app.screenshot("capped-conversation");
  await expect(screen.getByText(/This conversation is only partially loaded/)).toBeVisible();
});
