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

test("Usage shortcut dismisses the open branch picker", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("picker-demo");
  const thread = await t3.thread({ project, title: "Picker shortcut demo", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("combobox", /^Branch:/).tap();
  const option = screen.getByRole("option", /^main(?: current)?$/);
  await option.waitFor();
  await app.screenshot("branch-picker-open");
  await browser.keyboard.press("Control+u");
  await screen.getByRole("dialog", "Usage", { exact: true }).waitFor();
  await app.screenshot("usage-after-shortcut");
  const pickerInterceptsPointer = await browser.evaluate(() => {
    const item = document.querySelector('[data-slot="combobox-item-content"]');
    if (!item) return false;
    const rect = item.getBoundingClientRect();
    return rect.width > 0 && rect.height > 0 && item.contains(document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2));
  });
  expect(pickerInterceptsPointer).toBe(false);
  await screen.getByRole("dialog", "Usage", { exact: true }).getByRole("button", "All providers", { exact: true }).tap();
  await app.screenshot("usage-own-provider-menu");
});
