diff --git a/src/components/CallHistoryRow.test.tsx b/src/components/CallHistoryRow.test.tsx index 246795f..5146ecc 100644 --- a/src/components/CallHistoryRow.test.tsx +++ b/src/components/CallHistoryRow.test.tsx @@ -114,6 +114,25 @@ describe('CallHistoryRow', () => { expect(screen.queryByRole('region', { name: 'Call details' })).toBeNull(); }); + it('renders response diff lines when a comparison response is available', () => { + const callWithDiff: CallRecord = { + ...successCall, + compareResponse: { name: 'Alice', plan: 'Free' }, + response: { name: 'Alice', plan: 'Pro' }, + }; + + renderRow({ call: callWithDiff, expanded: true, onToggleExpand: () => {} }); + + expect(screen.getByLabelText('Response diff')).toBeTruthy(); + expect(screen.getByText(/-.*"plan": "Free"/)).toBeTruthy(); + expect(screen.getByText(/\+.*"plan": "Pro"/)).toBeTruthy(); + }); + + it('does not render response diff when no comparison response is available', () => { + renderRow({ call: successCall, expanded: true, onToggleExpand: () => {} }); + expect(screen.queryByLabelText('Response diff')).toBeNull(); + }); + // ── Data rendering ─────────────────────────────────────────────────────── it('displays the endpoint path', () => { diff --git a/src/components/CallHistoryRow.tsx b/src/components/CallHistoryRow.tsx index 523fb87..a6de951 100644 --- a/src/components/CallHistoryRow.tsx +++ b/src/components/CallHistoryRow.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react'; import { CheckCircle, XCircle } from 'lucide-react'; import { formatPrice } from '../utils/format'; +import { buildJsonDiff } from '../utils/diff'; export type CallRecord = { id: string; @@ -11,6 +11,7 @@ export type CallRecord = { cost: number; request?: unknown; response?: unknown; + compareResponse?: unknown; }; type Props = { @@ -55,6 +56,34 @@ function StatusIcon({ status }: { status: 'success' | 'error' }) { ); } +function ResponseDiff({ before, after }: { before: unknown; after: unknown }) { + const lines = buildJsonDiff(before, after); + + return ( +
+ {lines.map((line, index) => {
+ const prefix =
+ line.type === 'added' ? '+ ' : line.type === 'removed' ? '- ' : ' ';
+
+ return (
+
+ {prefix}
+ {line.text}
+ {'\n'}
+
+ );
+ })}
+
+ {JSON.stringify(call.response ?? {}, null, 2)}
+ {call.compareResponse !== undefined && (
+