Keep terminal shortcut notice visible
Keep the terminal shortcut capture warning on screen until the user dismisses it or opens shortcut settings.
This commit is contained in:
parent
38f3540696
commit
b8a7adf8ed
|
|
@ -0,0 +1,59 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { toast } from 'sonner'
|
||||
import { showTerminalShortcutCaptureNotification } from './terminal-shortcut-capture-notification'
|
||||
|
||||
const { toastMessage } = vi.hoisted(() => ({
|
||||
toastMessage: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: {
|
||||
message: toastMessage
|
||||
}
|
||||
}))
|
||||
|
||||
function createLocalStorage(): Storage {
|
||||
const values = new Map<string, string>()
|
||||
|
||||
return {
|
||||
get length() {
|
||||
return values.size
|
||||
},
|
||||
clear: () => values.clear(),
|
||||
getItem: (key: string) => values.get(key) ?? null,
|
||||
key: (index: number) => Array.from(values.keys())[index] ?? null,
|
||||
removeItem: (key: string) => {
|
||||
values.delete(key)
|
||||
},
|
||||
setItem: (key: string, value: string) => {
|
||||
values.set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('showTerminalShortcutCaptureNotification', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('localStorage', createLocalStorage())
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('keeps the shortcut capture warning visible until dismissed', () => {
|
||||
showTerminalShortcutCaptureNotification({
|
||||
actionId: 'tab.close',
|
||||
platform: 'darwin'
|
||||
})
|
||||
|
||||
expect(toast.message).toHaveBeenCalledWith(
|
||||
'Orca handled a terminal shortcut',
|
||||
expect.objectContaining({
|
||||
duration: Infinity,
|
||||
dismissible: true,
|
||||
action: expect.objectContaining({ label: 'Open Shortcuts' })
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
@ -62,6 +62,10 @@ export function showTerminalShortcutCaptureNotification({
|
|||
)
|
||||
toast.message('Orca handled a terminal shortcut', {
|
||||
description: `${definition.title} (${bindingLabel}) can be changed in Keyboard Shortcuts.`,
|
||||
// Why: this is the user's one-time rebind path for a captured shortcut; it
|
||||
// should stay visible until they act on or dismiss it.
|
||||
duration: Infinity,
|
||||
dismissible: true,
|
||||
icon: <Keyboard className="size-4 text-muted-foreground" />,
|
||||
action: {
|
||||
label: 'Open Shortcuts',
|
||||
|
|
|
|||
Loading…
Reference in New Issue