summaryrefslogtreecommitdiff
path: root/internal/ui/help/help_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-22 14:07:54 +0300
committerPaul Buetow <paul@buetow.org>2026-06-22 14:07:54 +0300
commit6417a632d65486f44eb51b48855eeafb2b03da31 (patch)
tree26754d27265e1bad869836e9befe2664150dadfc /internal/ui/help/help_test.go
parentb83ee79cc9372f2fa51daf71757a1213328e1723 (diff)
tq0 refactor UI help rendering
Diffstat (limited to 'internal/ui/help/help_test.go')
-rw-r--r--internal/ui/help/help_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/ui/help/help_test.go b/internal/ui/help/help_test.go
new file mode 100644
index 0000000..79c3ec0
--- /dev/null
+++ b/internal/ui/help/help_test.go
@@ -0,0 +1,75 @@
+package help
+
+import (
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/charmbracelet/x/ansi"
+)
+
+func TestLinesFlattensSectionsForSearch(t *testing.T) {
+ sections := []Section{
+ {
+ Title: "Navigation",
+ Items: []Item{
+ {Key: "j", Desc: "move down"},
+ {Key: "k", Desc: "move up"},
+ },
+ },
+ {
+ Title: "General",
+ Items: []Item{
+ {Key: "q", Desc: "quit"},
+ },
+ },
+ }
+
+ got := Lines(sections)
+ want := []string{
+ "Navigation",
+ "j: move down",
+ "k: move up",
+ "",
+ "General",
+ "q: quit",
+ }
+
+ if strings.Join(got, "\n") != strings.Join(want, "\n") {
+ t.Fatalf("Lines() mismatch\nwant:\n%s\ngot:\n%s", strings.Join(want, "\n"), strings.Join(got, "\n"))
+ }
+}
+
+func TestRenderHighlightsSearchMatches(t *testing.T) {
+ sections := []Section{
+ {
+ Title: "Search",
+ Items: []Item{
+ {Key: "/", Desc: "search tasks"},
+ {Key: "n", Desc: "next match"},
+ },
+ },
+ }
+ palette := Palette{
+ HeaderFG: "15",
+ HeaderBG: "8",
+ KeyFG: "14",
+ DescFG: "250",
+ SearchFG: "0",
+ SearchBG: "11",
+ }
+
+ base := Render(sections, palette, nil)
+ got := Render(sections, palette, regexp.MustCompile("search"))
+ if !strings.Contains(ansi.Strip(got), "search tasks") {
+ t.Fatalf("rendered help omitted matching item: %q", got)
+ }
+ if got == base {
+ t.Fatalf("search highlight did not change rendered help")
+ }
+
+ noMatch := Render(sections, palette, regexp.MustCompile("not-present"))
+ if noMatch != base {
+ t.Fatalf("non-matching search changed rendered help\nbase: %q\nnoMatch: %q", base, noMatch)
+ }
+}