Files
radicle-explorer/tests/e2e/hotkeys.spec.ts
T
2023-04-20 08:36:16 +02:00

36 lines
1.1 KiB
TypeScript

import { searchPlaceholder } from "@app/lib/shared";
import { test, expect } from "@tests/support/fixtures.js";
test("global hotkeys", async ({ page }) => {
await page.goto("/");
await page.locator("body").press(`/`);
await page.keyboard.type("searchquery");
// Keyboard hint shows up in the search bar.
{
await expect(page.getByText("⏎")).toBeVisible();
await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue(
"searchquery",
);
}
// Other hotkeys don't trigger while input is focussed.
{
await page.keyboard.type("?");
await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue(
"searchquery?",
);
await expect(page.getByText("Keyboard shortcuts")).not.toBeVisible();
}
// Hitting `Esc` defocuses the input.
{
await page.locator("body").press("Escape");
await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue(
"searchquery?",
);
await expect(page.getByText("⏎")).toBeVisible();
await expect(page.getByPlaceholder(searchPlaceholder)).not.toBeFocused();
}
});