claude-web-chat/fragments_test.go
djuka 3283888738
All checks were successful
Tests / unit-tests (push) Successful in 51s
Inicijalna implementacija Claude Web Chat (Faza 1 - CLI mod)
- Login sa session cookie autentifikacijom
- Lista projekata iz filesystem-a
- Chat sa Claude CLI preko WebSocket-a
- Streaming NDJSON parsiranje iz CLI stdout-a
- Sesija zivi nezavisno od browsera (reconnect replay)
- Sidebar sa .md fajlovima i markdown renderovanjem
- Dark tema, htmx + Go templates
- 47 unit testova

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:03:40 +00:00

128 lines
3.1 KiB
Go

package main
import (
"strings"
"testing"
)
func TestFragmentUserMessage(t *testing.T) {
f := FragmentUserMessage("Hello <world>")
if !strings.Contains(f, "message-user") {
t.Error("missing message-user class")
}
if !strings.Contains(f, "Hello &lt;world&gt;") {
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<text>")
if !strings.Contains(f, `id="msg-1"`) {
t.Error("missing message ID")
}
if !strings.Contains(f, "chunk&lt;text&gt;") {
t.Error("should escape HTML")
}
}
func TestFragmentAssistantComplete(t *testing.T) {
f := FragmentAssistantComplete("msg-1", "<p>Hello</p>")
if !strings.Contains(f, `id="msg-1"`) {
t.Error("missing message ID")
}
if !strings.Contains(f, "<p>Hello</p>") {
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)
}
}