/// <reference lib="dom" />
import { expect } from "e2e";
import { run } from "./shell.ts";
import { runPromise, test, WEB } from "./t3.ts";

test("Permissions shortcut closes the open branch picker", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Git");
  await runPromise(run("git", ["branch", "feature"], { cwd: project }));
  await t3.open("/");
  const permissions = browser.locator('[data-composer-shortcut~="composer.mode"]:visible').first();
  await permissions.focus();
  await browser.keyboard.press("Control+Shift+G");
  await screen.getByRole("option", "feature", { exact: true }).waitFor();
  await expect(browser.locator('input[placeholder="Search refs..."]')).toBeFocused();
  await app.screenshot("branch-open");
  await browser.keyboard.press("Control+Shift+A");
  await browser.locator('button[aria-label^="Permissions:"][aria-expanded="true"]').waitFor();
  await app.screenshot("permissions-after-branch-shortcut");
  await expect(browser.locator('[aria-label^="Branch:"][aria-expanded="true"]')).toHaveCount(0);
  await expect(screen.getByRole("option", "feature", { exact: true })).not.toBeVisible();
});
