Files
MujicaUI/resource_gauge_test.go
T
2026-10-05 14:49:26 -04:00

57 lines
1.4 KiB
Go

package mujica
import (
"testing"
"github.com/egoist/mygo/ui"
)
var resourceSample = []ResourceReading{
{Name: "CPU", Used: 45, Total: 100},
{Name: "Memory", Used: 6.4, Total: 8, Unit: "GB"},
{Name: "Disk", Used: 470, Total: 500, Unit: "GB"},
}
func TestResourceGaugeThresholdsAndKeyboard(t *testing.T) {
tt := ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
ResourceGauge(c, resourceSample, ResourceGaugeOptions{})
}, 700, 300)
if !tt.HasText("6.4 / 8 GB") || !tt.HasText("470 / 500 GB") {
t.Fatalf("texts %q", tt.Texts())
}
tt.Key(0, ui.KeyTab) // CPU dial
tt.Key(0, ui.KeyRight)
if !tt.HasText("45 % · Normal") {
t.Fatalf("CPU readout: %q", tt.Texts())
}
tt.Key(0, ui.KeyTab)
tt.Key(0, ui.KeyRight)
if !tt.HasText("80 % · High") {
t.Fatalf("memory readout: %q", tt.Texts())
}
tt.Key(0, ui.KeyTab)
tt.Key(0, ui.KeyRight)
if !tt.HasText("94 % · Critical") {
t.Fatalf("disk readout: %q", tt.Texts())
}
}
func TestResourceGaugeRejectsBadReading(t *testing.T) {
defer func() {
if recover() == nil {
t.Fatal("no panic")
}
}()
ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
ResourceGauge(c, []ResourceReading{{Name: "CPU", Used: 5, Total: 4}}, ResourceGaugeOptions{})
}, 200, 200)
}
func TestResourceGaugeSnapshot(t *testing.T) {
snapshot(t, "resource_gauge", 680, 250, func(c *ui.Context) {
ui.Column(c).Padding(16).Children(func() { ResourceGauge(c, resourceSample, ResourceGaugeOptions{}) })
})
}