-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functionality to implement help.KeyMap interface (#185)
* Added functionality to implement help.KeyMap interface * Formatting * Made additionalHelp... private. Integrated implementation with 'With..' * Added short comments and fixed logic error in Help string * Fixing linter issues * Fixing linter issues * Fix linter errors * Fixing linter error
- Loading branch information
1 parent
0a779ae
commit f9795db
Showing
4 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package table | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/charmbracelet/bubbles/help" | ||
"github.com/charmbracelet/bubbles/key" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestKeyMapShortHelp(t *testing.T) { | ||
columns := []Column{NewColumn("c1", "Column1", 10)} | ||
model := New(columns) | ||
km := DefaultKeyMap() | ||
model.WithKeyMap(km) | ||
assert.Nil(t, model.additionalShortHelpKeys) | ||
assert.Equal(t, model.ShortHelp(), []key.Binding{ | ||
model.keyMap.RowDown, | ||
model.keyMap.RowUp, | ||
model.keyMap.RowSelectToggle, | ||
model.keyMap.PageDown, | ||
model.keyMap.PageUp, | ||
model.keyMap.Filter, | ||
model.keyMap.FilterBlur, | ||
model.keyMap.FilterClear}, | ||
) | ||
// Testing if the 'adding of keys' works too. | ||
keys := []key.Binding{key.NewBinding(key.WithKeys("t"), key.WithHelp("t", "Testing additional keybinds"))} | ||
model = model.WithAdditionalShortHelpKeys(keys) | ||
assert.NotNil(t, model.additionalShortHelpKeys) | ||
assert.Equal(t, model.ShortHelp(), []key.Binding{ | ||
model.keyMap.RowDown, | ||
model.keyMap.RowUp, | ||
model.keyMap.RowSelectToggle, | ||
model.keyMap.PageDown, | ||
model.keyMap.PageUp, | ||
model.keyMap.Filter, | ||
model.keyMap.FilterBlur, | ||
model.keyMap.FilterClear, | ||
key.NewBinding( | ||
key.WithKeys("t"), | ||
key.WithHelp("t", | ||
"Testing additional keybinds"), | ||
), | ||
}) | ||
} | ||
|
||
func TestKeyMapFullHelp(t *testing.T) { | ||
columns := []Column{NewColumn("c1", "Column1", 10)} | ||
model := New(columns) | ||
km := DefaultKeyMap() | ||
model.WithKeyMap(km) | ||
assert.Nil(t, model.additionalFullHelpKeys) | ||
assert.Equal(t, | ||
model.FullHelp(), | ||
[][]key.Binding{ | ||
{model.keyMap.RowDown, model.keyMap.RowUp, model.keyMap.RowSelectToggle}, | ||
{model.keyMap.PageDown, model.keyMap.PageUp, model.keyMap.PageFirst, model.keyMap.PageLast}, | ||
{ | ||
model.keyMap.Filter, | ||
model.keyMap.FilterBlur, | ||
model.keyMap.FilterClear, | ||
model.keyMap.ScrollRight, | ||
model.keyMap.ScrollLeft, | ||
}, | ||
}, | ||
) | ||
// Testing if the 'adding of keys' works too. | ||
keys := []key.Binding{key.NewBinding(key.WithKeys("t"), key.WithHelp("t", "Testing additional keybinds"))} | ||
model = model.WithAdditionalFullHelpKeys(keys) | ||
assert.NotNil(t, model.additionalFullHelpKeys) | ||
assert.Equal(t, | ||
model.FullHelp(), | ||
[][]key.Binding{ | ||
{model.keyMap.RowDown, model.keyMap.RowUp, model.keyMap.RowSelectToggle}, | ||
{model.keyMap.PageDown, model.keyMap.PageUp, model.keyMap.PageFirst, model.keyMap.PageLast}, | ||
{model.keyMap.Filter, model.keyMap.FilterBlur, | ||
model.keyMap.FilterClear, | ||
model.keyMap.ScrollRight, | ||
model.keyMap.ScrollLeft}, | ||
{key.NewBinding(key.WithKeys("t"), key.WithHelp("t", "Testing additional keybinds"))}}, | ||
) | ||
} | ||
|
||
// Testing if Model actually implements the 'help.KeyMap' interface. | ||
func TestKeyMapInterface(t *testing.T) { | ||
model := New(nil) | ||
assert.Implements(t, (*help.KeyMap)(nil), model) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters