mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 18:52:19 +00:00
Add reset individual keybind button (#3423)
Co-authored-by: Benjamin Lu <templu1107@proton.me>
This commit is contained in:
@@ -286,4 +286,139 @@ describe('useKeybindingStore', () => {
|
||||
expect(store.getKeybinding(newKeybinding.combo)?.commandId).toBe('command2')
|
||||
expect(store.getKeybindingsByCommandId('command1')).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should return false when no default or current keybinding exists during reset', () => {
|
||||
const store = useKeybindingStore()
|
||||
const result = store.resetKeybindingForCommand('nonexistent.command')
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false when current keybinding equals default keybinding', () => {
|
||||
const store = useKeybindingStore()
|
||||
const defaultKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'L', ctrl: true }
|
||||
})
|
||||
|
||||
store.addDefaultKeybinding(defaultKeybinding)
|
||||
const result = store.resetKeybindingForCommand('test.command')
|
||||
|
||||
expect(result).toBe(false)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
defaultKeybinding
|
||||
)
|
||||
})
|
||||
|
||||
it('should unset user keybinding when no default keybinding exists and return true', () => {
|
||||
const store = useKeybindingStore()
|
||||
const userKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'M', ctrl: true }
|
||||
})
|
||||
|
||||
store.addUserKeybinding(userKeybinding)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
|
||||
const result = store.resetKeybindingForCommand('test.command')
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(store.keybindings).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should restore default keybinding when user has overridden it and return true', () => {
|
||||
const store = useKeybindingStore()
|
||||
|
||||
const defaultKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'N', ctrl: true }
|
||||
})
|
||||
|
||||
const userKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'O', alt: true }
|
||||
})
|
||||
|
||||
store.addDefaultKeybinding(defaultKeybinding)
|
||||
store.updateKeybindingOnCommand(userKeybinding)
|
||||
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
userKeybinding
|
||||
)
|
||||
|
||||
const result = store.resetKeybindingForCommand('test.command')
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
defaultKeybinding
|
||||
)
|
||||
})
|
||||
|
||||
it('should remove unset record and restore default keybinding when user has unset it', () => {
|
||||
const store = useKeybindingStore()
|
||||
|
||||
const defaultKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'P', ctrl: true }
|
||||
})
|
||||
|
||||
store.addDefaultKeybinding(defaultKeybinding)
|
||||
|
||||
store.unsetKeybinding(defaultKeybinding)
|
||||
expect(store.keybindings).toHaveLength(0)
|
||||
|
||||
const serializedCombo = defaultKeybinding.combo.serialize()
|
||||
const userUnsetKeybindings = store.getUserUnsetKeybindings()
|
||||
expect(userUnsetKeybindings[serializedCombo]).toBeTruthy()
|
||||
expect(
|
||||
userUnsetKeybindings[serializedCombo].equals(defaultKeybinding)
|
||||
).toBe(true)
|
||||
|
||||
const result = store.resetKeybindingForCommand('test.command')
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
defaultKeybinding
|
||||
)
|
||||
|
||||
expect(store.getUserUnsetKeybindings()[serializedCombo]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should handle complex scenario with both unset and user keybindings', () => {
|
||||
const store = useKeybindingStore()
|
||||
|
||||
// Create default keybinding
|
||||
const defaultKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'Q', ctrl: true }
|
||||
})
|
||||
store.addDefaultKeybinding(defaultKeybinding)
|
||||
|
||||
// Unset default keybinding
|
||||
store.unsetKeybinding(defaultKeybinding)
|
||||
expect(store.keybindings).toHaveLength(0)
|
||||
|
||||
// Add user keybinding with different combo
|
||||
const userKeybinding = new KeybindingImpl({
|
||||
commandId: 'test.command',
|
||||
combo: { key: 'R', alt: true }
|
||||
})
|
||||
store.addUserKeybinding(userKeybinding)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
userKeybinding
|
||||
)
|
||||
|
||||
// Reset keybinding to default
|
||||
const result = store.resetKeybindingForCommand('test.command')
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(store.keybindings).toHaveLength(1)
|
||||
expect(store.getKeybindingByCommandId('test.command')).toEqual(
|
||||
defaultKeybinding
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user