File size: 2,136 Bytes
776286d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { describe, expect, test, tier } from 'claude-code/testing'

import Git from '../../hooks/git'
import PaneState from '../../hooks/pane-state'
import Fixtures from '../fixtures'

tier('builtin')

describe('empty-state-of', () => {
  const dataIn = (
    mode: Git.BaseMode,
    overrides: Partial<Git.DiffData> = {},
  ): Git.DiffData => ({
    repository: Fixtures.CHECKOUT,
    mode,
    stats: Fixtures.NO_STATS,
    files: [],
    source: { kind: 'working-tree', base: 'HEAD' },
    isUnborn: false,
    baseRef: 'HEAD',
    stalePaths: [],
    isUntrackedWithheld: false,
    ...overrides,
  })

  const emptyOf = (data: Git.DiffData | null, filesCount: number) =>
    PaneState.emptyStateOf({ data, words: Git.GIT_WORDS }, filesCount)

  test("the built-in's headlines, keyed on the fetched mode", () => {
    expect(emptyOf(null, 0)?.headline).toBe('Diff unavailable')

    expect(emptyOf(dataIn('session'), 0)).toEqual({
      headline: 'No changes this session',
      hint: null,
    })

    expect(emptyOf(dataIn('uncommitted'), 0)?.headline).toBe(
      'No uncommitted changes',
    )

    expect(
      emptyOf(dataIn('branch', { source: Fixtures.VS_MAIN }), 0)?.headline,
    ).toBe('No changes vs main')

    expect(emptyOf(dataIn('branch'), 0)).toEqual({
      headline: 'No changes vs HEAD',
      hint: 'No base branch to compare against — showing changes vs HEAD',
    })

    expect(emptyOf(dataIn('session', { isUnborn: true }), 0)).toEqual({
      headline: 'No commits yet',
      hint: "Nothing to diff against until the repo's first commit",
    })
  })

  test('with files to count there is no empty state', () => {
    expect(emptyOf(dataIn('session'), 2)).toBeNull()
  })

  test('no tracked rows, untracked withheld: claims no more', () => {
    const withheld = { isUntrackedWithheld: true }

    expect(emptyOf(dataIn('session', withheld), 0)?.headline).toBe(
      'No tracked changes',
    )

    expect(
      emptyOf(dataIn('session', { ...withheld, isUnborn: true }), 0)?.headline,
    ).toBe('No tracked changes')

    expect(emptyOf(dataIn('uncommitted', withheld), 1)).toBeNull()
  })
})