WIP feedback
This commit is contained in:
25 files changed
+2141
-2
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package mujica
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
func TestSpinnerLabelAndSize(t *testing.T) {
|
||||
var mark ui.Rect
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{Locale: ZhCN})
|
||||
Spinner(c, SpinnerOptions{})
|
||||
Spinner(c, SpinnerOptions{Size: 32, Label: "Fetching mail", ShowLabel: true})
|
||||
}, 400, 300)
|
||||
r, ok := tt.Find("加载中")
|
||||
if !ok || r.W != 16 || r.H != 16 {
|
||||
t.Fatalf("default mark %v %v", r, ok)
|
||||
}
|
||||
if tt.HasText("加载中") {
|
||||
t.Fatal("hidden label painted")
|
||||
}
|
||||
mark, ok = tt.Find("Fetching mail")
|
||||
if !ok || mark.W != 32 {
|
||||
t.Fatalf("sized mark %v %v", mark, ok)
|
||||
}
|
||||
n := 0
|
||||
for _, s := range tt.Texts() {
|
||||
if s == "Fetching mail" {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n != 2 {
|
||||
t.Fatalf("label as name and text: %d of %q", n, tt.Texts())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpinnerMotion(t *testing.T) {
|
||||
show := true
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
if show {
|
||||
Spinner(c, SpinnerOptions{Size: 40})
|
||||
}
|
||||
}, 100, 100)
|
||||
a := encode(t, tt.Image())
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
tt.Frame()
|
||||
if bytes.Equal(a, encode(t, tt.Image())) {
|
||||
t.Fatal("spinner did not turn")
|
||||
}
|
||||
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1})
|
||||
a = encode(t, tt.Image())
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
tt.Frame()
|
||||
if !bytes.Equal(a, encode(t, tt.Image())) {
|
||||
t.Fatal("spinner turned under reduced motion")
|
||||
}
|
||||
show = false
|
||||
tt.Frame()
|
||||
if _, ok := tt.Find("Loading"); ok {
|
||||
t.Fatal("hidden spinner still built")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpinnerSnapshot(t *testing.T) {
|
||||
snapshot(t, "spinner", 360, 100, func(c *ui.Context) {
|
||||
ui.Row(c).Padding(24).Gap(24).AlignItems(ui.Center).Children(func() {
|
||||
Spinner(c, SpinnerOptions{})
|
||||
Spinner(c, SpinnerOptions{Size: 24})
|
||||
Spinner(c, SpinnerOptions{Size: 20, Label: "Syncing", ShowLabel: true})
|
||||
Button(c, "Saving", ButtonOptions{Loading: true})
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user