summaryrefslogtreecommitdiffstats
path: root/pkg/gui/status_line_manager_test.go
blob: 7ef5c15e6314ecec7130d59c72b6149b5dea0051 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
package gui

import (
	"testing"

	"github.com/jesseduffield/lazygit/pkg/commands/models"
	"github.com/stretchr/testify/assert"
)

func TestRender(t *testing.T) {
	scenarios := []struct {
		name     string
		root     *models.StatusLineNode
		expected []string
	}{
		{
			name:     "nil node",
			root:     nil,
			expected: []string{},
		},
		{
			name: "leaf node",
			root: &models.StatusLineNode{
				Path: "",
				Children: []*models.StatusLineNode{
					{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
				},
			},
			expected: []string{" M test"},
		},
		{
			name: "big example",
			root: &models.StatusLineNode{
				Path: "",
				Children: []*models.StatusLineNode{
					{
						Path:      "dir1",
						Collapsed: true,
						Children: []*models.StatusLineNode{
							{
								File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
								Path: "file2",
							},
						},
					},
					{
						Path: "dir2",
						Children: []*models.StatusLineNode{
							{
								Path: "dir2",
								Children: []*models.StatusLineNode{
									{
										File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
										Path: "file3",
									},
									{
										File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
										Path: "file4",
									},
								},
							},
							{
								File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
								Path: "file5",
							},
						},
					},
					{
						File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
						Path: "file1",
					},
				},
			},

			expected: []string{" M dir1 ►", "MM dir2 ▼", "├─ MM dir2 ▼", "│   ├─  M file3", "│   └─ M  file4", "└─ M  file5", "M  file1"},
		},
	}

	for _, s := range scenarios {
		s := s
		t.Run(s.name, func(t *testing.T) {
			mngr := &StatusLineManager{Tree: s.root}
			result := mngr.Render("", nil)
			assert.EqualValues(t, s.expected, result)
		})
	}
}