spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / pane-state / header-totals-of.test.ts
74 lines · 2.0 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import type Git from '../../hooks/git'
4import PaneState from '../../hooks/pane-state'
5import Fixtures from '../fixtures'
6
7tier('builtin')
8
9describe('header-totals-of', () => {
10 const dataOf = (
11 files: readonly Git.FileStat[],
12 filesCount: number,
13 ): Git.DiffData => ({
14 repository: Fixtures.CHECKOUT,
15 mode: 'session',
16 stats: {
17 filesCount,
18 linesAdded: files.reduce((sum, each) => sum + each.added, 0),
19 linesRemoved: files.reduce((sum, each) => sum + each.removed, 0),
20 },
21 files,
22 source: { kind: 'working-tree', base: 'HEAD' },
23 isUnborn: false,
24 baseRef: 'HEAD',
25 stalePaths: [],
26 isUntrackedWithheld: false,
27 })
28
29 test('pre-session rows leave the header; the rest is not shown', () => {
30 const data = dataOf(
31 [Fixtures.SESSION_ROW, Fixtures.PRE_SESSION_ROW],
32 Fixtures.REPORTED_COUNT,
33 )
34
35 expect(
36 PaneState.headerTotalsOf(
37 data,
38 PaneState.partitionOf(data.files, 'hidden'),
39 ),
40 ).toEqual({ filesCount: 3, linesAdded: 3, linesRemoved: 1, notShown: 2 })
41 })
42
43 test('every stored row pre-session: files past the cap still count', () => {
44 const stored = Array.from({ length: Fixtures.STORED_COUNT }, (_, at) => ({
45 ...Fixtures.PRE_SESSION_ROW,
46 path: `old${at}.ts`,
47 }))
48
49 const pastCap = Fixtures.PAST_CAP_COUNT - Fixtures.STORED_COUNT
50
51 expect(
52 PaneState.headerTotalsOf(
53 dataOf(stored, Fixtures.PAST_CAP_COUNT),
54 PaneState.partitionOf(stored, 'hidden'),
55 ),
56 ).toEqual({
57 filesCount: pastCap,
58 linesAdded: 0,
59 linesRemoved: 0,
60 notShown: pastCap,
61 })
62 })
63
64 test('tests count as noise and leave the shown rows', () => {
65 const partition = PaneState.partitionOf(
66 [Fixtures.SESSION_ROW, Fixtures.TEST_ROW],
67 'hidden',
68 )
69
70 expect(partition.shown.map(each => each.path)).toEqual(['src/a.ts'])
71 expect(partition.noiseCount).toBe(1)
72 expect(PaneState.partitionOf(partition.shown, 'shown').noiseCount).toBe(0)
73 })
74})