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

test("ArrowUp from the language search focuses the last language", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("menu-keyboard-demo");
  await t3.open("/settings/voice");
  await screen.getByRole("combobox", "Transcribe with").tap();
  await browser.keyboard.press("Home");
  await browser.keyboard.press("ArrowDown");
  await browser.keyboard.press("Enter");
  await screen.getByRole("button", /^Filter by language:/).tap();
  const search = screen.getByRole("textbox", "Search languages");
  await search.waitFor();
  await browser.keyboard.press("ArrowUp");
  await app.screenshot("language-search-after-arrow-up");
  const upFocus = await browser.evaluate(() => ({ role: document.activeElement?.getAttribute("role"), text: document.activeElement?.textContent?.trim(), label: document.activeElement?.getAttribute("aria-label") }));
  await search.tap();
  await browser.keyboard.press("ArrowDown");
  await app.screenshot("language-search-after-arrow-down");
  const downFocus = await browser.evaluate(() => document.activeElement?.textContent?.trim());
  expect(upFocus).toEqual({ role: "menuitemcheckbox", text: "Yiddish", label: null });
  expect(downFocus).toBe("All languages");
});
