WIP components (as built)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 15:51:57 -04:00
1 parent 73df90b9b1
commit b4798a6287
110 files changed
+3975 -273

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
package mujica
import (
"github.com/egoist/mygo/ui"
"mujicaui/internal"
"mujicaui/theme"
"testing"
)
func TestAssetAllocationChartWeightsDriftAndKeys(t *testing.T) {
items := []AllocationItem{{"Stocks", 60, 50}, {"Bonds", 30, 40}, {"Cash", 10, 10}}
var last ChartResult
tt := chatTester(960, 420, func(c *ui.Context) {
last = AssetAllocationChart(c, items, AssetAllocationChartOptions{Frame: ChartFrame{Label: "Allocation"}})
})
if !tt.HasText("60.0%") || !tt.HasText("+10.0 pt") || !tt.HasText("−10.0 pt") || !tt.HasText("Over") || !tt.HasText("Under") {
t.Fatalf("weights %q", tt.Texts())
}
tt.Key(0, ui.KeyTab)
tt.Key(0, ui.KeyHome)
if last.Point != 0 {
t.Fatalf("point %d", last.Point)
}
tt.Key(0, ui.KeyEnd)
if last.Point != 2 {
t.Fatalf("point %d", last.Point)
}
marketsPanic(t, func(c *ui.Context) {
AssetAllocationChart(c, []AllocationItem{{"Bad", 1, 101}}, AssetAllocationChartOptions{Frame: ChartFrame{Label: "x"}})
})
}
func TestAssetAllocationChartSnapshot(t *testing.T) {
snapshot(t, "asset_allocation_chart", 760, 380, func(c *ui.Context) {
ui.Column(c).Padding(16).Gap(12).Fill().Children(func() {
AssetAllocationChart(c, []AllocationItem{{"Stocks", 62000, 55}, {"Bonds", 25000, 30}, {"Cash", 8000, 10}, {"Gold", 5000, 5}}, AssetAllocationChartOptions{Frame: ChartFrame{Label: "Allocation"}})
})
})
}
func TestAssetAllocationChartMergedMarkers(t *testing.T) {
items := []AllocationItem{{"Tiny A", 0.1, 0}, {"Tiny B", 0.1, 0}, {"Stocks", 99.8, 0}}
tt := chatTester(960, 420, func(c *ui.Context) {
AssetAllocationChart(c, items, AssetAllocationChartOptions{Frame: ChartFrame{Label: "Allocation"}})
})
r, _ := tt.Find("99.8%")
asset, _ := tt.Find("Asset")
palette := internal.Palette(theme.Light())
found := false
for y := int(r.Y); y < int(r.Y+r.H); y++ {
for x := int(asset.X); x < int(r.X); x++ {
pixel := tt.Image().RGBAAt(x, y)
if pixel.R == palette[0].R && pixel.G == palette[0].G && pixel.B == palette[0].B {
found = true
}
}
}
if !found {
t.Fatal("Stocks list marker differs from its donut marker")
}
}