diff options
author | Liberatys <nick.flueckiger@renuo.ch> | 2021-08-03 22:44:43 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-08-25 20:13:50 +1000 |
commit | 6b68f4f25d3c717d8540ce7ac5b2ccf4b82e41e3 (patch) | |
tree | 30b6f2f4dc4a29177434ecad3ac0914269aa77cf /pkg/gui/filetree | |
parent | 89ee0a1dee9101668cc4cb177aafc156faa5f35b (diff) |
Update as per review and add tests
Diffstat (limited to 'pkg/gui/filetree')
-rw-r--r-- | pkg/gui/filetree/file_manager_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/pkg/gui/filetree/file_manager_test.go b/pkg/gui/filetree/file_manager_test.go index 2e19e94ea..a365a37b5 100644 --- a/pkg/gui/filetree/file_manager_test.go +++ b/pkg/gui/filetree/file_manager_test.go @@ -93,3 +93,62 @@ func TestRender(t *testing.T) { }) } } + +func TestFilterAction(t *testing.T) { + scenarios := []struct { + name string + filter FileManagerDisplayFilter + files []*models.File + expected []*models.File + }{ + { + name: "filter files with unstaged changes", + filter: DisplayUnstaged, + files: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: true}, + &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + }, + expected: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + }, + }, + { + name: "filter files with staged changes", + filter: DisplayStaged, + files: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, + &models.File{Name: "dir2/file5", ShortStatus: "M ", HasStagedChanges: false}, + &models.File{Name: "file1", ShortStatus: "M ", HasStagedChanges: true}, + }, + expected: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasStagedChanges: true}, + &models.File{Name: "file1", ShortStatus: "M ", HasStagedChanges: true}, + }, + }, + { + name: "filter all files", + filter: DisplayAll, + files: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + }, + expected: []*models.File{ + &models.File{Name: "dir2/dir2/file4", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "dir2/file5", ShortStatus: "M ", HasUnstagedChanges: true}, + &models.File{Name: "file1", ShortStatus: "M ", HasUnstagedChanges: true}, + }, + }, + } + + for _, s := range scenarios { + s := s + t.Run(s.name, func(t *testing.T) { + mngr := &FileManager{files: s.files, filter: s.filter} + result := mngr.GetFilesForDisplay() + assert.EqualValues(t, s.expected, result) + }) + } +} |