Skip to content
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
689a8bd
Add interactive TUI mode with file tree side panel
armanarutiunov Feb 11, 2026
4d11f97
Add per-file addition/deletion line counts
armanarutiunov Feb 11, 2026
c434705
Add dir, border-focused, additions, deletions theme colors
armanarutiunov Feb 11, 2026
0575e48
Rewrite file tree as nested expandable tree with file icons and +N -M…
armanarutiunov Feb 11, 2026
92ae324
Add focus border indicator, ctrl+d/u half-page scroll, update sync fo…
armanarutiunov Feb 11, 2026
53d1685
Match folder color to file name header, darken tree background
armanarutiunov Feb 11, 2026
e5aed4e
Add git staging status detection with green/orange file coloring
armanarutiunov Feb 11, 2026
2cc4e2a
Add staged/partial-staged/file-selected theme colors, fix span ordering
armanarutiunov Feb 11, 2026
4096f5d
Use background-only selection for files, keep inverse for dirs
armanarutiunov Feb 11, 2026
c06368d
Fix dead ternary in FileTreePanel, use execFileSync in gitStatus
armanarutiunov Feb 12, 2026
9a533ca
Deduplicate side-by-side diff parser into single iterSideBySideDiffEv…
armanarutiunov Feb 12, 2026
6eb9fa7
Add Windows fallback for interactive mode, deduplicate TREE_WIDTH/BOR…
armanarutiunov Feb 12, 2026
df4fa57
Fix stale rendering artifacts with ERASE_TO_EOL and screen clear
armanarutiunov Feb 12, 2026
4086e02
Add 'e' key tree toggle and dynamic diff re-render on terminal resize
armanarutiunov Feb 12, 2026
a608033
Fix ttyFd leak, remove dead params, restore comments, export helpers
armanarutiunov Feb 12, 2026
211ffe4
Add unit tests for TUI helpers
armanarutiunov Feb 12, 2026
0be5f85
Make tree width configurable via split-diffs.tree-width
armanarutiunov Feb 12, 2026
6f29eee
Add 'f' key to toggle flat/folder file tree mode
armanarutiunov Mar 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unit tests for TUI helpers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
armanarutiunov and claude committed Feb 12, 2026
commit 211ffe479c1c94dc9ca60ef97d98f67fff4f91a5
173 changes: 173 additions & 0 deletions src/tui/tui.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { truncateAnsi } from './Screen';
import { getFileIcon } from './fileIcons';
import { binarySearchBoundary } from './sync';
import { buildTree, flattenVisible } from './FileTreePanel';
import { DiffFile } from './collectDiffData';

const RESET = '\x1b[0m';

describe('truncateAnsi', () => {
test('plain text within limit', () => {
expect(truncateAnsi('hello', 10)).toBe('hello');
});

test('plain text exceeding limit', () => {
const result = truncateAnsi('hello world', 5);
expect(result).toBe('hello' + RESET);
});

test('zero width returns reset only', () => {
const result = truncateAnsi('hello', 0);
expect(result).toBe(RESET);
});

test('preserves ANSI escapes, truncates visible chars', () => {
const input = '\x1b[31mhello\x1b[0m world';
const result = truncateAnsi(input, 5);
// Should contain 'hello' colored red but not ' world'
expect(result).toContain('\x1b[31m');
expect(result.replace(/\x1b\[[0-9;]*m/g, '')).toBe('hello');
});

test('empty string returns empty', () => {
expect(truncateAnsi('', 10)).toBe('');
});

test('exact width returns unchanged', () => {
expect(truncateAnsi('abcde', 5)).toBe('abcde');
});
});

describe('getFileIcon', () => {
test('.ts extension', () => {
expect(getFileIcon('src/foo.ts')).toBe('\ue628');
});

test('.tsx extension', () => {
expect(getFileIcon('Component.tsx')).toBe('\ue7ba');
});

test('unknown extension returns default', () => {
expect(getFileIcon('file.xyz')).toBe('\uf15b');
});

test('Dockerfile without extension', () => {
expect(getFileIcon('Dockerfile')).toBe('\ue7b0');
});

test('Dockerfile with suffix', () => {
expect(getFileIcon('Dockerfile.prod')).toBe('\ue7b0');
});

test('.gitignore', () => {
expect(getFileIcon('.gitignore')).toBe('\ue702');
});

test('case-insensitive extension', () => {
expect(getFileIcon('README.MD')).toBe('\ue73e');
});
});

describe('binarySearchBoundary', () => {
test('single boundary', () => {
expect(binarySearchBoundary([0], 5)).toBe(0);
});

test('exact match returns that index', () => {
expect(binarySearchBoundary([0, 10, 20], 10)).toBe(1);
});

test('between boundaries returns lower', () => {
expect(binarySearchBoundary([0, 10, 20], 15)).toBe(1);
});

test('before first boundary returns 0', () => {
expect(binarySearchBoundary([5, 10, 20], 2)).toBe(0);
});

test('after last boundary returns last index', () => {
expect(binarySearchBoundary([0, 10, 20], 100)).toBe(2);
});

test('at first boundary returns 0', () => {
expect(binarySearchBoundary([0, 10, 20], 0)).toBe(0);
});

test('at last boundary returns last index', () => {
expect(binarySearchBoundary([0, 10, 20], 20)).toBe(2);
});
});

function makeDiffFile(fileNameB: string): DiffFile {
return {
displayName: fileNameB,
fileNameA: '',
fileNameB,
additions: 0,
deletions: 0,
startLineIndex: 0,
};
}

describe('buildTree', () => {
test('single file at root', () => {
const tree = buildTree([makeDiffFile('README.md')]);
expect(tree).toHaveLength(1);
expect(tree[0].type).toBe('file');
expect(tree[0].name).toBe('README.md');
});

test('nested file creates dir nodes', () => {
const tree = buildTree([makeDiffFile('src/tui/App.ts')]);
expect(tree).toHaveLength(1);
expect(tree[0].type).toBe('dir');
expect(tree[0].name).toBe('src');
const src = tree[0] as { children: any[] };
expect(src.children[0].type).toBe('dir');
expect(src.children[0].name).toBe('tui');
});

test('sibling files share dir node', () => {
const tree = buildTree([
makeDiffFile('src/a.ts'),
makeDiffFile('src/b.ts'),
]);
expect(tree).toHaveLength(1);
expect(tree[0].type).toBe('dir');
const src = tree[0] as { children: any[] };
expect(src.children).toHaveLength(2);
});
});

describe('flattenVisible', () => {
test('returns dirs and files in order', () => {
const tree = buildTree([
makeDiffFile('src/a.ts'),
makeDiffFile('src/b.ts'),
makeDiffFile('README.md'),
]);
const visible = flattenVisible(tree);
// dir 'src', file 'a.ts', file 'b.ts', file 'README.md'
expect(visible).toHaveLength(4);
expect(visible[0].type).toBe('dir');
expect(visible[1].type).toBe('file');
expect(visible[2].type).toBe('file');
expect(visible[3].type).toBe('file');
});

test('collapsed dir hides children', () => {
const tree = buildTree([
makeDiffFile('src/a.ts'),
makeDiffFile('README.md'),
]);
// Collapse 'src'
const srcDir = tree[0] as { expanded: boolean };
srcDir.expanded = false;
const visible = flattenVisible(tree);
// dir 'src' (collapsed), file 'README.md'
expect(visible).toHaveLength(2);
expect(visible[0].type).toBe('dir');
expect(visible[1].type).toBe('file');
expect(visible[1].node.name).toBe('README.md');
});
});