Skip to content

Commit 48491fe

Browse files
committed
Test gesture and lifecycle modifier emission
1 parent bb4584b commit 48491fe

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests/EvaluatorTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,38 @@ struct ModifierTests {
146146
let limit = node.modifiers.first { $0.kind == "lineLimit" }
147147
#expect(limit?.args["count"] == .int(2))
148148
}
149+
150+
@Test("onTapGesture registers a callback and emits its id")
151+
func onTapGesture() {
152+
var tapped = false
153+
let host = ViewHost(Text("x").onTapGesture { tapped = true })
154+
let node = host.evaluate()
155+
let tap = node.modifiers.first { $0.kind == "onTapGesture" }
156+
guard case .int(let id)? = tap?.args["action"] else {
157+
Issue.record("missing action id"); return
158+
}
159+
host.callbacks.invokeVoid(Int64(id))
160+
#expect(tapped)
161+
}
162+
163+
@Test("onAppear and onDisappear emit distinct callback kinds")
164+
func appearDisappear() {
165+
let node = ViewHost(Text("x").onAppear {}.onDisappear {}).evaluate()
166+
#expect(node.modifiers.contains { $0.kind == "onAppear" })
167+
#expect(node.modifiers.contains { $0.kind == "onDisappear" })
168+
}
169+
170+
@Test("onChange emits a token describing the observed value")
171+
func onChange() {
172+
let node = ViewHost(Text("x").onChange(of: 42) {}).evaluate()
173+
let change = node.modifiers.first { $0.kind == "onChange" }
174+
#expect(change?.args["token"] == .string("42"))
175+
}
176+
177+
@Test("disabled emits its flag")
178+
func disabled() {
179+
let node = ViewHost(Text("x").disabled(true)).evaluate()
180+
let flag = node.modifiers.first { $0.kind == "disabled" }
181+
#expect(flag?.args["value"] == .bool(true))
182+
}
149183
}

0 commit comments

Comments
 (0)