diff options
Diffstat (limited to 'packages/cli/src/ui/commands')
| -rw-r--r-- | packages/cli/src/ui/commands/corgiCommand.test.ts | 34 | ||||
| -rw-r--r-- | packages/cli/src/ui/commands/corgiCommand.ts | 15 | ||||
| -rw-r--r-- | packages/cli/src/ui/commands/types.ts | 3 |
3 files changed, 52 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/corgiCommand.test.ts b/packages/cli/src/ui/commands/corgiCommand.test.ts new file mode 100644 index 00000000..3c25e8cd --- /dev/null +++ b/packages/cli/src/ui/commands/corgiCommand.test.ts @@ -0,0 +1,34 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { corgiCommand } from './corgiCommand.js'; +import { type CommandContext } from './types.js'; +import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; + +describe('corgiCommand', () => { + let mockContext: CommandContext; + + beforeEach(() => { + mockContext = createMockCommandContext(); + vi.spyOn(mockContext.ui, 'toggleCorgiMode'); + }); + + it('should call the toggleCorgiMode function on the UI context', async () => { + if (!corgiCommand.action) { + throw new Error('The corgi command must have an action.'); + } + + await corgiCommand.action(mockContext, ''); + + expect(mockContext.ui.toggleCorgiMode).toHaveBeenCalledTimes(1); + }); + + it('should have the correct name and description', () => { + expect(corgiCommand.name).toBe('corgi'); + expect(corgiCommand.description).toBe('Toggles corgi mode.'); + }); +}); diff --git a/packages/cli/src/ui/commands/corgiCommand.ts b/packages/cli/src/ui/commands/corgiCommand.ts new file mode 100644 index 00000000..290c071e --- /dev/null +++ b/packages/cli/src/ui/commands/corgiCommand.ts @@ -0,0 +1,15 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { type SlashCommand } from './types.js'; + +export const corgiCommand: SlashCommand = { + name: 'corgi', + description: 'Toggles corgi mode.', + action: (context, _args) => { + context.ui.toggleCorgiMode(); + }, +}; diff --git a/packages/cli/src/ui/commands/types.ts b/packages/cli/src/ui/commands/types.ts index 51b66fb4..3e269cbf 100644 --- a/packages/cli/src/ui/commands/types.ts +++ b/packages/cli/src/ui/commands/types.ts @@ -47,6 +47,8 @@ export interface CommandContext { * @param history The array of history items to load. */ loadHistory: UseHistoryManagerReturn['loadHistory']; + /** Toggles a special display mode. */ + toggleCorgiMode: () => void; }; // Session-specific data session: { @@ -103,6 +105,7 @@ export type SlashCommandActionReturn = | QuitActionReturn | OpenDialogActionReturn | LoadHistoryActionReturn; + // The standardized contract for any command in the system. export interface SlashCommand { name: string; |
