import { type Page, expect } from '@playwright/test' const COMMAND_INPUT = 'input[placeholder="Type a command..."]' export async function openCommandPalette(page: Page): Promise { await page.locator('body').click() await page.keyboard.press('Control+k') await expect(page.locator(COMMAND_INPUT)).toBeVisible() } export async function closeCommandPalette(page: Page): Promise { await page.keyboard.press('Escape') await expect(page.locator(COMMAND_INPUT)).not.toBeVisible() } export async function findCommand( page: Page, name: string, ): Promise { await page.locator(COMMAND_INPUT).fill(name) const match = page.locator('[data-selected="true"]').first() try { await match.waitFor({ timeout: 2_000 }) const text = await match.textContent() return text?.toLowerCase().includes(name.toLowerCase()) ?? false } catch { return false } } export async function executeCommand( page: Page, name: string, ): Promise { await page.locator(COMMAND_INPUT).fill(name) const match = page.locator('[data-selected="true"]').first() await match.waitFor({ timeout: 2_000 }) await page.keyboard.press('Enter') } export async function verifyVisible( page: Page, selector: string, ): Promise { await expect(page.locator(selector).first()).toBeVisible() } export async function verifyFocusable( page: Page, selector: string, ): Promise { const el = page.locator(selector).first() await expect(el).toBeVisible() await el.focus() await expect(el).toBeFocused() } export async function sendShortcut( page: Page, key: string, modifiers: Array<'Meta' | 'Control' | 'Shift' | 'Alt'> = [], ): Promise { const combo = [...modifiers, key].join('+') await page.keyboard.press(combo) }