package tui import ( "context" "git.a-wan.net/alan/pipelines/internal/protocol" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/x/ansi" "strings" "testing" ) func TestStatusPalettePopupAndClosePreservesUnderlyingPage(t *testing.T) { m := New(context.Background(), "ws://127.0.0.1:8080/connect") m.width = 120 m.height = 40 m.runOpen = true m.keys.runs = true m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 42}} m = press(m, ":") m = press(m, "status") m = press(m, "enter") if !m.statusOpen || m.paletteOpen || !strings.Contains(ansi.Strip(m.View()), "Not connected") { t.Fatal("status unavailable off Home", m.View()) } m.statusRequest = "status-1" updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Status, ID: "status-1", Status: &protocol.SystemStatus{Hostname: "test-machine", Server: protocol.ServiceStatus{Health: "healthy", Port: "8080"}, Ntfy: protocol.ServiceStatus{Health: "healthy", URL: "http://192.0.2.2:8090", Port: "8090"}, Addresses: []protocol.NetworkAddress{{Interface: "en0", IP: "192.0.2.2"}}}})) m = updated.(Model) view := ansi.Strip(m.View()) for _, text := range []string{"Pipelines server", "ntfy", "8080", "8090", "192.0.2.2"} { if !strings.Contains(view, text) { t.Fatal("missing status info", text, view) } } m = press(m, "esc") if strings.Contains(view, "test-machine") || strings.Contains(view, "Client connection:") { t.Fatal("status includes unnecessary metadata", view) } if m.statusOpen || m.runDetail.ID != 42 { t.Fatal("status destroyed run selection") } updated, _ = m.Update(tea.WindowSizeMsg{Width: 40, Height: 12}) m = updated.(Model) m.statusOpen = true if len(strings.Split(ansi.Strip(m.View()), "\n")) != 12 { t.Fatal("popup overflowed short terminal") } } func TestDashboardSideBySideStatsAndNarrowStacking(t *testing.T) { m := New(context.Background(), "") m.width = 120 m.loaded = true m.pipelines = []protocol.PipelineSummary{{ID: 1, Name: "popular", Version: 2, Stages: 3}} m.usage = &protocol.UsageStats{RunCounts: protocol.RunCounts{Total: 80, Succeeded: 60, Failed: 20, AverageSeconds: 60}, Pipelines: []protocol.PipelineUsage{{PipelineID: 1, Name: "popular", RunCounts: protocol.RunCounts{Total: 80, Succeeded: 60, Failed: 20, AverageSeconds: 60}}}, Days: []protocol.DailyUsage{{Runs: 0}, {Runs: 1}, {Runs: 8}}} view := ansi.Strip(strings.Join(m.homeLines(), "\n")) for _, text := range []string{"80 runs", "success 75%", "avg completed 1m0s", "14d activity", "60 succeeded", "20 failed", "avg 1m0s"} { if !strings.Contains(view, text) { t.Fatal("missing dashboard metric", text, view) } } sameLine := false for _, line := range strings.Split(view, "\n") { if strings.Contains(line, "Latest runs") && strings.Contains(line, "Existing pipelines") { sameLine = true } } if !sameLine { t.Fatal("wide dashboard did not use columns", view) } m.width = 60 view = ansi.Strip(strings.Join(m.homeLines(), "\n")) for _, line := range strings.Split(view, "\n") { if strings.Contains(line, "Latest runs") && strings.Contains(line, "Existing pipelines") { t.Fatal("narrow dashboard did not stack") } } if usageChart([]protocol.DailyUsage{{Runs: 0}, {Runs: 0}}) != "ยทยท" { t.Fatal("empty activity fabricated bars") } }