mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 08:39:34 +00:00
752227da4c
The shortcut opened the menu but never closed it, so the only way out was Escape or the button. useHotkeys registers its listener once and keeps the callback it was first given. The callback closed over the disclosure toggle, which decides its direction from the opened value captured at that point. That value stays false for the life of the component, so every press took the open branch and the menu was reopened rather than closed. Instrumenting the handler shows it firing on each press while still reporting the menu as closed, after the component has already re-rendered with it open. Holding the state here and toggling from the previous value removes the dependency on the callback being current, so the shortcut works regardless. Covered by a spec asserting the shortcut both opens and closes, and that it closes a menu that was opened with the button. Both fail before this change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014L7R2LgjMSH2WQbiSP4uRn
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
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();
|
|
});
|