package picker import ( "os" "path/filepath" "strings" "testing" "glint/internal/theme" "github.com/charmbracelet/lipgloss" ) // Long vault-relative paths must not wrap in the list column: a wrapped label // inflates the rendered height past the viewport and scrolls the query field // (top line) off-screen. Every rendered line must fit the terminal width. func TestListLabelsDoNotWrapOrOverflow(t *testing.T) { root := t.TempDir() names := []string{ "short.md", "Meetings/2026-06-18 Weekly Project Sync Notes and Review.md", "Issues/tracker/task-003 - schedule-nightly-backup-and-rotate-old-snapshots-cron-job.md", "Working Files/Reference Material (longer parenthetical title here).md", } // Plus enough files to overfill the viewport — the real-world trigger is a // vault of hundreds of notes, where a single wrapped label pushes the query // field off the top. for i := 0; i < 80; i++ { names = append(names, filepath.Join("ARCHER/Meetings", "2026-06-18 ARCHER ABE Team Meeting Review long filler "+strings.Repeat("x", 30)+".md")) } for i, n := range names { // de-dup the filler names so they are distinct files if i >= 4 { n = strings.Replace(n, "filler ", "filler"+string(rune('a'+i%26))+" ", 1) } p := filepath.Join(root, n) if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(p, []byte("# x\n"), 0o644); err != nil { t.Fatal(err) } } for _, dims := range [][2]int{{120, 30}, {80, 24}, {50, 20}} { m, err := New(root, theme.FlexokiDark(), "", "dark") if err != nil { t.Fatal(err) } m.SetSize(dims[0], dims[1]-1) // app gives the picker height-1 out := m.View() lines := strings.Split(out, "\n") if !strings.Contains(lines[0], "note") { t.Errorf("dims=%v: query field not on the first line; got %q", dims, lines[0]) } for i, ln := range lines { if w := lipgloss.Width(ln); w > dims[0] { t.Errorf("dims=%v: line %d width %d exceeds terminal width %d (will wrap): %q", dims, i, w, dims[0], ln) } } if len(lines) > dims[1] { t.Errorf("dims=%v: picker view has %d lines, exceeds terminal height %d", dims, len(lines), dims[1]) } } }