summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/helpCommand.test.ts
diff options
context:
space:
mode:
authorPyush Sinha <[email protected]>2025-08-04 09:53:50 -0700
committerGitHub <[email protected]>2025-08-04 16:53:50 +0000
commite506b40c271da0e05a361f5299c37976a9e1f1f3 (patch)
tree2d569bd9a86734778f89e0197716e1b5db2954aa /packages/cli/src/ui/commands/helpCommand.test.ts
parent83a04c47552c1407662a5e3e567f4c5e50bba5de (diff)
fix: /help remove flickering and respect clear shortcut (ctr+l) (#3611)
Co-authored-by: Jacob Richman <[email protected]> Co-authored-by: Allen Hutchison <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/commands/helpCommand.test.ts')
-rw-r--r--packages/cli/src/ui/commands/helpCommand.test.ts46
1 files changed, 29 insertions, 17 deletions
diff --git a/packages/cli/src/ui/commands/helpCommand.test.ts b/packages/cli/src/ui/commands/helpCommand.test.ts
index b0441106..566eead7 100644
--- a/packages/cli/src/ui/commands/helpCommand.test.ts
+++ b/packages/cli/src/ui/commands/helpCommand.test.ts
@@ -4,37 +4,49 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { vi, describe, it, expect, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { helpCommand } from './helpCommand.js';
import { type CommandContext } from './types.js';
+import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
+import { MessageType } from '../types.js';
+import { CommandKind } from './types.js';
describe('helpCommand', () => {
let mockContext: CommandContext;
+ const originalEnv = { ...process.env };
beforeEach(() => {
- mockContext = {} as unknown as CommandContext;
+ mockContext = createMockCommandContext({
+ ui: {
+ addItem: vi.fn(),
+ },
+ } as unknown as CommandContext);
});
- it("should return a dialog action and log a debug message for '/help'", () => {
- const consoleDebugSpy = vi
- .spyOn(console, 'debug')
- .mockImplementation(() => {});
+ afterEach(() => {
+ process.env = { ...originalEnv };
+ vi.clearAllMocks();
+ });
+
+ it('should add a help message to the UI history', async () => {
if (!helpCommand.action) {
throw new Error('Help command has no action');
}
- const result = helpCommand.action(mockContext, '');
- expect(result).toEqual({
- type: 'dialog',
- dialog: 'help',
- });
- expect(consoleDebugSpy).toHaveBeenCalledWith('Opening help UI ...');
+ await helpCommand.action(mockContext, '');
+
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
+ expect.objectContaining({
+ type: MessageType.HELP,
+ timestamp: expect.any(Date),
+ }),
+ expect.any(Number),
+ );
});
- it("should also be triggered by its alternative name '?'", () => {
- // This test is more conceptual. The routing of altNames to the command
- // is handled by the slash command processor, but we can assert the
- // altNames is correctly defined on the command object itself.
- expect(helpCommand.altNames).toContain('?');
+ it('should have the correct command properties', () => {
+ expect(helpCommand.name).toBe('help');
+ expect(helpCommand.kind).toBe(CommandKind.BUILT_IN);
+ expect(helpCommand.description).toBe('for help on gemini-cli');
});
});