|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import { describe, it, expect } from 'vitest'; |
| 8 | +import { HelpCommand } from './help.js'; |
| 9 | +import { CommandRegistry } from './commandRegistry.js'; |
| 10 | +import type { Command, CommandContext } from './types.js'; |
| 11 | + |
| 12 | +describe('HelpCommand', () => { |
| 13 | + it('returns formatted help text with sorted commands', async () => { |
| 14 | + const registry = new CommandRegistry(); |
| 15 | + |
| 16 | + const cmdB: Command = { |
| 17 | + name: 'bravo', |
| 18 | + description: 'Bravo command', |
| 19 | + execute: async () => ({ name: 'bravo', data: '' }), |
| 20 | + }; |
| 21 | + |
| 22 | + const cmdA: Command = { |
| 23 | + name: 'alpha', |
| 24 | + description: 'Alpha command', |
| 25 | + execute: async () => ({ name: 'alpha', data: '' }), |
| 26 | + }; |
| 27 | + |
| 28 | + registry.register(cmdB); |
| 29 | + registry.register(cmdA); |
| 30 | + |
| 31 | + const helpCommand = new HelpCommand(registry); |
| 32 | + |
| 33 | + const context = {} as CommandContext; |
| 34 | + |
| 35 | + const response = await helpCommand.execute(context, []); |
| 36 | + |
| 37 | + expect(response.name).toBe('help'); |
| 38 | + |
| 39 | + const data = response.data as string; |
| 40 | + |
| 41 | + expect(data).toContain('Gemini CLI Help:'); |
| 42 | + expect(data).toContain('### Basics'); |
| 43 | + expect(data).toContain('### Commands'); |
| 44 | + |
| 45 | + const lines = data.split('\n'); |
| 46 | + const alphaIndex = lines.findIndex((l) => l.includes('/alpha')); |
| 47 | + const bravoIndex = lines.findIndex((l) => l.includes('/bravo')); |
| 48 | + |
| 49 | + expect(alphaIndex).toBeLessThan(bravoIndex); |
| 50 | + expect(alphaIndex).not.toBe(-1); |
| 51 | + expect(bravoIndex).not.toBe(-1); |
| 52 | + }); |
| 53 | +}); |
0 commit comments