jesseduffield.lazygit/pkg/gui/controllers/helpers/confirmation_helper_test.go
Stefan Haller 1fb5f87d05 Lay out the filter row of a menu that filters as you type
The row is reserved for as long as such a menu is open, even while it is
still hidden, so that it can appear without moving the menu. That costs
two rows of the popup, which is why the screen has to be a little taller
before a menu is worth showing at all.

The prompt in front of the input field is dropped when the row gets too
narrow to type in, and the keybindings menu says what '@' does when it
still fits.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-31 20:41:22 +02:00

32 lines
1 KiB
Go

package helpers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMenuFilterPrompt(t *testing.T) {
longPrompt := "Filter ('@' for keybindings): "
shortPrompt := "Filter: "
tests := []struct {
name string
candidates []string
contentWidth int
expected string
}{
{name: "room for four characters", candidates: []string{shortPrompt}, contentWidth: 12, expected: shortPrompt},
{name: "room for three characters", candidates: []string{shortPrompt}, contentWidth: 11, expected: ""},
{name: "prefers the first candidate", candidates: []string{longPrompt, shortPrompt}, contentWidth: 34, expected: longPrompt},
{name: "falls back to the next one", candidates: []string{longPrompt, shortPrompt}, contentWidth: 33, expected: shortPrompt},
{name: "measures display width", candidates: []string{"篩選: "}, contentWidth: 9, expected: ""},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.expected, menuFilterPrompt(test.candidates, test.contentWidth))
})
}
}