package main import ( "strings" "testing" ) func TestFragmentUserMessage(t *testing.T) { f := FragmentUserMessage("Hello ") if !strings.Contains(f, "message-user") { t.Error("missing message-user class") } if !strings.Contains(f, "Hello <world>") { t.Error("should escape HTML") } if !strings.Contains(f, `hx-swap-oob="beforeend"`) { t.Error("missing OOB swap") } } func TestFragmentAssistantStart(t *testing.T) { f := FragmentAssistantStart("msg-1") if !strings.Contains(f, `id="msg-1"`) { t.Error("missing message ID") } if !strings.Contains(f, "message-assistant") { t.Error("missing message-assistant class") } } func TestFragmentAssistantChunk(t *testing.T) { f := FragmentAssistantChunk("msg-1", "chunk") if !strings.Contains(f, `id="msg-1"`) { t.Error("missing message ID") } if !strings.Contains(f, "chunk<text>") { t.Error("should escape HTML") } } func TestFragmentAssistantComplete(t *testing.T) { f := FragmentAssistantComplete("msg-1", "

Hello

") if !strings.Contains(f, `id="msg-1"`) { t.Error("missing message ID") } if !strings.Contains(f, "

Hello

") { t.Error("should include raw HTML content") } } func TestFragmentToolCall(t *testing.T) { f := FragmentToolCall("Read", "/tmp/test.go") if !strings.Contains(f, "message-tool") { t.Error("missing message-tool class") } if !strings.Contains(f, "Read") { t.Error("missing tool name") } } func TestFragmentToolCallTruncation(t *testing.T) { longInput := strings.Repeat("x", 300) f := FragmentToolCall("Write", longInput) if !strings.Contains(f, "...") { t.Error("should truncate long input") } } func TestFragmentSystemMessage(t *testing.T) { f := FragmentSystemMessage("Connected") if !strings.Contains(f, "message-system") { t.Error("missing message-system class") } if !strings.Contains(f, "Connected") { t.Error("missing text") } } func TestFragmentTypingIndicator(t *testing.T) { show := FragmentTypingIndicator(true) if !strings.Contains(show, "typing-indicator") { t.Error("missing typing indicator") } if !strings.Contains(show, "razmišlja") { t.Error("missing thinking text") } hide := FragmentTypingIndicator(false) if !strings.Contains(hide, `id="typing-indicator"`) { t.Error("missing ID") } if strings.Contains(hide, "razmišlja") { t.Error("should not contain thinking text when hidden") } } func TestFragmentStatus(t *testing.T) { connected := FragmentStatus(true) if !strings.Contains(connected, "connected") { t.Error("missing connected class") } if !strings.Contains(connected, "Povezan") { t.Error("missing connected text") } disconnected := FragmentStatus(false) if strings.Contains(disconnected, "connected") { t.Error("should not have connected class when disconnected") } } func TestFragmentClearInput(t *testing.T) { f := FragmentClearInput() if !strings.Contains(f, `id="message-input"`) { t.Error("missing input ID") } if !strings.Contains(f, "hx-swap-oob") { t.Error("missing OOB swap") } } func TestFragmentCombine(t *testing.T) { combined := FragmentCombine("a", "b", "c") if combined != "a\nb\nc" { t.Errorf("got %q", combined) } }