1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/cheatsheet/generate_test.go

270 lines
5.1 KiB
Go
Raw Normal View History

2022-03-20 04:59:33 +02:00
package cheatsheet
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/stretchr/testify/assert"
)
func TestGetBindingSections(t *testing.T) {
tr := i18n.EnglishTranslationSet()
tests := []struct {
testName string
bindings []*types.Binding
expected []*bindingSection
}{
{
testName: "no bindings",
bindings: []*types.Binding{},
expected: []*bindingSection{},
},
{
testName: "one binding",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
expected: []*bindingSection{
{
2022-03-26 05:44:30 +02:00
title: "Files",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
},
},
{
testName: "global binding",
bindings: []*types.Binding{
{
ViewName: "",
Description: "quit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
expected: []*bindingSection{
{
title: "Global Keybindings",
bindings: []*types.Binding{
{
ViewName: "",
Description: "quit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
},
},
{
testName: "grouped bindings",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "submodules",
2022-03-20 04:59:33 +02:00
Description: "drop submodule",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
expected: []*bindingSection{
{
2022-03-26 05:44:30 +02:00
title: "Files",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
{
2022-03-26 05:44:30 +02:00
title: "Submodules",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "submodules",
2022-03-20 04:59:33 +02:00
Description: "drop submodule",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
},
},
{
testName: "with navigation bindings",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "scroll",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
{
ViewName: "commits",
Description: "revert commit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
expected: []*bindingSection{
{
title: "List Panel Navigation",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "scroll",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
},
},
{
2022-03-26 05:44:30 +02:00
title: "Commits",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "commits",
Description: "revert commit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
{
2022-03-26 05:44:30 +02:00
title: "Files",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
},
},
{
testName: "with duplicate navigation bindings",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "scroll",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
{
ViewName: "commits",
Description: "revert commit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "commits",
Description: "scroll",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
{
ViewName: "commits",
Description: "page up",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
},
expected: []*bindingSection{
{
title: "List Panel Navigation",
bindings: []*types.Binding{
{
ViewName: "files",
Description: "scroll",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
{
ViewName: "commits",
Description: "page up",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
Tag: "navigation",
},
},
},
{
2022-03-26 05:44:30 +02:00
title: "Commits",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "commits",
Description: "revert commit",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
{
2022-03-26 05:44:30 +02:00
title: "Files",
2022-03-20 04:59:33 +02:00
bindings: []*types.Binding{
{
ViewName: "files",
Description: "stage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
{
ViewName: "files",
Description: "unstage file",
2022-12-30 02:34:01 +02:00
Key: 'a',
2022-03-20 04:59:33 +02:00
},
},
},
},
},
}
for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
actual := getBindingSections(test.bindings, &tr)
assert.EqualValues(t, test.expected, actual)
})
}
}