diff --git a/pkg/commands/models/file_change_interface.go b/pkg/commands/models/file_change_interface.go index 5413b076f..76d313d1a 100644 --- a/pkg/commands/models/file_change_interface.go +++ b/pkg/commands/models/file_change_interface.go @@ -1,5 +1,6 @@ package models +// sometimes we need to deal with either a node (which contains a file) or an actual file type IFileChange interface { GetHasUnstagedChanges() bool GetHasStagedChanges() bool diff --git a/pkg/commands/models/file_change_node.go b/pkg/commands/models/file_change_node.go index d6f22d37f..0150e8d46 100644 --- a/pkg/commands/models/file_change_node.go +++ b/pkg/commands/models/file_change_node.go @@ -12,8 +12,7 @@ type FileChangeNode struct { Children []*FileChangeNode File *File Path string // e.g. '/path/to/mydir' - Collapsed bool - CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode + CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode } func (s *FileChangeNode) GetHasUnstagedChanges() bool { diff --git a/pkg/gui/file_change_manager_test.go b/pkg/gui/file_change_manager_test.go index 016f97ac2..f339aae0f 100644 --- a/pkg/gui/file_change_manager_test.go +++ b/pkg/gui/file_change_manager_test.go @@ -9,9 +9,10 @@ import ( func TestRender(t *testing.T) { scenarios := []struct { - name string - root *models.FileChangeNode - expected []string + name string + root *models.FileChangeNode + collapsedPaths map[string]bool + expected []string }{ { name: "nil node", @@ -34,13 +35,16 @@ func TestRender(t *testing.T) { Path: "", Children: []*models.FileChangeNode{ { - Path: "dir1", - Collapsed: true, + Path: "dir1", Children: []*models.FileChangeNode{ { File: &models.File{Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "dir1/file2", }, + { + File: &models.File{Name: "dir1/file3", ShortStatus: "M ", HasUnstagedChanges: true}, + Path: "dir1/file3", + }, }, }, { @@ -71,15 +75,15 @@ func TestRender(t *testing.T) { }, }, }, - - expected: []string{"dir1 ▼", "└─ M file2", "dir2 ▼", "├─ dir2 ▼", "│ ├─ M file3", "│ └─ M file4", "└─ M file5", "M file1"}, + expected: []string{"dir1 ►", "dir2 ▼", "├─ dir2 ▼", "│ ├─ M file3", "│ └─ M file4", "└─ M file5", "M file1"}, + collapsedPaths: map[string]bool{"dir1": true}, }, } for _, s := range scenarios { s := s t.Run(s.name, func(t *testing.T) { - mngr := &FileChangeManager{Tree: s.root} + mngr := &FileChangeManager{Tree: s.root, CollapsedPaths: s.collapsedPaths} result := mngr.Render("", nil) assert.EqualValues(t, s.expected, result) })