mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 10:27:33 +00:00
* fix(mobile): compare branches and show diffs with desktop's base-ref and whitespace settings Base-ref resolution moves to src/shared and the host publishes the compare-against-upstream and show-whitespace settings, so the phone's branch compare and diffs match desktop. * fix(mobile): use the upstream compare policy on the review screen and rebuild diffs when whitespace changes * fix(mobile): reread Source Control settings on Refresh and restart diffs loading under the old whitespace setting * test(mobile): cover diffs dropped when desktop's whitespace setting arrives * refactor(mobile): share one Source Control settings read per host across screens
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { buildMobileDiffLines } from './mobile-diff-lines'
|
|
|
|
describe('buildMobileDiffLines', () => {
|
|
it('marks added, deleted, and unchanged lines', () => {
|
|
const result = buildMobileDiffLines('one\ntwo\nthree\n', 'one\nTWO\nthree\nfour\n')
|
|
|
|
expect(result.truncated).toBe(false)
|
|
expect(result.lines).toEqual([
|
|
{ kind: 'context', text: 'one', oldLineNumber: 1, newLineNumber: 1 },
|
|
{ kind: 'delete', text: 'two', oldLineNumber: 2 },
|
|
{ kind: 'add', text: 'TWO', newLineNumber: 2 },
|
|
{ kind: 'context', text: 'three', oldLineNumber: 3, newLineNumber: 3 },
|
|
{ kind: 'add', text: 'four', newLineNumber: 4 }
|
|
])
|
|
})
|
|
|
|
it('caps add-only preview rows before returning the mobile truncation marker', () => {
|
|
const modified = Array.from({ length: 3_000 }, (_, index) => `line-${index + 1}`).join('\n')
|
|
|
|
const result = buildMobileDiffLines('', `${modified}\n`)
|
|
|
|
expect(result.truncated).toBe(true)
|
|
expect(result.lines).toHaveLength(2_501)
|
|
expect(result.lines[0]).toEqual({ kind: 'add', text: 'line-1', newLineNumber: 1 })
|
|
expect(result.lines[2_499]).toEqual({ kind: 'add', text: 'line-2500', newLineNumber: 2500 })
|
|
expect(result.lines[2_500]).toEqual({
|
|
kind: 'context',
|
|
text: '... diff truncated for mobile preview ...'
|
|
})
|
|
})
|
|
|
|
it('caps prefix-suffix fallback rows for very large changed files', () => {
|
|
const original = Array.from({ length: 3_000 }, (_, index) => `old-${index + 1}`).join('\n')
|
|
const modified = Array.from({ length: 3_000 }, (_, index) => `new-${index + 1}`).join('\n')
|
|
|
|
const result = buildMobileDiffLines(`${original}\n`, `${modified}\n`)
|
|
|
|
expect(result.truncated).toBe(true)
|
|
expect(result.lines).toHaveLength(2_501)
|
|
expect(result.lines[0]).toEqual({ kind: 'delete', text: 'old-1', oldLineNumber: 1 })
|
|
expect(result.lines[2_499]).toEqual({
|
|
kind: 'delete',
|
|
text: 'old-2500',
|
|
oldLineNumber: 2500
|
|
})
|
|
expect(result.lines[2_500]).toEqual({
|
|
kind: 'context',
|
|
text: '... diff truncated for mobile preview ...'
|
|
})
|
|
})
|
|
|
|
it('hides a re-indent unless whitespace is shown, like desktop', () => {
|
|
const original = 'if (a) {\n run()\n}\n'
|
|
const modified = 'if (a) {\n run()\n}\n'
|
|
const kinds = (lines: { kind: string }[]) => lines.map((line) => line.kind)
|
|
expect(
|
|
kinds(buildMobileDiffLines(original, modified, { ignoreTrimWhitespace: true }).lines)
|
|
).toEqual(['context', 'context', 'context'])
|
|
expect(kinds(buildMobileDiffLines(original, modified).lines)).toEqual([
|
|
'context',
|
|
'delete',
|
|
'add',
|
|
'context'
|
|
])
|
|
})
|
|
})
|