2026-03-21 16:20:16 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-21 18:32:07 +02:00
|
|
|
"strings"
|
2026-03-21 16:20:16 +02:00
|
|
|
"testing"
|
|
|
|
|
|
2026-03-21 18:32:07 +02:00
|
|
|
"github.com/charmbracelet/bubbles/viewport"
|
2026-03-21 16:20:16 +02:00
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Since sidekick-tui/main.go uses global variables and is a tea.Model,
|
|
|
|
|
// we test basic model behavior.
|
|
|
|
|
|
|
|
|
|
func TestInitialModel(t *testing.T) {
|
|
|
|
|
// For testing, sidekick.LoadConfig would fail or look in its default dir.
|
|
|
|
|
// This ensures that the model can be initialized even without a config.
|
|
|
|
|
m := initialModel()
|
|
|
|
|
|
|
|
|
|
if m.agent == nil {
|
|
|
|
|
t.Error("expected default agent to be initialized even without config")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.textarea.Value() != "" {
|
|
|
|
|
t.Errorf("expected empty textarea, got %s", m.textarea.Value())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestModelUpdate(t *testing.T) {
|
|
|
|
|
m := initialModel()
|
|
|
|
|
m.ready = true
|
|
|
|
|
m.width = 80
|
|
|
|
|
m.height = 24
|
|
|
|
|
|
|
|
|
|
// Test a key message (Enter)
|
|
|
|
|
m.textarea.SetValue("Hello")
|
|
|
|
|
newModel, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
|
|
|
|
|
|
|
|
|
|
tm := newModel.(model)
|
|
|
|
|
if tm.isThinking != true {
|
|
|
|
|
t.Error("expected model to be in thinking state after Enter")
|
|
|
|
|
}
|
|
|
|
|
if tm.textarea.Value() != "" {
|
|
|
|
|
t.Error("expected textarea to be reset after Enter")
|
|
|
|
|
}
|
|
|
|
|
if cmd == nil {
|
|
|
|
|
t.Error("expected a command after Enter")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test an agent response message
|
|
|
|
|
respModel, _ := tm.Update(agentResponseMsg{response: "Hi"})
|
|
|
|
|
rm := respModel.(model)
|
|
|
|
|
if rm.isThinking != false {
|
|
|
|
|
t.Error("expected model to stop thinking after response")
|
|
|
|
|
}
|
|
|
|
|
if len(rm.messages) < 2 {
|
|
|
|
|
t.Error("expected message list to grow after response")
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-21 18:32:07 +02:00
|
|
|
|
|
|
|
|
func TestMessageWrapping(t *testing.T) {
|
|
|
|
|
m := initialModel()
|
|
|
|
|
m.ready = true
|
|
|
|
|
m.viewport = viewport.New(10, 5) // Very narrow
|
|
|
|
|
|
|
|
|
|
longMsg := "This is a very long message that should be wrapped."
|
|
|
|
|
respModel, _ := m.Update(agentResponseMsg{response: longMsg})
|
|
|
|
|
rm := respModel.(model)
|
|
|
|
|
|
|
|
|
|
lastMsg := rm.messages[len(rm.messages)-1]
|
|
|
|
|
if !strings.Contains(lastMsg, "\n") {
|
|
|
|
|
t.Errorf("expected long message to be wrapped, but no newline found")
|
|
|
|
|
}
|
|
|
|
|
}
|