mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 09:01:17 -07:00
fix(cli): enable typechecking for ui/components tests (#11419)
Co-authored-by: Jacob MacDonald <jakemac@google.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import type {
|
||||
TextBuffer,
|
||||
TextBufferState,
|
||||
TextBufferAction,
|
||||
VisualLayout,
|
||||
} from './text-buffer.js';
|
||||
import {
|
||||
useTextBuffer,
|
||||
@@ -24,6 +25,12 @@ import {
|
||||
} from './text-buffer.js';
|
||||
import { cpLen } from '../../utils/textUtils.js';
|
||||
|
||||
const defaultVisualLayout: VisualLayout = {
|
||||
visualLines: [''],
|
||||
logicalToVisualMap: [[[0, 0]]],
|
||||
visualToLogicalMap: [[0, 0]],
|
||||
};
|
||||
|
||||
const initialState: TextBufferState = {
|
||||
lines: [''],
|
||||
cursorRow: 0,
|
||||
@@ -33,6 +40,9 @@ const initialState: TextBufferState = {
|
||||
redoStack: [],
|
||||
clipboard: null,
|
||||
selectionAnchor: null,
|
||||
viewportWidth: 80,
|
||||
viewportHeight: 24,
|
||||
visualLayout: defaultVisualLayout,
|
||||
};
|
||||
|
||||
describe('textBufferReducer', () => {
|
||||
@@ -1700,28 +1710,40 @@ describe('logicalPosToOffset', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Helper to create state for reducer tests
|
||||
const createTestState = (
|
||||
lines: string[],
|
||||
cursorRow: number,
|
||||
cursorCol: number,
|
||||
viewportWidth = 80,
|
||||
): TextBufferState => {
|
||||
const text = lines.join('\n');
|
||||
let state = textBufferReducer(initialState, {
|
||||
type: 'set_text',
|
||||
payload: text,
|
||||
});
|
||||
state = textBufferReducer(state, {
|
||||
type: 'set_cursor',
|
||||
payload: { cursorRow, cursorCol, preferredCol: null },
|
||||
});
|
||||
state = textBufferReducer(state, {
|
||||
type: 'set_viewport',
|
||||
payload: { width: viewportWidth, height: 24 },
|
||||
});
|
||||
return state;
|
||||
};
|
||||
|
||||
describe('textBufferReducer vim operations', () => {
|
||||
describe('vim_delete_line', () => {
|
||||
it('should delete a single line including newline in multi-line text', () => {
|
||||
const initialState: TextBufferState = {
|
||||
lines: ['line1', 'line2', 'line3'],
|
||||
cursorRow: 1,
|
||||
cursorCol: 2,
|
||||
preferredCol: null,
|
||||
visualLines: [['line1'], ['line2'], ['line3']],
|
||||
visualScrollRow: 0,
|
||||
visualCursor: { row: 1, col: 2 },
|
||||
viewport: { width: 10, height: 5 },
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
};
|
||||
const state = createTestState(['line1', 'line2', 'line3'], 1, 2);
|
||||
|
||||
const action: TextBufferAction = {
|
||||
type: 'vim_delete_line',
|
||||
payload: { count: 1 },
|
||||
};
|
||||
|
||||
const result = textBufferReducer(initialState, action);
|
||||
const result = textBufferReducer(state, action);
|
||||
expect(result).toHaveOnlyValidCharacters();
|
||||
|
||||
// After deleting line2, we should have line1 and line3, with cursor on line3 (now at index 1)
|
||||
@@ -1731,25 +1753,14 @@ describe('textBufferReducer vim operations', () => {
|
||||
});
|
||||
|
||||
it('should delete multiple lines when count > 1', () => {
|
||||
const initialState: TextBufferState = {
|
||||
lines: ['line1', 'line2', 'line3', 'line4'],
|
||||
cursorRow: 1,
|
||||
cursorCol: 0,
|
||||
preferredCol: null,
|
||||
visualLines: [['line1'], ['line2'], ['line3'], ['line4']],
|
||||
visualScrollRow: 0,
|
||||
visualCursor: { row: 1, col: 0 },
|
||||
viewport: { width: 10, height: 5 },
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
};
|
||||
const state = createTestState(['line1', 'line2', 'line3', 'line4'], 1, 0);
|
||||
|
||||
const action: TextBufferAction = {
|
||||
type: 'vim_delete_line',
|
||||
payload: { count: 2 },
|
||||
};
|
||||
|
||||
const result = textBufferReducer(initialState, action);
|
||||
const result = textBufferReducer(state, action);
|
||||
expect(result).toHaveOnlyValidCharacters();
|
||||
|
||||
// Should delete line2 and line3, leaving line1 and line4
|
||||
@@ -1759,25 +1770,14 @@ describe('textBufferReducer vim operations', () => {
|
||||
});
|
||||
|
||||
it('should clear single line content when only one line exists', () => {
|
||||
const initialState: TextBufferState = {
|
||||
lines: ['only line'],
|
||||
cursorRow: 0,
|
||||
cursorCol: 5,
|
||||
preferredCol: null,
|
||||
visualLines: [['only line']],
|
||||
visualScrollRow: 0,
|
||||
visualCursor: { row: 0, col: 5 },
|
||||
viewport: { width: 10, height: 5 },
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
};
|
||||
const state = createTestState(['only line'], 0, 5);
|
||||
|
||||
const action: TextBufferAction = {
|
||||
type: 'vim_delete_line',
|
||||
payload: { count: 1 },
|
||||
};
|
||||
|
||||
const result = textBufferReducer(initialState, action);
|
||||
const result = textBufferReducer(state, action);
|
||||
expect(result).toHaveOnlyValidCharacters();
|
||||
|
||||
// Should clear the line content but keep the line
|
||||
@@ -1787,25 +1787,14 @@ describe('textBufferReducer vim operations', () => {
|
||||
});
|
||||
|
||||
it('should handle deleting the last line properly', () => {
|
||||
const initialState: TextBufferState = {
|
||||
lines: ['line1', 'line2'],
|
||||
cursorRow: 1,
|
||||
cursorCol: 0,
|
||||
preferredCol: null,
|
||||
visualLines: [['line1'], ['line2']],
|
||||
visualScrollRow: 0,
|
||||
visualCursor: { row: 1, col: 0 },
|
||||
viewport: { width: 10, height: 5 },
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
};
|
||||
const state = createTestState(['line1', 'line2'], 1, 0);
|
||||
|
||||
const action: TextBufferAction = {
|
||||
type: 'vim_delete_line',
|
||||
payload: { count: 1 },
|
||||
};
|
||||
|
||||
const result = textBufferReducer(initialState, action);
|
||||
const result = textBufferReducer(state, action);
|
||||
expect(result).toHaveOnlyValidCharacters();
|
||||
|
||||
// Should delete the last line completely, not leave empty line
|
||||
@@ -1815,18 +1804,7 @@ describe('textBufferReducer vim operations', () => {
|
||||
});
|
||||
|
||||
it('should handle deleting all lines and maintain valid state for subsequent paste', () => {
|
||||
const initialState: TextBufferState = {
|
||||
lines: ['line1', 'line2', 'line3', 'line4'],
|
||||
cursorRow: 0,
|
||||
cursorCol: 0,
|
||||
preferredCol: null,
|
||||
visualLines: [['line1'], ['line2'], ['line3'], ['line4']],
|
||||
visualScrollRow: 0,
|
||||
visualCursor: { row: 0, col: 0 },
|
||||
viewport: { width: 10, height: 5 },
|
||||
undoStack: [],
|
||||
redoStack: [],
|
||||
};
|
||||
const state = createTestState(['line1', 'line2', 'line3', 'line4'], 0, 0);
|
||||
|
||||
// Delete all 4 lines with 4dd
|
||||
const deleteAction: TextBufferAction = {
|
||||
@@ -1834,7 +1812,7 @@ describe('textBufferReducer vim operations', () => {
|
||||
payload: { count: 4 },
|
||||
};
|
||||
|
||||
const afterDelete = textBufferReducer(initialState, deleteAction);
|
||||
const afterDelete = textBufferReducer(state, deleteAction);
|
||||
expect(afterDelete).toHaveOnlyValidCharacters();
|
||||
|
||||
// After deleting all lines, should have one empty line
|
||||
|
||||
Reference in New Issue
Block a user