@@ -6,6 +6,7 @@ import (
8 "charm.land/bubbles/v2/textarea"
8 "charm.land/bubbles/v2/textarea"
9+ "github.com/charmbracelet/crush/internal/session"
9 "github.com/charmbracelet/crush/internal/ui/chat"
10 "github.com/charmbracelet/crush/internal/ui/chat"
10 "github.com/charmbracelet/crush/internal/ui/common"
11 "github.com/charmbracelet/crush/internal/ui/common"
@@ -118,3 +119,109 @@ func TestHandleTextareaHeightChange_FollowModeStaysAtBottom(t *testing.T) {
118 t.Fatal("expected chat to remain at bottom after editor resize in follow mode")
119 t.Fatal("expected chat to remain at bottom after editor resize in follow mode")
123+func TestAutoExpandPillsIfReasonable(t *testing.T) {
126+ t.Run("expands when terminal is tall enough and todos exist", func(t *testing.T) {
131+ u.session = &session.Session{ID: "s1", Todos: []session.Todo{
132+ {Status: session.TodoStatusInProgress, Content: "do work"},
133+ {Status: session.TodoStatusPending, Content: "do more"},
136+ u.autoExpandPillsIfReasonable()
138+ if !u.pillsExpanded {
139+ t.Fatal("expected pillsExpanded to be true")
141+ if u.focusedPillSection != pillSectionTodos {
142+ t.Fatalf("expected focusedPillSection to be pillSectionTodos, got %d", u.focusedPillSection)
146+ t.Run("does not expand when terminal is too short", func(t *testing.T) {
151+ u.session = &session.Session{ID: "s1", Todos: []session.Todo{
152+ {Status: session.TodoStatusInProgress, Content: "do work"},
155+ u.autoExpandPillsIfReasonable()
157+ if u.pillsExpanded {
158+ t.Fatal("expected pillsExpanded to be false when terminal height is below threshold")
162+ t.Run("does not expand when all todos are completed", func(t *testing.T) {
167+ u.session = &session.Session{ID: "s1", Todos: []session.Todo{
168+ {Status: session.TodoStatusCompleted, Content: "done"},
171+ u.autoExpandPillsIfReasonable()
173+ if u.pillsExpanded {
174+ t.Fatal("expected pillsExpanded to be false when all todos are completed")
178+ t.Run("does not expand when already expanded", func(t *testing.T) {
183+ u.pillsExpanded = true
184+ u.session = &session.Session{ID: "s1", Todos: []session.Todo{
185+ {Status: session.TodoStatusInProgress, Content: "do work"},
187+ u.updateLayoutAndSize()
189+ u.autoExpandPillsIfReasonable()
191+ if !u.pillsExpanded {
192+ t.Fatal("expected pillsExpanded to stay true")
196+ t.Run("expands for prompt queue when no todos", func(t *testing.T) {
201+ u.session = &session.Session{ID: "s1", Todos: []session.Todo{}}
204+ u.autoExpandPillsIfReasonable()
206+ if !u.pillsExpanded {
207+ t.Fatal("expected pillsExpanded to be true for prompt queue")
209+ if u.focusedPillSection != pillSectionQueue {
210+ t.Fatalf("expected focusedPillSection to be pillSectionQueue, got %d", u.focusedPillSection)
214+ t.Run("does not expand when no session", func(t *testing.T) {
221+ u.autoExpandPillsIfReasonable()
223+ if u.pillsExpanded {
224+ t.Fatal("expected pillsExpanded to be false when there is no session")