Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Make `nsgotest` steps advance through pending style transitions so `OnTransitionEnd` and closing popups settle before a step returns (#335 by @houko).
- Add HarmonyOS as a preview target, whose ArkTS host runs the engine in ArkWeb and draws it with ArkUI views, in `nsgo build`, `nsgo run` and `nsgo test -target harmonyos` (#79 by @togotop).
- Add in-app purchases on macOS, iOS and tvOS through StoreKit 2: the store's products and prices, purchases answering cancelled and pending apart from failed with the signed transaction, updates made outside the app, finishing, current entitlements and restoring, in Go, TSX and `nsgotest`, when `nsgo.yaml` sets `apple.purchases` (#353 by @houko).
- Add `desktop.SetWindowWorkspaces` and `WindowOptions.Workspaces`, which keep a window on every Space and over other apps' full screen spaces on macOS, at any level but the desktop's, which stays behind them, and on every virtual desktop on X11, with `desktop.CanSetWindowWorkspaces`, which says whether it takes effect (#572 by @houko).
Expand Down
2 changes: 1 addition & 1 deletion base/confirm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestReturnRunsTheDefaultActionOnce(t *testing.T) {
AccessibilityDescription: "They are lost otherwise.", TestID: "layer", Children: content, Animation: core.ModalNone,
PopupStyle: core.Style{Transition: core.Transition{Duration: 200 * time.Millisecond, Properties: core.TransitionOpacity}},
EndingStyle: core.Style{Opacity: core.Alpha(0)}}
}, nsgotest.Environment(c.env))
}, nsgotest.Environment(c.env), nsgotest.ManualFrames())
layer := app.Find("role:alertdialog")
if layer.Props.Label != "Save" || layer.Props.Description != "They are lost otherwise." {
t.Fatalf("layer accessibility = %+v", layer.Props)
Expand Down
2 changes: 1 addition & 1 deletion base/menukeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestAMenuGoingTakesNoKeys(t *testing.T) {
base.MenuItem{Label: "Copy", OnSelect: func() { chosen = append(chosen, "Copy") }, Style: core.Style{Height: core.Pt(30), Width: core.Pt(100)}},
base.MenuItem{Label: "Paste", OnSelect: func() { chosen = append(chosen, "Paste") }, Style: core.Style{Height: core.Pt(30), Width: core.Pt(100)}},
}}
}, nsgotest.Environment(core.Environment{Idiom: core.IdiomDesktop, OS: core.OSMacOS}))
}, nsgotest.Environment(core.Environment{Idiom: core.IdiomDesktop, OS: core.OSMacOS}), nsgotest.ManualFrames())
app.Key("tab")
app.Key("enter")
app.Key("enter")
Expand Down
6 changes: 3 additions & 3 deletions base/popups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ func TestPopoversOnTouchScreensTakeThePressOutside(t *testing.T) {

func TestDesktopPopupsComeInAndGoThroughTheirPhases(t *testing.T) {
var log []string
app := startDesktop(t, func(cx *core.Scope) core.Node {
app := nsgotest.Start(t, func(cx *core.Scope) core.Node {
return base.Popover{Trigger: core.Text{Content: "Pop"}, Label: "Pop",
OnOpen: func() { log = append(log, "open") }, OnClose: func() { log = append(log, "close") },
PopupClass: "transition-opacity duration-200", StartingClass: "opacity-0", EndingClass: "opacity-0",
Children: []core.Node{core.Text{Content: "inside"}}}
})
}, nsgotest.Environment(core.Environment{Idiom: core.IdiomDesktop}), nsgotest.ManualFrames())
opacity := func() float32 { return app.Find("text:inside").Parent.Style.Opacity }
app.Press("label:Pop")
if got := opacity(); got != 0 {
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestPopoverGivesTheFocusBackAsItCloses(t *testing.T) {
Children: []core.Node{core.Input{Ref: field, TestID: "field", Style: core.Style{Width: core.Pt(80), Height: core.Pt(20)}}}},
base.Button{Label: "Other", TestID: "other", OnPress: func(core.PressEvent) {}, Style: core.Style{Height: core.Pt(20)}},
}}
}, nsgotest.Environment(core.Environment{Idiom: core.IdiomDesktop, OS: core.OSMacOS}))
}, nsgotest.Environment(core.Environment{Idiom: core.IdiomDesktop, OS: core.OSMacOS}), nsgotest.ManualFrames())
app.Key("tab")
app.Key("enter")
if !app.Find("id:field").Focused {
Expand Down
11 changes: 11 additions & 0 deletions core/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ func (t *Tree) timeTransitionEnds() {
t.ending = t.ending[:0]
}

// PendingTransitionEnds reports whether a live view has a style transition
// whose OnTransitionEnd callback has not run yet.
func (t *Tree) PendingTransitionEnds() bool {
for _, n := range t.nodes {
if n != nil && !n.deleted && !n.owner.disposed && n.endStop != nil {
return true
}
}
return false
}

// shrinkItems drops the items' slice for a smaller one once a commit of n
// items left most of it unused: the slice the first commit grew would stay
// this tree's capacity for good, and a long list keep megabytes for the
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Steps (`steps.go`, `pointer.go`) act as a user does and send what a platform sen

`Ref.Focus` commands follow the same platform stops in the headless model: phones focus fields, while desktop and web environments also focus enabled pressable and `Focusable` views. A plain, hidden or `NoFocus` view or a view covered by a modal leaves the current focus alone. This differs from the `Focus` step, which reaches a stop as a user does.

Each step then takes frames while an animation that ends runs or a list binds the rows it paces ([lists](scrolling.md#lists)), for at most 2 seconds of clock time. Frames the app requests itself do not hold a step, since its own loops may never end; `ManualFrames` keeps steps from taking frames at all, for tests that look at animations on the way. `Advance` moves the clock a frame at a time; `FastForward` jumps it, running each due timer once.
Each step then takes frames while an animation that ends, a style transition whose `OnTransitionEnd` is pending, or a list binds the rows it paces ([lists](scrolling.md#lists)), for at most 2 seconds of clock time. Frames the app requests itself do not hold a step, since its own loops may never end; `ManualFrames` keeps steps from taking frames at all, for tests that look at animations on the way. `Advance` moves the clock a frame at a time; `FastForward` jumps it, running each due timer once.

Headless `nsgo test` adds `nsgocheck` to the effective build tags, preserving `GOFLAGS` and explicit `-- -tags` values. In such a build, each graph created with `RootOptions.CheckCommits` (every `nsgotest` app outside `Measure`, and the core's test graphs) records its creating goroutine and rejects access from another, while the graph is idle, with a `Scope.Post` diagnostic ([core](core.md)); an engine passes `engine.Options.CheckCommits` to its root. Target tests include the same diagnostics under `nsgotest`. Native `nsgodev` builds enable them; release builds contain no goroutine lookup or ownership branch; WebAssembly omits this goroutine-ID assertion in development and test builds because browser callbacks may resume on a different managed goroutine; commit-consistency checks still run. On native hosts, test graphs and their cleanup must run on the same goroutine.

Expand Down
2 changes: 1 addition & 1 deletion docs/public/en/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ An Android test that panics or exits before reporting its result fails with the

On `web` the tests run in a headless Chrome, Chromium or Edge the tool finds, or in the browser executable `NSGO_BROWSER` names. The tool waits up to 30 seconds for it to start, stops waiting when the command is cancelled, and reports the browser's error output if it exits or never answers.

Each step, and `app.Settle()`, waits for the engine's pending commit before counting 100 ms without batches or finite animations. The whole wait stops after five seconds even if the app keeps changing; a slow first dialog needs no extra post or sleep in the test.
Each step, and `app.Settle()`, waits for the engine's pending commit before counting 100 ms without batches or finite animations. Headless steps also advance style transitions until their `OnTransitionEnd` callbacks run. The whole wait stops after five seconds even if the app keeps changing; a slow first dialog needs no extra post or sleep in the test.

On Android, the tool wakes a sleeping screen and dismisses a lock screen without a credential before building and before each test. A device locked with a PIN, password or pattern must be unlocked before the run can continue; the error names the device.

Expand Down
2 changes: 1 addition & 1 deletion docs/public/zh/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ go tool nsgo test -target macos

在 `web` 上,测试运行在工具找到的无头 Chrome、Chromium 或 Edge 中,也可以用 `NSGO_BROWSER` 指定浏览器的可执行文件。工具最多等待 30 秒让它启动,命令被取消时立即停止等待;浏览器提前退出或一直不响应时,会报告它的错误输出。

每个步骤和 `app.Settle()` 都会先等引擎完成待提交的更新,再等待连续 100 ms 没有新批次或有限动画。即使应用持续变化,整个等待也会在五秒后结束;首次构建较慢的对话框不需要测试额外投递任务或休眠。
每个步骤和 `app.Settle()` 都会先等引擎完成待提交的更新,再等待连续 100 ms 没有新批次或有限动画。无头步骤也会推进样式过渡,直到它们的 `OnTransitionEnd` 回调执行。即使应用持续变化,整个等待也会在五秒后结束;首次构建较慢的对话框不需要测试额外投递任务或休眠。

在 Android 上,工具会在构建前和每个测试前唤醒休眠的屏幕,并关闭没有凭据的锁屏。设有 PIN、密码或图案的设备必须先解锁才能继续;错误消息会指出设备。

Expand Down
2 changes: 1 addition & 1 deletion nsgotest/nsgotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func (a *App) done() {
}
a.Settle()
limit := a.Clock.Now().Add(settleLimit)
for !a.manualFrames && (a.anim.Ending() || a.tree.Pacing()) && a.Clock.Now().Before(limit) {
for !a.manualFrames && (a.anim.Ending() || a.tree.Pacing() || a.tree.PendingTransitionEnds()) && a.Clock.Now().Before(limit) {
a.Clock.Advance(driver.FrameInterval)
a.runFrame()
a.Settle()
Expand Down
57 changes: 57 additions & 0 deletions nsgotest/nsgotest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,68 @@ import (
"testing"
"time"

"github.com/nsgo-dev/nsgo/base"
"github.com/nsgo-dev/nsgo/core"
"github.com/nsgo-dev/nsgo/desktop"
"github.com/nsgo-dev/nsgo/internal/driver"
)

func TestStepsWaitForEndingStyleTransition(t *testing.T) {
var open *core.Signal[bool]
app := Start(t, func(cx *core.Scope) core.Node {
open = core.NewSignal(cx, true)
return base.Dialog{
Open: open.Get, Animation: core.ModalNone, TestID: "dialog",
PopupStyle: core.Style{
Width: core.Pt(100), Height: core.Pt(100),
Transition: core.Transition{Duration: 200 * time.Millisecond, Properties: core.TransitionOpacity},
},
EndingStyle: core.Style{Opacity: core.Alpha(0)},
After: []core.Node{core.View{
Role: core.RoleButton, Label: "close", TestID: "close",
OnPress: func(core.PressEvent) { open.Set(false) },
Style: core.Style{Width: core.Pt(40), Height: core.Pt(40)},
}},
}
})
app.Press("id:close")
if app.Exists("id:dialog") {
t.Fatal("Press returned while the dialog's ending transition still runs")
}
}

func TestManualFramesKeepsEndingStyleTransitionPending(t *testing.T) {
var open *core.Signal[bool]
app := Start(t, func(cx *core.Scope) core.Node {
open = core.NewSignal(cx, true)
return base.Dialog{
Open: open.Get, Animation: core.ModalNone, TestID: "dialog",
PopupStyle: core.Style{
Width: core.Pt(100),
Height: core.Pt(100),
Transition: core.Transition{
Duration: 200 * time.Millisecond,
Properties: core.TransitionOpacity,
},
},
EndingStyle: core.Style{Opacity: core.Alpha(0)},
After: []core.Node{core.View{
Role: core.RoleButton, Label: "close", TestID: "close",
OnPress: func(core.PressEvent) { open.Set(false) },
Style: core.Style{Width: core.Pt(40), Height: core.Pt(40)},
}},
}
}, ManualFrames())
app.Press("id:close")
if !app.Exists("id:dialog") {
t.Fatal("ManualFrames advanced the ending transition")
}
app.Advance(200 * time.Millisecond)
if app.Exists("id:dialog") {
t.Fatal("ending transition did not finish after Advance")
}
}

// Frames follow the manual clock: Advance runs the frame an app waits for
// at each display interval, with the frame's time from that clock.
func TestFramesFollowTheClock(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion ui/dialog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/nsgo-dev/nsgo/base"
"github.com/nsgo-dev/nsgo/core"
"github.com/nsgo-dev/nsgo/nsgotest"
)

// TestDialog opens a dialog, centered on desktops and a sheet on phones,
Expand All @@ -15,6 +16,10 @@ import (
func TestDialog(t *testing.T) {
each(t, func(t *testing.T, e core.Environment) {
var confirmed bool
var opts []nsgotest.Option
if e.Idiom == core.IdiomDesktop {
opts = append(opts, nsgotest.ManualFrames())
}
app, p := start(t, e, func(cx *core.Scope) core.Node {
open, alert := core.NewSignal(cx, false), core.NewSignal(cx, false)
return core.View{Style: core.Style{AlignItems: core.AlignStart, Gap: 8}, Children: []core.Node{
Expand All @@ -30,7 +35,7 @@ func TestDialog(t *testing.T) {
Actions: []AlertAction{{Text: "Cancel", Variant: ButtonSecondary, TestID: "keep"},
{Text: "Delete", Color: ColorsOf(cx).Danger, TestID: "confirm", OnPress: func() { confirmed = true }}}},
}}
})
}, opts...)
app.Press("open")
d := app.Find("dialog")
if e.Idiom == core.IdiomDesktop {
Expand Down
2 changes: 1 addition & 1 deletion ui/tabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestTabsContent(t *testing.T) {
// TestTabsSlide slides the indicator on a change of tab alone.
func TestTabsSlide(t *testing.T) {
headless(t)
app, _ := start(t, desktopEnv, tabsContent)
app, _ := start(t, desktopEnv, tabsContent, nsgotest.ManualFrames())
thumb := func() *nsgotest.View { return app.Find("segmented").Children[0] }
if d := thumb().Style.Transition.Duration; d != 0 {
t.Fatalf("the first placement slides for %v", d)
Expand Down
Loading