|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import { describe, it, expect, vi } from 'vitest'; |
| 8 | +import { TopicMessage } from './TopicMessage.js'; |
| 9 | +import { renderWithProviders } from '../../../test-utils/render.js'; |
| 10 | +import { |
| 11 | + TOPIC_PARAM_TITLE, |
| 12 | + TOPIC_PARAM_SUMMARY, |
| 13 | + TOPIC_PARAM_STRATEGIC_INTENT, |
| 14 | + CoreToolCallStatus, |
| 15 | + UPDATE_TOPIC_TOOL_NAME, |
| 16 | +} from '@google/gemini-cli-core'; |
| 17 | + |
| 18 | +describe('<TopicMessage />', () => { |
| 19 | + const baseArgs = { |
| 20 | + [TOPIC_PARAM_TITLE]: 'Test Topic', |
| 21 | + [TOPIC_PARAM_STRATEGIC_INTENT]: 'This is the strategic intent.', |
| 22 | + [TOPIC_PARAM_SUMMARY]: |
| 23 | + 'This is the detailed summary that should be expandable.', |
| 24 | + }; |
| 25 | + |
| 26 | + const renderTopic = async ( |
| 27 | + args: Record<string, unknown>, |
| 28 | + height?: number, |
| 29 | + toolActions?: { |
| 30 | + isExpanded?: (callId: string) => boolean; |
| 31 | + toggleExpansion?: (callId: string) => void; |
| 32 | + }, |
| 33 | + ) => |
| 34 | + renderWithProviders( |
| 35 | + <TopicMessage |
| 36 | + args={args} |
| 37 | + terminalWidth={80} |
| 38 | + availableTerminalHeight={height} |
| 39 | + callId="test-topic" |
| 40 | + name={UPDATE_TOPIC_TOOL_NAME} |
| 41 | + description="Updating topic" |
| 42 | + status={CoreToolCallStatus.Success} |
| 43 | + confirmationDetails={undefined} |
| 44 | + resultDisplay={undefined} |
| 45 | + />, |
| 46 | + { toolActions, mouseEventsEnabled: true }, |
| 47 | + ); |
| 48 | + |
| 49 | + it('renders title and intent by default (collapsed)', async () => { |
| 50 | + const { lastFrame } = await renderTopic(baseArgs, 40); |
| 51 | + const frame = lastFrame(); |
| 52 | + expect(frame).toContain('Test Topic:'); |
| 53 | + expect(frame).toContain('This is the strategic intent.'); |
| 54 | + expect(frame).not.toContain('This is the detailed summary'); |
| 55 | + expect(frame).not.toContain('(ctrl+o to expand)'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('renders summary when globally expanded (Ctrl+O)', async () => { |
| 59 | + const { lastFrame } = await renderTopic(baseArgs, undefined); |
| 60 | + const frame = lastFrame(); |
| 61 | + expect(frame).toContain('Test Topic:'); |
| 62 | + expect(frame).toContain('This is the strategic intent.'); |
| 63 | + expect(frame).toContain('This is the detailed summary'); |
| 64 | + expect(frame).not.toContain('(ctrl+o to collapse)'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('renders summary when selectively expanded via context', async () => { |
| 68 | + const isExpanded = vi.fn((id) => id === 'test-topic'); |
| 69 | + const { lastFrame } = await renderTopic(baseArgs, 40, { isExpanded }); |
| 70 | + const frame = lastFrame(); |
| 71 | + expect(frame).toContain('Test Topic:'); |
| 72 | + expect(frame).toContain('This is the detailed summary'); |
| 73 | + expect(frame).not.toContain('(ctrl+o to collapse)'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('calls toggleExpansion when clicked', async () => { |
| 77 | + const toggleExpansion = vi.fn(); |
| 78 | + const { simulateClick } = await renderTopic(baseArgs, 40, { |
| 79 | + toggleExpansion, |
| 80 | + }); |
| 81 | + |
| 82 | + // In renderWithProviders, the component is wrapped in a Box with terminalWidth. |
| 83 | + // The TopicMessage has marginLeft={2}. |
| 84 | + // So col 5 should definitely hit the text content. |
| 85 | + // row 1 is the first line of the TopicMessage. |
| 86 | + await simulateClick(5, 1); |
| 87 | + |
| 88 | + expect(toggleExpansion).toHaveBeenCalledWith('test-topic'); |
| 89 | + }); |
| 90 | + |
| 91 | + it('falls back to summary if strategic_intent is missing', async () => { |
| 92 | + const args = { |
| 93 | + [TOPIC_PARAM_TITLE]: 'Test Topic', |
| 94 | + [TOPIC_PARAM_SUMMARY]: 'Only summary is present.', |
| 95 | + }; |
| 96 | + const { lastFrame } = await renderTopic(args, 40); |
| 97 | + const frame = lastFrame(); |
| 98 | + expect(frame).toContain('Test Topic:'); |
| 99 | + expect(frame).toContain('Only summary is present.'); |
| 100 | + expect(frame).not.toContain('(ctrl+o to expand)'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('renders only strategic_intent if summary is missing', async () => { |
| 104 | + const args = { |
| 105 | + [TOPIC_PARAM_TITLE]: 'Test Topic', |
| 106 | + [TOPIC_PARAM_STRATEGIC_INTENT]: 'Only intent is present.', |
| 107 | + }; |
| 108 | + const { lastFrame } = await renderTopic(args, 40); |
| 109 | + const frame = lastFrame(); |
| 110 | + expect(frame).toContain('Test Topic:'); |
| 111 | + expect(frame).toContain('Only intent is present.'); |
| 112 | + expect(frame).not.toContain('(ctrl+o to expand)'); |
| 113 | + }); |
| 114 | +}); |
0 commit comments