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.test.ts
105 lines · 3.4 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Fixtures from './fixtures'
4
5tier('builtin')
6
7describe('views', () => {
8 test('docked, every file has its hunks under the list', async ($, on) => {
9 const world = Fixtures.inRepository(on, Fixtures.TWO_FILES)
10
11 await $.session.start(Fixtures.SESSION)
12 await $.command.run(Fixtures.DIFF)
13 await world.clock.advance(Fixtures.SETTLE_MS)
14
15 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.PANE))
16
17 expect(drawn).toContain('2 files changed +3 -1')
18 expect(drawn).toContain('+const a = 2')
19 expect(drawn).toContain('+export const c = 2')
20 expect(drawn).not.toContain('❯')
21 })
22
23 test('inline, a row moves the pointer and the body to it', async ($, on) => {
24 const world = Fixtures.inRepository(on, Fixtures.TWO_FILES)
25
26 await $.session.start(Fixtures.SESSION)
27 await $.command.run(Fixtures.DIFF)
28 await world.clock.advance(Fixtures.SETTLE_MS)
29 await $.ui.render(Fixtures.INLINE_PANE)
30
31 expect(await $.ui.press({ plugin: 'diff', key: 'file:lib.ts' })).toEqual({
32 element: 'file:lib.ts',
33 })
34
35 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))
36
37 expect(drawn).toContain('\u276f lib.ts')
38 expect(drawn).toContain('+export const c = 2')
39 expect(drawn).not.toContain('+const a = 2')
40 })
41
42 test('past eight files the docked list counts the rest', async ($, on) => {
43 const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
44
45 await $.session.start(Fixtures.SESSION)
46 await $.command.run(Fixtures.DIFF)
47 await world.clock.advance(Fixtures.SETTLE_MS)
48
49 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.PANE))
50
51 expect(drawn).toContain('10 files changed +10 -10')
52 expect(drawn).toContain('file7.ts')
53 expect(drawn).toContain('↓ 2 more below')
54
55 expect(drawn.indexOf('↓ 2 more below')).toBeLessThan(
56 drawn.indexOf('file8.ts'),
57 )
58 })
59
60 test('a rename lists as git prints it, and reads no body', async ($, on) => {
61 const world = Fixtures.inRepository(on, Fixtures.RENAMED)
62
63 await $.session.start(Fixtures.SESSION)
64 await $.command.run(Fixtures.DIFF)
65 await world.clock.advance(Fixtures.SETTLE_MS)
66
67 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.PANE))
68
69 expect(drawn).toContain('1 file changed')
70 expect(drawn).toContain('docs/{notes.txt => renamed-notes.txt}')
71 expect(drawn).toContain('No diff content')
72
73 expect(
74 world.runs.filter(run => run.argv.includes('docs/renamed-notes.txt')),
75 ).toEqual([])
76 })
77
78 test('inline on a wide terminal, the rows round one file', async ($, on) => {
79 const world = Fixtures.inRepository(on, Fixtures.TWO_FILES)
80
81 await $.session.start(Fixtures.SESSION)
82 await $.command.run(Fixtures.DIFF)
83 await world.clock.advance(Fixtures.SETTLE_MS)
84
85 const drawn = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))
86
87 expect(drawn).toContain('❯ app.ts')
88 expect(drawn).toContain('+const a = 2')
89 expect(drawn).not.toContain('+export const c = 2')
90 })
91
92 test('inline on a narrow terminal, the resize line', async ($, on) => {
93 const world = Fixtures.inRepository(on, Fixtures.TWO_FILES)
94
95 await $.session.start(Fixtures.SESSION)
96 await $.command.run(Fixtures.DIFF)
97 await world.clock.advance(Fixtures.SETTLE_MS)
98
99 expect(
100 Fixtures.textOf(await $.ui.render(Fixtures.NARROW_INLINE_PANE)),
101 ).toBe(
102 'Resize your terminal to at least 110 columns to show the diff panel',
103 )
104 })
105})