Files
MujicaUI/search_progress_test.go
T
2026-10-05 15:02:31 -04:00

61 lines
1.9 KiB
Go

package mujica
import (
"testing"
"github.com/egoist/mygo/ui"
)
func searchStages(done int) []SearchStage {
labels := []string{"Planning queries", "Searching the web", "Reading sources", "Writing the answer"}
out := make([]SearchStage, len(labels))
for i, l := range labels {
out[i] = SearchStage{Label: l, Done: i < done}
}
return out
}
func TestSearchProgressFoldsWhenDone(t *testing.T) {
opts := SearchProgressOptions{Query: "Versailles 1682", Read: 3, Total: 8, Stages: searchStages(2)}
tt := ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
SearchProgress(c, opts)
}, 500, 300)
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1})
for _, s := range []string{"Searching for “Versailles 1682”", "Read 3 of 8 sources", "Reading sources"} {
if !tt.HasText(s) {
t.Errorf("missing %q in %q", s, tt.Texts())
}
}
opts.Done, opts.Read, opts.Stages = true, 8, searchStages(4)
tt.Frame()
if !tt.HasText("Searched “Versailles 1682”, read 8 sources") || tt.HasText("Reading sources") {
t.Fatalf("done: %q", tt.Texts())
}
_ = tt.Click("Searched “Versailles 1682”, read 8 sources")
if !tt.HasText("Reading sources") {
t.Fatal("finished search does not open again")
}
}
func TestSearchProgressBadCounts(t *testing.T) {
defer func() {
if recover() == nil {
t.Fatal("no panic for Read above Total")
}
}()
ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
SearchProgress(c, SearchProgressOptions{Query: "q", Read: 3, Total: 1})
}, 100, 100)
}
func TestSearchProgressSnapshot(t *testing.T) {
snapshot(t, "search_progress", 440, 230, func(c *ui.Context) {
ui.Column(c).Padding(16).Gap(12).Children(func() {
SearchProgress(c, SearchProgressOptions{Query: "Versailles 1682", Read: 3, Total: 8, Stages: searchStages(2)})
SearchProgress(c, SearchProgressOptions{Query: "Hall of Mirrors", Read: 5, Total: 5, Stages: searchStages(4), Done: true})
})
})
}