import { expect } from "e2e";
import * as Effect from "effect/Effect";
import { run } from "./shell.ts";
import { runPromise, test, WEB } from "./t3.ts";

test("Zero-padded pull request number keeps the matching PR first", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("PR lookup");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project }));
  const thread = await t3.thread({ project, title: "Pull request number lookup", messages: ["Hello"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.fill("#42");
  await screen.getByRole("option", /Improve terminal navigation shortcuts/).waitFor({ timeout: 60_000 });
  await app.screenshot("baseline-42");
  await composer.fill("");
  await composer.fill("#0042");
  await runPromise(Effect.sleep("10 seconds"));
  await app.screenshot("zero-padded-0042");
  await expect(browser.locator('[data-composer-command-drawer] [role="option"]').first()).toContainText("Improve terminal navigation shortcuts and streamline git action PR flow");
});
