mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-04 10:34:55 +02:00
Update as per review and add tests
This commit is contained in:
parent
89ee0a1dee
commit
6b68f4f25d
@ -474,30 +474,28 @@ func (gui *Gui) handleCommitEditorPress() error {
|
||||
}
|
||||
|
||||
func (gui *Gui) handleStatusFilterPressed() error {
|
||||
menuItems := []*menuItem{}
|
||||
|
||||
menuItems = append(menuItems, &menuItem{
|
||||
displayString: gui.Tr.FilterStagedFiles,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayStaged)
|
||||
menuItems := []*menuItem{
|
||||
{
|
||||
displayString: gui.Tr.FilterStagedFiles,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayStaged)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
menuItems = append(menuItems, &menuItem{
|
||||
displayString: gui.Tr.FilterUnstagedFiles,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayUnstaged)
|
||||
{
|
||||
displayString: gui.Tr.FilterUnstagedFiles,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayUnstaged)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
menuItems = append(menuItems, &menuItem{
|
||||
displayString: gui.Tr.ResetCommitFilterState,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayAll)
|
||||
{
|
||||
displayString: gui.Tr.ResetCommitFilterState,
|
||||
onPress: func() error {
|
||||
return gui.setStatusFiltering(filetree.DisplayAll)
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return gui.createMenu(gui.Tr.FilteringMenuTitle, menuItems, createMenuOptions{showCancel: false})
|
||||
return gui.createMenu(gui.Tr.FilteringMenuTitle, menuItems, createMenuOptions{showCancel: true })
|
||||
}
|
||||
|
||||
func (gui *Gui) setStatusFiltering(filter filetree.FileManagerDisplayFilter) error {
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ func polishTranslationSet() TranslationSet {
|
||||
LcAbortMerge: "o scalaniu",
|
||||
LcResolveMergeConflicts: "rozwiąż konflikty scalania",
|
||||
LcCommitFileFilter: "Filtrowanie plików commitować",
|
||||
FilterStagedFiles: "Show only staged files",
|
||||
FilterUnstagedFiles: "Show only unstaged files",
|
||||
ResetCommitFilterState: "Reset commit file state filter",
|
||||
FilterStagedFiles: "Pokaż tylko pliki etapowe",
|
||||
FilterUnstagedFiles: "Pokaż tylko niestageowane pliki",
|
||||
ResetCommitFilterState: "Resetuj filtr stanu pliku commit",
|
||||
LcCheckout: "przełącz",
|
||||
NoChangedFiles: "Brak zmienionych plików",
|
||||
FileHasNoUnstagedChanges: "Plik nie zawiera żadnych nieopublikowanych zmian do dodania",
|
||||
|
Loading…
Reference in New Issue
Block a user