1package model
2
3import (
4 "testing"
5
6 "github.com/charmbracelet/crush/internal/message"
7 "github.com/charmbracelet/crush/internal/ui/chat"
8 "github.com/stretchr/testify/require"
9)
10
11// TestChatToggleExpandedSelectedItem_AssistantMessage is the regression test
12// for ยง4.8.1: before the fix, AssistantMessageItem.ToggleExpanded returned no
13// value so the type did not satisfy chat.Expandable, and the keyboard-driven
14// ToggleExpandedSelectedItem path silently skipped thinking blocks. This
15// wires a real Chat with an AssistantMessageItem, selects it, invokes
16// ToggleExpandedSelectedItem, and asserts the thinking block actually
17// flipped.
18func TestChatToggleExpandedSelectedItem_AssistantMessage(t *testing.T) {
19 t.Parallel()
20
21 u := newTestUI()
22
23 msg := &message.Message{ID: "m-assist", Role: message.Assistant}
24 item := chat.NewAssistantMessageItem(u.com.Styles, msg)
25
26 // The keyboard expand path uses the generic Expandable interface;
27 // verifying satisfaction at runtime guards the contract.
28 exp, ok := item.(chat.Expandable)
29 require.True(t, ok, "AssistantMessageItem must satisfy chat.Expandable")
30
31 u.chat.SetMessages(item)
32 u.chat.SetSelected(0)
33
34 // First keyboard toggle should expand. Immediately follow with a
35 // direct ToggleExpanded: it flips the now-expanded item back to
36 // collapsed and returns false. If the keyboard path had silently
37 // skipped the item (the bug), the item would still be collapsed and
38 // the direct toggle would return true.
39 u.chat.ToggleExpandedSelectedItem()
40 require.False(t, exp.ToggleExpanded(),
41 "keyboard toggle did not expand the assistant thinking block")
42
43 // Second keyboard toggle against the re-collapsed item should expand
44 // it again. Direct ToggleExpanded then returns false because it
45 // re-collapses.
46 u.chat.ToggleExpandedSelectedItem()
47 require.False(t, exp.ToggleExpanded(),
48 "second keyboard toggle did not re-expand the assistant thinking block")
49}