diff options
| author | Anas Sulaiman <[email protected]> | 2025-06-10 18:05:44 +0000 |
|---|---|---|
| committer | Anas H. Sulaiman <[email protected]> | 2025-06-11 09:47:11 -0400 |
| commit | 9d992b32e48625ace24789e23f814c1e4430c5f2 (patch) | |
| tree | 23fd9469bc51ac4145fcf94cccfe036ef08c420a /packages/cli/src/ui/components/messages/DiffRenderer.test.tsx | |
| parent | 00c4527a1b4177699b4d512053dff2578572676f (diff) | |
add a unit test with multiple hunks for diff renderer
Diffstat (limited to 'packages/cli/src/ui/components/messages/DiffRenderer.test.tsx')
| -rw-r--r-- | packages/cli/src/ui/components/messages/DiffRenderer.test.tsx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx b/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx index 39c327e7..c6ecc279 100644 --- a/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx +++ b/packages/cli/src/ui/components/messages/DiffRenderer.test.tsx @@ -170,4 +170,42 @@ index abc..def 100644 expect(output).toContain('context line 5'); expect(output).toContain('context line 11'); }); + + it('should correctly render a diff with multiple hunks and a gap indicator', () => { + const diffWithMultipleHunks = ` +diff --git a/multi.js b/multi.js +index 123..789 100644 +--- a/multi.js ++++ b/multi.js +@@ -1,3 +1,3 @@ + console.log('first hunk'); +-const oldVar = 1; ++const newVar = 1; + console.log('end of first hunk'); +@@ -20,3 +20,3 @@ + console.log('second hunk'); +-const anotherOld = 'test'; ++const anotherNew = 'test'; + console.log('end of second hunk'); +`; + const { lastFrame } = render( + <DiffRenderer diffContent={diffWithMultipleHunks} filename="multi.js" />, + ); + const output = lastFrame(); + + // Check for content from the first hunk + expect(output).toContain("1 console.log('first hunk');"); + expect(output).toContain('2 - const oldVar = 1;'); + expect(output).toContain('2 + const newVar = 1;'); + expect(output).toContain("3 console.log('end of first hunk');"); + + // Check for the gap indicator between hunks + expect(output).toContain('═'); + + // Check for content from the second hunk + expect(output).toContain("20 console.log('second hunk');"); + expect(output).toContain("21 - const anotherOld = 'test';"); + expect(output).toContain("21 + const anotherNew = 'test';"); + expect(output).toContain("22 console.log('end of second hunk');"); + }); }); |
