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 / views / detail / detail-view.test.ts
88 lines · 2.2 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Views from '../../../hooks/views'
4import Fixtures from '../../fixtures'
5
6tier('builtin')
7
8describe('detail-view', () => {
9 test('hunks draw as one diff Code named by the path', async ($, on) => {
10 Fixtures.drawsPane(on, kit =>
11 Views.detailView(
12 kit,
13 {
14 words: { untrackedNoteOf: () => [] },
15 path: 'src/app/config.ts',
16 renamedFrom: null,
17 isUntracked: false,
18 isBinary: false,
19 body: {
20 hunks: [
21 {
22 oldStart: 1,
23 newStart: 1,
24 lines: [' a = 1', '-b = 2', '+b = 3', ' c = 4'],
25 },
26 {
27 oldStart: Fixtures.BIG_LINES,
28 newStart: Fixtures.BIG_LINES,
29 lines: [' x = 1', '+y = 2'],
30 },
31 ],
32 isTruncated: false,
33 isLarge: false,
34 },
35 bodyState: 'ready',
36 isArmed: false,
37 },
38 Fixtures.noop,
39 ),
40 )
41
42 const tree = await $.ui.render(Fixtures.VIEW_PANE)
43
44 expect(Fixtures.codesIn(tree)).toEqual([
45 {
46 source: [
47 '@@ -1,3 +1,3 @@',
48 ' a = 1',
49 '-b = 2',
50 '+b = 3',
51 ' c = 4',
52 '@@ -1000,1 +1000,2 @@',
53 ' x = 1',
54 '+y = 2',
55 ].join('\n'),
56 format: 'diff',
57 path: 'src/app/config.ts',
58 },
59 ])
60
61 expect(Fixtures.isDrawn(tree), 'the engine took the tree').toBe(true)
62 expect(Fixtures.jsonOf(tree)).not.toContain('truncated')
63 })
64
65 test("the name sits over the built-in's dim rule", async ($, on) => {
66 let isUntracked = false
67
68 Fixtures.drawsPane(on, kit =>
69 Views.detailView(
70 kit,
71 Fixtures.configDetailOf(isUntracked),
72 Fixtures.noop,
73 ),
74 )
75
76 for (const untracked of [false, true]) {
77 isUntracked = untracked
78
79 const [name, rule, body] = Fixtures.childrenOf(
80 await $.ui.render(Fixtures.VIEW_PANE),
81 )
82
83 expect(Fixtures.stringsOf(name)).toContain('src/app/config.ts')
84 expect(Fixtures.stringsOf(rule)).toEqual(['─'.repeat(Fixtures.COLUMNS)])
85 expect(body).toBeDefined()
86 }
87 })
88})