import { expect, test } from '@playwright/test'; /** * The Space shortcut has to read the current open state, not the one captured when * the shortcut was registered, otherwise it only ever opens the menu. */ test('Space toggles the navigation menu both ways', async ({ page }) => { await page.goto('/timer'); // the shortcut is registered by the view chrome, wait for it before typing await expect(page.getByTestId('navigation__toggle-menu')).toBeAttached(); const menu = page.getByRole('dialog'); await expect(menu).toBeHidden(); await page.keyboard.press(' '); await expect(menu).toBeVisible(); await page.keyboard.press(' '); await expect(menu).toBeHidden(); }); test('Space closes a menu opened with the button', async ({ page }) => { await page.goto('/timer'); await expect(page.getByTestId('navigation__toggle-menu')).toBeAttached(); await page.mouse.move(Math.random() * 100, Math.random() * 100); await page.getByTestId('navigation__toggle-menu').click(); const menu = page.getByRole('dialog'); await expect(menu).toBeVisible(); await page.keyboard.press(' '); await expect(menu).toBeHidden(); });