Display: review r2 fixes
This commit is contained in:
10 files changed
+283
-122
No files matched your search
+46
-4
@@ -77,11 +77,14 @@ func TestImageRetry(t *testing.T) {
|
||||
retries++
|
||||
}
|
||||
}, 300, 300)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
if !tt.Focused("Retry") {
|
||||
t.Fatal("retry not focused by Tab")
|
||||
}
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if err := tt.Click("Retry"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if retries != 2 {
|
||||
t.Fatalf("retries %d, want 2", retries)
|
||||
}
|
||||
@@ -102,12 +105,13 @@ func TestImageNegativeSizePanics(t *testing.T) {
|
||||
|
||||
func TestImageSnapshot(t *testing.T) {
|
||||
bmp := imageTestBitmap()
|
||||
snapshot(t, "image", 600, 180, func(c *ui.Context) {
|
||||
snapshot(t, "image", 760, 170, func(c *ui.Context) {
|
||||
ui.Row(c).Padding(20).Gap(12).AlignItems(ui.Start).Children(func() {
|
||||
Image(c, bmp, ImageOptions{Width: 120, Height: 120, Crop: true, Alt: "Cropped"})
|
||||
Image(c, nil, ImageOptions{Width: 120, Height: 120})
|
||||
Image(c, nil, ImageOptions{Width: 120, Height: 120, Loading: true})
|
||||
Image(c, nil, ImageOptions{Width: 160, Height: 140, Err: errors.New("404")})
|
||||
Image(c, nil, ImageOptions{Width: 200, Height: 120, Err: errors.New("404")})
|
||||
Image(c, bmp, ImageOptions{Err: errors.New("404")})
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -135,3 +139,41 @@ func TestImageKeepsSizeWhileLoading(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageStatesShareBoxWhenShrunk(t *testing.T) {
|
||||
bmp := imageTestBitmap()
|
||||
var got []ui.Rect
|
||||
for _, opts := range []ImageOptions{{}, {Loading: true}, {Err: errors.New("x")}} {
|
||||
var r ui.Rect
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
ui.Row(c).Width(40).AlignItems(ui.Start).Children(func() {
|
||||
r = Image(c, bmp, opts).Element.Bounds()
|
||||
})
|
||||
}, 300, 300)
|
||||
tt.Frame()
|
||||
got = append(got, r)
|
||||
}
|
||||
if got[0].W != 40 || got[0].H != 20 || got[1] != got[0] || got[2] != got[0] {
|
||||
t.Fatalf("loaded, loading, error boxes %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageRetryInSmallBox(t *testing.T) {
|
||||
retries := 0
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
ui.Row(c).Width(40).AlignItems(ui.Start).Children(func() {
|
||||
if Image(c, imageTestBitmap(), ImageOptions{Err: errors.New("timeout")}).Retry {
|
||||
retries++
|
||||
}
|
||||
})
|
||||
}, 300, 300)
|
||||
tt.Frame()
|
||||
if err := tt.Click("Retry"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if retries != 1 {
|
||||
t.Fatalf("retries %d, want 1", retries)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user