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

test("Keybindings search finds the shown Ctrl shortcuts", WEB, async ({ t3, app, browser, screen }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  await t3.project("shortcut-demo");
  await t3.open("/settings/keybindings");
  const search = screen.getByRole("searchbox", "Search keybindings");
  await search.waitFor();
  const results: Record<string, boolean> = {};
  for (const [query, label] of [["ctrl+k", "Command Palette: Toggle"], ["Ctrl+K", "Command Palette: Toggle"], ["ctrl+shift+o", "Chat: New"], ["mod+k", "Command Palette: Toggle"]]) {
    await search.fill(query);
    await screen.getByText(/No keybindings match your search\.|Command Palette: Toggle|Chat: New/, { exact: true }).first().waitFor();
    // Read after React has finished the deferred search render.
    await browser.evaluate(async () => { await new Promise<void>(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))); return null; });
    await app.screenshot(query.replaceAll("+", "-"));
    results[query] = await browser.evaluate((text) => document.body.innerText.includes(text), label);
  }
  expect(results).toEqual({ "ctrl+k": true, "Ctrl+K": true, "ctrl+shift+o": true, "mod+k": true });
});
