Overlays: review r2 fixes

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 13:17:47 -04:00
1 parent 9329ce2ed3
commit a4e5683f57
22 files changed
+197 -37

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
package mujica
import (
"strings"
"testing"
"github.com/egoist/mygo/ui"
)
// overlayLongText is about 372 characters of description.
var overlayLongText = strings.Repeat("The east wing stays sealed until the court returns. ", 7)
// overlayInWindow fails unless every label lies fully inside a w×h window.
func overlayInWindow(t *testing.T, tt *ui.Tester, w, h float32, labels ...string) {
t.Helper()
for _, l := range labels {
r, ok := tt.Find(l)
if !ok || r.W == 0 || r.H == 0 || r.Y < 0 || r.X < 0 || r.Y+r.H > h || r.X+r.W > w {
t.Errorf("%q at %+v (found %v) outside the %v×%v window", l, r, ok, w, h)
}
}
}
func TestDialogActionsStayInWindowAtLargeText(t *testing.T) {
open, name := true, "Ophelia"
tt := ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
Dialog(c, &open, DialogOptions{Title: "Rename", Description: overlayLongText, Actions: func() {
Button(c, "Cancel", ButtonOptions{Variant: Secondary})
Button(c, "Save", ButtonOptions{})
}}, func() { ui.TextInput(c, &name) })
}, 800, 600)
tt.SetPreferences(ui.Preferences{TextScale: 2})
tt.Frame()
overlayInWindow(t, tt, 800, 600, "Cancel", "Save")
}
func TestAlertDialogActionsStayInWindowAtLargeText(t *testing.T) {
open := true
tt := ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
AlertDialog(c, &open, AlertDialogOptions{Title: "Burn?", Description: overlayLongText, ConfirmText: "letters"})
}, 800, 600)
tt.SetPreferences(ui.Preferences{TextScale: 2})
tt.Frame()
overlayInWindow(t, tt, 800, 600, "Cancel", "Delete", "Type “letters” to confirm")
}
func TestOverlayPanelFitsWindow(t *testing.T) {
for _, modal := range []bool{true, false} {
open := true
var panel ui.Rect
tt := ui.NewTester(func(c *ui.Context) {
Use(c, Settings{})
if p := Overlay(c, &open, OverlayOptions{Modal: modal}, func() {
ui.Text(c, strings.Repeat(overlayLongText, 6))
Button(c, "Done", ButtonOptions{})
}); p != nil {
panel = p.Bounds()
}
}, 600, 400)
tt.Frame()
if panel.X < 16 || panel.Y < 16 || panel.X+panel.W > 584 || panel.Y+panel.H > 384 {
t.Errorf("modal %v: panel %+v outside the window minus Inset", modal, panel)
}
}
}