Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

hotkey.spec.ts

41 lines1.6 KB

1import { test, expect } from '@playwright/test'
2import { DevtoolsPage } from '@tanstack/devtools-e2e'
3​
4// The shell's open hotkey is ["Control", "~"] and it is matched against
5// `KeyboardEvent.key` via @solid-primitives/keyboard. Playwright's
6// `keyboard.press('~')` would require Shift (which adds an extra key and breaks
7// the match), so we dispatch the exact keydown events the shell listens for:
8// Control first (so the modifier becomes the first held key), then "~" with
9// ctrlKey set. This mirrors a real Ctrl+~ press without the Shift artifact.
10async function pressOpenHotkey(page: import('@playwright/test').Page) {
11 await page.evaluate(() => {
12 window.dispatchEvent(
13 new KeyboardEvent('keydown', { key: 'Control', ctrlKey: true }),
14 )
15 window.dispatchEvent(
16 new KeyboardEvent('keydown', { key: '~', ctrlKey: true }),
17 )
18 window.dispatchEvent(new KeyboardEvent('keyup', { key: '~' }))
19 window.dispatchEvent(new KeyboardEvent('keyup', { key: 'Control' }))
20 })
22​
23test.describe('open hotkey', () => {
24 test('Control+~ toggles the panel open', async ({ page }) => {
25 const dt = new DevtoolsPage(page)
26 await dt.goto()
27 await expect(dt.panel()).toHaveAttribute('data-open', 'false')
28 await pressOpenHotkey(page)
29 await expect(dt.panel()).toHaveAttribute('data-open', 'true')
30 })
31​
32 test('Control+~ does not open panel when a text input is focused', async ({
33 page,
34 }) => {
35 const dt = new DevtoolsPage(page)
36 await dt.goto()
37 await page.getByTestId('text-input').focus()
38 await pressOpenHotkey(page)
39 await expect(dt.panel()).toHaveAttribute('data-open', 'false')
40 })
41})