import { expect } from "e2e";

import { run } from "./shell.ts";
import { runPromise, test, WEB } from "./t3.ts";

test("The mixed branch picker prefers a local branch over its remote namesake", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("demo");
  const git = (...args: string[]) => runPromise(run("git", args, { cwd: project }));
  await git("branch", "topic");
  await git("clone", "--bare", ".", "../upstream.git");
  await git("remote", "add", "origin", "../upstream.git");
  await git("fetch", "origin");
  await git("remote", "set-head", "origin", "--auto");
  await git("branch", "-d", "topic");
  await git("branch", "origin/topic");
  await browser.setViewport({ width: 1280, height: 800 });
  await t3.open("/");
  const picker = browser.locator('[data-slot="combobox-trigger"][aria-label^="Branch:"]:visible').first();
  await picker.click();
  const topic = screen.getByRole("option", /^origin\/\s*topic\b/);
  await topic.waitFor();
  await app.screenshot("local-branch-origin-topic");
  await expect(topic).not.toContainText("remote");
});
