diff options
| author | Harold Mciver <[email protected]> | 2025-07-16 20:27:36 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-17 00:27:36 +0000 |
| commit | fbe09cd35e6c043ea2dc69281b758e5ad9f3896c (patch) | |
| tree | 481b16f1e56ae7fc0eea04de11f60fcd04e0e961 /packages/cli/src/ui | |
| parent | ab9eb9377fdfe7823be8ea0c7c394c5368b28951 (diff) | |
update `/editor` to new slash command arch (#4153)
Co-authored-by: Abhi <[email protected]>
Diffstat (limited to 'packages/cli/src/ui')
| -rw-r--r-- | packages/cli/src/ui/commands/editorCommand.test.ts | 30 | ||||
| -rw-r--r-- | packages/cli/src/ui/commands/editorCommand.ts | 16 | ||||
| -rw-r--r-- | packages/cli/src/ui/commands/types.ts | 3 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.test.ts | 12 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/slashCommandProcessor.ts | 10 |
5 files changed, 51 insertions, 20 deletions
diff --git a/packages/cli/src/ui/commands/editorCommand.test.ts b/packages/cli/src/ui/commands/editorCommand.test.ts new file mode 100644 index 00000000..9b5e84d3 --- /dev/null +++ b/packages/cli/src/ui/commands/editorCommand.test.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { editorCommand } from './editorCommand.js'; +// 1. Import the mock context utility +import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; + +describe('editorCommand', () => { + it('should return a dialog action to open the editor dialog', () => { + if (!editorCommand.action) { + throw new Error('The editor command must have an action.'); + } + const mockContext = createMockCommandContext(); + const result = editorCommand.action(mockContext, ''); + + expect(result).toEqual({ + type: 'dialog', + dialog: 'editor', + }); + }); + + it('should have the correct name and description', () => { + expect(editorCommand.name).toBe('editor'); + expect(editorCommand.description).toBe('set external editor preference'); + }); +}); diff --git a/packages/cli/src/ui/commands/editorCommand.ts b/packages/cli/src/ui/commands/editorCommand.ts new file mode 100644 index 00000000..dbfafa51 --- /dev/null +++ b/packages/cli/src/ui/commands/editorCommand.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { type OpenDialogActionReturn, type SlashCommand } from './types.js'; + +export const editorCommand: SlashCommand = { + name: 'editor', + description: 'set external editor preference', + action: (): OpenDialogActionReturn => ({ + type: 'dialog', + dialog: 'editor', + }), +}; diff --git a/packages/cli/src/ui/commands/types.ts b/packages/cli/src/ui/commands/types.ts index 85a85abe..a61a29f2 100644 --- a/packages/cli/src/ui/commands/types.ts +++ b/packages/cli/src/ui/commands/types.ts @@ -71,8 +71,7 @@ export interface MessageActionReturn { */ export interface OpenDialogActionReturn { type: 'dialog'; - // TODO: Add 'theme' | 'auth' | 'editor' | 'privacy' as migration happens. - dialog: 'help' | 'auth' | 'theme' | 'privacy'; + dialog: 'help' | 'auth' | 'theme' | 'editor' | 'privacy'; } /** diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 399a923b..ab16d813 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -206,18 +206,6 @@ describe('useSlashCommandProcessor', () => { const getProcessor = () => getProcessorHook().result.current; - describe('Other commands', () => { - it('/editor should open editor dialog and return handled', async () => { - const { handleSlashCommand } = getProcessor(); - let commandResult: SlashCommandProcessorResult | false = false; - await act(async () => { - commandResult = await handleSlashCommand('/editor'); - }); - expect(mockOpenEditorDialog).toHaveBeenCalled(); - expect(commandResult).toEqual({ type: 'handled' }); - }); - }); - describe('New command registry', () => { let ActualCommandService: typeof CommandService; diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index c1c65080..237356fa 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -200,11 +200,6 @@ export const useSlashCommandProcessor = ( const commands: LegacySlashCommand[] = [ // `/help` and `/clear` have been migrated and REMOVED from this list. { - name: 'editor', - description: 'set external editor preference', - action: (_mainCommand, _subCommand, _args) => openEditorDialog(), - }, - { name: 'corgi', action: (_mainCommand, _subCommand, _args) => { toggleCorgiMode(); @@ -425,7 +420,6 @@ export const useSlashCommandProcessor = ( return commands; }, [ addMessage, - openEditorDialog, toggleCorgiMode, config, session, @@ -519,6 +513,9 @@ export const useSlashCommandProcessor = ( case 'theme': openThemeDialog(); return { type: 'handled' }; + case 'editor': + openEditorDialog(); + return { type: 'handled' }; case 'privacy': openPrivacyNotice(); return { type: 'handled' }; @@ -617,6 +614,7 @@ export const useSlashCommandProcessor = ( addMessage, openThemeDialog, openPrivacyNotice, + openEditorDialog, ], ); |
