MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
128 lines
3.6 KiB
Go
128 lines
3.6 KiB
Go
package devtools
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
)
|
|
|
|
func refreshTester(interval *time.Duration, opts *RefreshIntervalSelectorOptions, refreshes, changes *int) *ui.Tester {
|
|
return ui.NewTester(func(c *ui.Context) {
|
|
core.Use(c, core.Settings{})
|
|
r := RefreshIntervalSelector(c, interval, *opts)
|
|
if r.Refresh {
|
|
*refreshes++
|
|
}
|
|
if r.Changed {
|
|
*changes++
|
|
}
|
|
}, 500, 300)
|
|
}
|
|
|
|
func TestRefreshIntervalSelectorManualAndAuto(t *testing.T) {
|
|
interval := time.Duration(0)
|
|
opts := RefreshIntervalSelectorOptions{Intervals: []time.Duration{time.Second, time.Minute}}
|
|
refreshes, changes := 0, 0
|
|
tt := refreshTester(&interval, &opts, &refreshes, &changes)
|
|
_ = tt.Click("Refresh")
|
|
if refreshes != 1 {
|
|
t.Fatalf("manual refreshes %d", refreshes)
|
|
}
|
|
tt.Advance(1100 * time.Millisecond)
|
|
if refreshes != 1 {
|
|
t.Fatal("refreshed while off")
|
|
}
|
|
_ = tt.Click("Refresh interval")
|
|
_ = tt.Click("Every 1 s")
|
|
if interval != time.Second || changes != 1 {
|
|
t.Fatalf("interval %v changes %d", interval, changes)
|
|
}
|
|
start := tt.Now()
|
|
if !overlayUntil(tt, func() bool { return refreshes == 2 }) {
|
|
t.Fatal("no automatic refresh")
|
|
}
|
|
if tt.Now().Sub(start) < 900*time.Millisecond {
|
|
t.Fatal("refreshed before the interval")
|
|
}
|
|
}
|
|
|
|
func TestRefreshIntervalSelectorRefreshingAndDisabled(t *testing.T) {
|
|
interval := time.Second
|
|
opts := RefreshIntervalSelectorOptions{Intervals: []time.Duration{time.Second}, Refreshing: true}
|
|
refreshes, changes := 0, 0
|
|
tt := refreshTester(&interval, &opts, &refreshes, &changes)
|
|
_ = tt.Click("Refresh")
|
|
tt.Advance(1100 * time.Millisecond)
|
|
if refreshes != 0 || !tt.HasText("Refresh") {
|
|
t.Fatalf("refreshing: %d", refreshes)
|
|
}
|
|
opts = RefreshIntervalSelectorOptions{Intervals: []time.Duration{time.Second}, Disabled: true}
|
|
tt.Frame()
|
|
tt.Advance(1100 * time.Millisecond)
|
|
_ = tt.Click("Refresh")
|
|
if refreshes != 0 {
|
|
t.Fatalf("disabled refreshed %d", refreshes)
|
|
}
|
|
defer func() {
|
|
if recover() == nil {
|
|
t.Fatal("unoffered interval did not panic")
|
|
}
|
|
}()
|
|
bad := 7 * time.Second
|
|
refreshTester(&bad, &RefreshIntervalSelectorOptions{}, &refreshes, &changes)
|
|
}
|
|
|
|
func TestRefreshIntervalSelectorSnapshot(t *testing.T) {
|
|
snapshot(t, "refresh_interval_selector", 420, 80, func(c *ui.Context) {
|
|
interval := 30 * time.Second
|
|
ui.Column(c).Padding(16).Children(func() {
|
|
RefreshIntervalSelector(c, &interval, RefreshIntervalSelectorOptions{})
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestRefreshIntervalSelectorKeyboardAncestorDisable(t *testing.T) {
|
|
interval := time.Duration(0)
|
|
disabled := false
|
|
changes, refreshes := 0, 0
|
|
tt := ui.NewTester(func(c *ui.Context) {
|
|
core.Use(c, core.Settings{})
|
|
ui.Column(c).Disabled(disabled).Children(func() {
|
|
r := RefreshIntervalSelector(c, &interval, RefreshIntervalSelectorOptions{})
|
|
if r.Changed {
|
|
changes++
|
|
}
|
|
if r.Refresh {
|
|
refreshes++
|
|
}
|
|
})
|
|
}, 500, 400)
|
|
_ = tt.Click("Refresh interval")
|
|
tt.Key(0, ui.KeyDown)
|
|
tt.Key(0, ui.KeyEnter)
|
|
if interval != 5*time.Second || changes != 1 {
|
|
t.Fatal("keyboard interval")
|
|
}
|
|
_ = tt.Click("Refresh interval")
|
|
disabled = true
|
|
tt.Key(0, ui.KeyDown)
|
|
tt.Key(0, ui.KeyEnter)
|
|
if interval != 5*time.Second || changes != 1 || refreshes != 0 || tt.HasText("Every 10 s") {
|
|
t.Fatal("disabled popup remained active")
|
|
}
|
|
}
|
|
|
|
func TestRefreshIntervalSelectorRejectsDuplicateIntervals(t *testing.T) {
|
|
defer func() {
|
|
if recover() == nil {
|
|
t.Fatal("duplicate intervals accepted")
|
|
}
|
|
}()
|
|
interval := time.Duration(0)
|
|
refreshes, changes := 0, 0
|
|
refreshTester(&interval, &RefreshIntervalSelectorOptions{Intervals: []time.Duration{time.Second, time.Second}}, &refreshes, &changes)
|
|
}
|