Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI
This commit is contained in:
1822 files changed
+24568
-21314
No files matched your search
@@ -0,0 +1,71 @@
|
||||
package devtools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/core"
|
||||
)
|
||||
|
||||
var servicesSample = []ServiceItem{
|
||||
{Name: "API", Health: ServiceOperational},
|
||||
{Name: "Search", Health: ServiceDegraded, Note: "Indexing is slow"},
|
||||
{Name: "Payments", Health: ServiceOutage, Note: "Provider unreachable"},
|
||||
}
|
||||
|
||||
func TestServiceStatusSummaryAndRows(t *testing.T) {
|
||||
services := servicesSample
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
ServiceStatus(c, services, ServiceStatusOptions{})
|
||||
}, 520, 400)
|
||||
for _, s := range []string{"Some services down", "1 up · 1 degraded · 1 down", "Degraded", "Outage", "Provider unreachable"} {
|
||||
if !tt.HasText(s) {
|
||||
t.Fatalf("missing %q in %q", s, tt.Texts())
|
||||
}
|
||||
}
|
||||
services = servicesSample[:1]
|
||||
tt.Frame()
|
||||
if !tt.HasText("All systems operational") {
|
||||
t.Fatalf("all ok: %q", tt.Texts())
|
||||
}
|
||||
services = nil
|
||||
tt.Frame()
|
||||
if !tt.HasText("No services") {
|
||||
t.Fatal("empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceStatusManyVirtualized(t *testing.T) {
|
||||
many := make([]ServiceItem, 100000)
|
||||
for i := range many {
|
||||
many[i] = ServiceItem{Name: fmt.Sprint("svc ", i)}
|
||||
}
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
ServiceStatus(c, many, ServiceStatusOptions{})
|
||||
}, 520, 400)
|
||||
if n := len(tt.Texts()); n > 300 {
|
||||
t.Fatalf("%d texts", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceStatusSnapshot(t *testing.T) {
|
||||
snapshot(t, "service_status", 520, 280, func(c *ui.Context) {
|
||||
ui.Column(c).Padding(16).Children(func() { ServiceStatus(c, servicesSample, ServiceStatusOptions{}) })
|
||||
})
|
||||
}
|
||||
|
||||
func TestServiceStatusRejectsUnknownHealth(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Fatal("unknown service health accepted")
|
||||
}
|
||||
}()
|
||||
ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
ServiceStatus(c, []ServiceItem{{Name: "API", Health: 99}}, ServiceStatusOptions{})
|
||||
}, 400, 300)
|
||||
}
|
||||
Reference in new issue
Block a user