1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package app
import (
"strings"
"testing"
"glint/internal/help"
tea "github.com/charmbracelet/bubbletea"
)
// ctrlSlash is what the terminal sends for Ctrl+/ (the unit separator, 0x1f).
var ctrlSlash = tea.KeyMsg{Type: tea.KeyCtrlUnderscore}
func TestHelpToggleOpensAndCloses(t *testing.T) {
a := statusApp()
a.Update(ctrlSlash)
if a.mode != ModeHelp {
t.Fatalf("Ctrl+/ did not open help: mode = %v", a.mode)
}
a.Update(ctrlSlash)
if a.mode != ModeEditor {
t.Fatalf("second Ctrl+/ did not close help: mode = %v", a.mode)
}
}
func TestHelpEscCloses(t *testing.T) {
a := statusApp()
a.Update(ctrlSlash)
a.Update(tea.KeyMsg{Type: tea.KeyEsc})
if a.mode != ModeEditor {
t.Fatalf("Esc did not close help: mode = %v", a.mode)
}
}
func TestHelpViewShowsHelpContent(t *testing.T) {
a := statusApp()
a.Update(tea.WindowSizeMsg{Width: 120, Height: 40})
a.Update(ctrlSlash)
got := a.View()
if !strings.Contains(got, "USAGE") {
t.Fatalf("help view missing content from help.Text:\n%s", got)
}
}
func TestHelpUsesSharedSource(t *testing.T) {
if !strings.Contains(help.Text, "EDITOR KEYS") || !strings.Contains(help.Text, "Ctrl+S") {
t.Fatalf("help.Text is not the full reference:\n%s", help.Text)
}
}
func TestStatusBarShowsToggleKey(t *testing.T) {
a := statusApp()
if got := a.statusBar(); !strings.Contains(got, "ctrl+/") {
t.Fatalf("status bar missing help toggle key:\n%s", got)
}
}
|