|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { describe, expect, it } from 'vitest'; |
| 7 | +import { describe, expect, it, vi } from 'vitest'; |
8 | 8 | import type { Key as InkKey } from 'ink'; |
9 | 9 | import { TextBuffer } from '../../../src/ui/textBuffer.js'; |
10 | 10 | import { |
@@ -80,3 +80,52 @@ describe('AgentUI layout stability', () => { |
80 | 80 | expect(getComposerHelpLine(true, '70% context left', '? shortcuts · / commands')).toBe(' '); |
81 | 81 | }); |
82 | 82 | }); |
| 83 | + |
| 84 | +describe('AgentUI Ctrl+C behavior', () => { |
| 85 | + it('clears input when Ctrl+C is pressed with non-empty text', () => { |
| 86 | + const buffer = new TextBuffer(80, 10, 'hello world'); |
| 87 | + const onCtrlC = vi.fn(); |
| 88 | + |
| 89 | + // Simulate the Ctrl+C handler logic from AgentUI |
| 90 | + const currentInput = buffer.getText(); |
| 91 | + |
| 92 | + if (currentInput.length > 0) { |
| 93 | + // Should clear the input |
| 94 | + buffer.setText(''); |
| 95 | + onCtrlC(); |
| 96 | + } |
| 97 | + |
| 98 | + expect(buffer.getText()).toBe(''); |
| 99 | + expect(onCtrlC).toHaveBeenCalled(); |
| 100 | + }); |
| 101 | + |
| 102 | + it('does not trigger exit flow when Ctrl+C is pressed with non-empty text', () => { |
| 103 | + const buffer = new TextBuffer(80, 10, 'some typed text'); |
| 104 | + let exitCalled = false; |
| 105 | + |
| 106 | + // Simulate the Ctrl+C handler logic from AgentUI |
| 107 | + const currentInput = buffer.getText(); |
| 108 | + |
| 109 | + if (currentInput.length > 0) { |
| 110 | + // Should clear the input, NOT go to exit flow |
| 111 | + buffer.setText(''); |
| 112 | + } else { |
| 113 | + // Exit flow only when input is empty |
| 114 | + exitCalled = true; |
| 115 | + } |
| 116 | + |
| 117 | + expect(buffer.getText()).toBe(''); |
| 118 | + expect(exitCalled).toBe(false); |
| 119 | + }); |
| 120 | + |
| 121 | + it('preserves multi-line content until Ctrl+C clears it', () => { |
| 122 | + const buffer = new TextBuffer(80, 10, 'line1\nline2\nline3'); |
| 123 | + |
| 124 | + expect(buffer.getText()).toBe('line1\nline2\nline3'); |
| 125 | + |
| 126 | + // Simulate Ctrl+C clearing |
| 127 | + buffer.setText(''); |
| 128 | + |
| 129 | + expect(buffer.getText()).toBe(''); |
| 130 | + }); |
| 131 | +}); |
0 commit comments