Skip to content

Commit

Permalink
chore(help): add full help test to support #554
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Oct 10, 2024
1 parent d3dc455 commit a9c714a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
54 changes: 54 additions & 0 deletions help/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package help

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/charmbracelet/bubbles/key"
)

func TestFullHelp(t *testing.T) {
m := New()
m.FullSeparator = " | "
k := key.WithKeys("x")
kb := [][]key.Binding{
{
key.NewBinding(k, key.WithHelp("enter", "continue")),
},
{
key.NewBinding(k, key.WithHelp("esc", "back")),
key.NewBinding(k, key.WithHelp("?", "help")),
},
{
key.NewBinding(k, key.WithHelp("H", "home")),
key.NewBinding(k, key.WithHelp("ctrl+c", "quit")),
key.NewBinding(k, key.WithHelp("ctrl+l", "log")),
},
}

for i, w := range []int{20, 30, 40} {
m.Width = w
s := m.FullHelpView(kb)

dir := "testdata"
filename := filepath.Join(dir, fmt.Sprintf("full_help_%d.golden", i))

// Un-comment to generate golden files
// if err := os.MkdirAll(dir, 0755); err != nil {
// t.Error(err)
// }
// if err := os.WriteFile(filename, []byte(s), 0644); err != nil {
// t.Error(err)
// }

b, err := os.ReadFile(filename)
if err != nil {
t.Error(err)
}
if s != string(b) {
t.Errorf("Expected:\n%q, Got:\n%q", b, s)
}
}
}
1 change: 1 addition & 0 deletions help/testdata/full_help_0.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enter continue …
2 changes: 2 additions & 0 deletions help/testdata/full_help_1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
enter continue | esc back …
? help
3 changes: 3 additions & 0 deletions help/testdata/full_help_2.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enter continue | esc back | H home
? help ctrl+c quit
ctrl+l log

0 comments on commit a9c714a

Please sign in to comment.