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

test("Each PR keeps its own detail tab", WEB, async ({ t3, app, browser, screen }) => {
  await t3.project("demo", { ".git/config": '[remote "origin"]\nurl = https://github.com/pingdotgg/t3code.git\nfetch = +refs/heads/*:refs/remotes/origin/*\n' });
  await t3.open("/pull-requests?state=all&q=a%20question%20after%20a%20server%20restart");
  await screen.getByText("#46110", { exact: true }).first().click();
  await screen.getByRole("button", "Code", { exact: true }).click();
  await screen.getByRole("searchbox", "Search pull requests", { exact: true }).fill("Google sign-in in browser tabs");
  await screen.getByText("#45883", { exact: true }).first().click();
  await screen.getByRole("button", "Timeline", { exact: true }).click();
  await browser.locator("[data-right-panel-tab-list]").getByText("#46110", { exact: false }).click();
  await app.screenshot("first-pr-after-selecting-second-pr-tab");
  await expect(screen.getByRole("button", "Code", { exact: true })).toHaveAttribute("aria-pressed", "true");
  await browser.locator("[data-right-panel-tab-list]").getByText("#45883", { exact: false }).click();
  await app.screenshot("second-pr-retains-timeline");
  await expect(screen.getByRole("button", "Timeline", { exact: true })).toHaveAttribute("aria-pressed", "true");
});
