2021-03-14 10:38:59 +02:00
|
|
|
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
|
2021-03-21 01:23:14 +02:00
|
|
|
root *models.FileChangeNode
|
2021-03-14 10:38:59 +02:00
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil node",
|
|
|
|
root: nil,
|
|
|
|
expected: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "leaf node",
|
2021-03-21 01:23:14 +02:00
|
|
|
root: &models.FileChangeNode{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "",
|
2021-03-21 01:23:14 +02:00
|
|
|
Children: []*models.FileChangeNode{
|
2021-03-21 01:03:51 +02:00
|
|
|
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []string{" M test"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "big example",
|
2021-03-21 01:23:14 +02:00
|
|
|
root: &models.FileChangeNode{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "",
|
2021-03-21 01:23:14 +02:00
|
|
|
Children: []*models.FileChangeNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "dir1",
|
2021-03-14 10:38:59 +02:00
|
|
|
Collapsed: true,
|
2021-03-21 01:23:14 +02:00
|
|
|
Children: []*models.FileChangeNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
|
|
|
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "file2",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "dir2",
|
2021-03-21 01:23:14 +02:00
|
|
|
Children: []*models.FileChangeNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "dir2",
|
2021-03-21 01:23:14 +02:00
|
|
|
Children: []*models.FileChangeNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
|
|
|
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "file3",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
File: &models.File{Name: "file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "file4",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "file5",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
File: &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true},
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "file1",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2021-03-21 01:23:14 +02:00
|
|
|
mngr := &FileChangeManager{Tree: s.root}
|
2021-03-14 10:38:59 +02:00
|
|
|
result := mngr.Render("", nil)
|
|
|
|
assert.EqualValues(t, s.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|