53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { useKeyboardShortcuts } from '../../src/hooks/useKeyboardShortcuts'
|
|
import { KeybindingAction } from '../../src/constants/keybindings'
|
|
import { useKeybindingStore } from '../../src/stores/keybindingStore'
|
|
import { useCommandPaletteStore } from '../../src/stores/commandPaletteStore'
|
|
|
|
function ShortcutHarness() {
|
|
useKeyboardShortcuts()
|
|
return <input aria-label="editable" />
|
|
}
|
|
|
|
describe('editable clipboard shortcut contract', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
useKeybindingStore.setState({ customKeybindings: {}, isLoaded: true })
|
|
useCommandPaletteStore.setState({ isOpen: false })
|
|
})
|
|
|
|
it.each(['a', 'c', 'v', 'x', 'z', 'y'])('does not prevent Cmd/Ctrl+%s in an input', (key) => {
|
|
render(<ShortcutHarness />)
|
|
const input = screen.getByLabelText('editable')
|
|
const event = new KeyboardEvent('keydown', {
|
|
key,
|
|
metaKey: true,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
})
|
|
|
|
expect(input.dispatchEvent(event)).toBe(true)
|
|
expect(event.defaultPrevented).toBe(false)
|
|
})
|
|
|
|
it('keeps paste reserved even when a user shortcut conflicts with Cmd/Ctrl+V', () => {
|
|
useKeybindingStore.setState({
|
|
customKeybindings: { [KeybindingAction.TOOLS_COMMAND_PALETTE]: 'Ctrl+V' },
|
|
isLoaded: true,
|
|
})
|
|
render(<ShortcutHarness />)
|
|
const input = screen.getByLabelText('editable')
|
|
const event = new KeyboardEvent('keydown', {
|
|
key: 'v',
|
|
metaKey: true,
|
|
bubbles: true,
|
|
cancelable: true,
|
|
})
|
|
|
|
input.dispatchEvent(event)
|
|
expect(event.defaultPrevented).toBe(false)
|
|
expect(useCommandPaletteStore.getState().isOpen).toBe(false)
|
|
})
|
|
})
|