mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 20:50:06 +00:00
* Add keybinding schema * nit * Keybinding store * nit * wip * Bind condition on ComfyCommand * Add settings * nit * Revamp keybinding store * Add tests * Add load keybinding * load extension keybindings * Load extension commands * Handle keybindings * test * Keybinding playwright test * Update README * nit * Remove log * Remove system stats fromt logging.ts
123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
import { setActivePinia, createPinia } from 'pinia'
|
|
import {
|
|
useKeybindingStore,
|
|
KeybindingImpl
|
|
} from '../../../src/stores/keybindingStore'
|
|
|
|
describe('useKeybindingStore', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
})
|
|
|
|
it('should add and retrieve default keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'A', ctrl: true }
|
|
})
|
|
|
|
store.addDefaultKeybinding(keybinding)
|
|
|
|
expect(store.keybindings).toHaveLength(1)
|
|
expect(store.getKeybinding(keybinding.combo)).toEqual(keybinding)
|
|
})
|
|
|
|
it('should add and retrieve user keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'B', alt: true }
|
|
})
|
|
|
|
store.addUserKeybinding(keybinding)
|
|
|
|
expect(store.keybindings).toHaveLength(1)
|
|
expect(store.getKeybinding(keybinding.combo)).toEqual(keybinding)
|
|
})
|
|
|
|
it('should override default keybindings with user keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const defaultKeybinding = new KeybindingImpl({
|
|
commandId: 'test.command1',
|
|
combo: { key: 'C', ctrl: true }
|
|
})
|
|
const userKeybinding = new KeybindingImpl({
|
|
commandId: 'test.command2',
|
|
combo: { key: 'C', ctrl: true }
|
|
})
|
|
|
|
store.addDefaultKeybinding(defaultKeybinding)
|
|
store.addUserKeybinding(userKeybinding)
|
|
|
|
expect(store.keybindings).toHaveLength(1)
|
|
expect(store.getKeybinding(userKeybinding.combo)).toEqual(userKeybinding)
|
|
})
|
|
|
|
it('should unset user keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'D', meta: true }
|
|
})
|
|
|
|
store.addUserKeybinding(keybinding)
|
|
expect(store.keybindings).toHaveLength(1)
|
|
|
|
store.unsetKeybinding(keybinding)
|
|
expect(store.keybindings).toHaveLength(0)
|
|
})
|
|
|
|
it('should unset default keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'E', ctrl: true, alt: true }
|
|
})
|
|
|
|
store.addDefaultKeybinding(keybinding)
|
|
expect(store.keybindings).toHaveLength(1)
|
|
|
|
store.unsetKeybinding(keybinding)
|
|
expect(store.keybindings).toHaveLength(0)
|
|
})
|
|
|
|
it('should throw an error when adding duplicate default keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'F', shift: true }
|
|
})
|
|
|
|
store.addDefaultKeybinding(keybinding)
|
|
expect(() => store.addDefaultKeybinding(keybinding)).toThrow()
|
|
})
|
|
|
|
it('should allow adding duplicate user keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding1 = new KeybindingImpl({
|
|
commandId: 'test.command1',
|
|
combo: { key: 'G', ctrl: true }
|
|
})
|
|
const keybinding2 = new KeybindingImpl({
|
|
commandId: 'test.command2',
|
|
combo: { key: 'G', ctrl: true }
|
|
})
|
|
|
|
store.addUserKeybinding(keybinding1)
|
|
store.addUserKeybinding(keybinding2)
|
|
|
|
expect(store.keybindings).toHaveLength(1)
|
|
expect(store.getKeybinding(keybinding2.combo)).toEqual(keybinding2)
|
|
})
|
|
|
|
it('should throw an error when unsetting non-existent keybindings', () => {
|
|
const store = useKeybindingStore()
|
|
const keybinding = new KeybindingImpl({
|
|
commandId: 'test.command',
|
|
combo: { key: 'H', alt: true, shift: true }
|
|
})
|
|
|
|
expect(() => store.unsetKeybinding(keybinding)).toThrow()
|
|
})
|
|
})
|