MCPcopy
hub / github.com/basecamp/once / TestMenu_ShortcutsLeftAlignedKeysRightAligned

Function TestMenu_ShortcutsLeftAlignedKeysRightAligned

internal/ui/menu_test.go:73–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestMenu_ShortcutsLeftAlignedKeysRightAligned(t *testing.T) {
74 menu := NewMenu(
75 MenuItem{Label: "Go", Key: 0, Shortcut: WithHelp(NewKeyBinding("g"), "g", "")},
76 MenuItem{Label: "Stop", Key: 1, Shortcut: WithHelp(NewKeyBinding("s"), "s", "")},
77 )
78 menu.SetWidth(20)
79
80 view := ansi.Strip(menu.View())
81 lines := strings.Split(view, "\n")
82
83 for _, line := range lines {
84 assert.Equal(t, 20, lipgloss.Width(line))
85 }
86
87 // Labels left-aligned
88 assert.True(t, strings.HasPrefix(lines[0], "Go"))
89 assert.True(t, strings.HasPrefix(lines[1], "Stop"))
90
91 // Shortcut keys right-aligned
92 assert.True(t, strings.HasSuffix(lines[0], "g"))
93 assert.True(t, strings.HasSuffix(lines[1], "s"))
94}
95
96func TestMenu_ShortcutsAlignedWithMixedLabelLengths(t *testing.T) {
97 menu := NewMenu(

Callers

nothing calls this directly

Calls 6

SetWidthMethod · 0.95
ViewMethod · 0.95
NewMenuFunction · 0.85
WithHelpFunction · 0.85
NewKeyBindingFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…