module view import src.events import src.history import src.snapshot fn save(id string, message string, checkpoint bool) history.Save { return history.Save{ id: id message: message created_at: 1790000000 size_bytes: 1024 is_checkpoint: checkpoint } } fn line_map(ids []string) map[string]bool { mut out := map[string]bool{} for id in ids { out[id] = true } return out } fn test_tabs_filter_by_what_is_on_the_line() { on_the_line := line_map(['aaa', 'ccc']) mut replayed := save('bbb', 'replayed away', false) replayed.replayed_from = 'aaa' items := [save('aaa', 'first', false), replayed, save('ccc', 'before things', true)] assert filter_saves(items, .all, on_the_line, '').len == 3 // A replayed-away save exists in history but is on neither live list. assert filter_saves(items, .saves, on_the_line, '').map(it.id) == ['aaa', 'ccc'] assert filter_saves(items, .checkpoints, on_the_line, '').map(it.id) == ['ccc'] } fn test_search_is_case_insensitive_across_the_fields() { on_the_line := line_map(['aaa', 'bbb', 'ccc']) mut with_agent := save('bbb', 'fix chunk boundary', false) with_agent.agent = 'DeepSeek/Flash' mut with_session := save('ccc', 'other work', false) with_session.session = 'phase one' items := [save('aaa', 'add storage', false), with_agent, with_session] assert filter_saves(items, .all, on_the_line, 'STORAGE').map(it.id) == ['aaa'] assert filter_saves(items, .all, on_the_line, 'chunk').map(it.id) == ['bbb'] assert filter_saves(items, .all, on_the_line, 'deepseek').map(it.id) == ['bbb'] assert filter_saves(items, .all, on_the_line, 'PHASE').map(it.id) == ['ccc'] assert filter_saves(items, .all, on_the_line, 'nothing here').len == 0 } fn test_move_selection_clamps_at_both_ends() { assert move_selection(0, 1, 3) == 1 assert move_selection(2, 1, 3) == 2 assert move_selection(0, -1, 3) == 0 assert move_selection(0, 0, 0) == 0 assert move_selection(5, 1, 0) == 0 // G asks for a move past the end and lands on the last entry. assert move_selection(3, -1, 3) == 2 } fn test_detail_lists_files_with_stats_and_notes_binaries() { target := save('aaa', 'change two files', false) flag := events.Flag{ save_id: 'aaa' flagged: true reason: 'sketchy' } deltas := [ snapshot.Delta{ path: 'src/main.v' kind: 'modified' added: 4 removed: 2 }, snapshot.Delta{ path: 'logo.png' kind: 'added' binary: true }, ] text := detail_lines(target, deltas, flag).join('\n') assert text.contains('checksum aaa') assert text.contains('flag sketchy') assert text.contains('src/main.v') assert text.contains('+4') assert text.contains('-2') assert text.contains('logo.png') assert text.contains('(binary)') assert text.contains('2 files changed against the parent') } fn test_detail_says_so_when_nothing_changed() { target := save('aaa', 'first save', false) text := detail_lines(target, [], events.Flag{ save_id: 'aaa' }).join('\n') assert text.contains('nothing changed against the parent') } fn test_frame_shows_counts_the_selected_entry_and_the_status_bar() { on_the_line := line_map(['aaa', 'ccc']) items := [save('aaa', 'first', false), save('ccc', 'before storage', true)] screen := Screen{ tab: .all items: items selected: 1 on_line: on_the_line counts: count_tabs(items, on_the_line) rows: 24 cols: 100 status: '3 shown' } text := frame_lines(screen).join('\n') assert text.contains('all (2)') assert text.contains('checkpoints (1)') assert text.contains('before storage') assert text.contains('aaa') // The selected entry carries its extra line. assert text.contains('agent') assert text.contains('◐') assert text.contains('3 shown') } fn test_frame_says_no_results_when_the_search_matches_nothing() { screen := Screen{ tab: .all rows: 24 cols: 80 query: 'nothing matches this' counts: TabCounts{} } text := frame_lines(screen).join('\n') assert text.contains('no results') assert text.contains('/nothing matches this') } fn test_render_clears_each_line_before_drawing_it() { screen := Screen{ tab: .saves rows: 6 cols: 60 } frame := render(screen) assert frame.starts_with('\x1b[H') // One line-clear per row drawn, so a shorter frame cannot leave the tail of // a longer one behind. assert frame.count('\x1b[2K') == frame_lines(screen).len }