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