2021-03-21 06:25:29 +02:00
|
|
|
package filetree
|
2021-03-14 10:38:59 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRender(t *testing.T) {
|
|
|
|
scenarios := []struct {
|
2021-03-21 06:01:13 +02:00
|
|
|
name string
|
2021-03-31 14:26:53 +02:00
|
|
|
root *FileNode
|
2021-03-21 06:01:13 +02:00
|
|
|
collapsedPaths map[string]bool
|
|
|
|
expected []string
|
2021-03-14 10:38:59 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil node",
|
|
|
|
root: nil,
|
|
|
|
expected: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "leaf node",
|
2021-03-31 14:26:53 +02:00
|
|
|
root: &FileNode{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
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-31 14:26:53 +02:00
|
|
|
root: &FileNode{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 06:01:13 +02:00
|
|
|
Path: "dir1",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 02:26:16 +02:00
|
|
|
File: &models.File{Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
|
|
Path: "dir1/file2",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
2021-03-21 06:01:13 +02:00
|
|
|
{
|
|
|
|
File: &models.File{Name: "dir1/file3", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
|
|
Path: "dir1/file3",
|
|
|
|
},
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-21 01:03:51 +02:00
|
|
|
Path: "dir2",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 02:26:16 +02:00
|
|
|
Path: "dir2/dir2",
|
2021-03-31 14:26:53 +02:00
|
|
|
Children: []*FileNode{
|
2021-03-14 10:38:59 +02:00
|
|
|
{
|
2021-03-21 02:26:16 +02:00
|
|
|
File: &models.File{Name: "dir2/dir2/file3", ShortStatus: " M", HasStagedChanges: true},
|
|
|
|
Path: "dir2/dir2/file3",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
{
|
2021-03-21 02:26:16 +02:00
|
|
|
File: &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
|
|
Path: "dir2/dir2/file4",
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-21 02:26:16 +02:00
|
|
|
File: &models.File{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true},
|
|
|
|
Path: "dir2/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
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-21 06:01:13 +02:00
|
|
|
expected: []string{"dir1 ►", "dir2 ▼", "├─ dir2 ▼", "│ ├─ M file3", "│ └─ M file4", "└─ M file5", "M file1"},
|
|
|
|
collapsedPaths: map[string]bool{"dir1": true},
|
2021-03-14 10:38:59 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
s := s
|
|
|
|
t.Run(s.name, func(t *testing.T) {
|
2021-03-31 14:26:53 +02:00
|
|
|
mngr := &FileManager{tree: s.root, collapsedPaths: s.collapsedPaths}
|
2021-03-14 10:38:59 +02:00
|
|
|
result := mngr.Render("", nil)
|
|
|
|
assert.EqualValues(t, s.expected, result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|