Skip to content

Commit 90d36e1

Browse files
committed
Test Stepper, SecureField, and Menu
1 parent e4790c2 commit 90d36e1

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests/ControlTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ struct ControlTests {
7676
#expect(node.props["selection"] == .string("Banana"))
7777
}
7878

79+
@Test("Stepper increments and decrements within bounds, updating its label")
80+
func stepper() {
81+
struct Screen: View {
82+
@State var count = 5
83+
var body: some View { Stepper("Count: \(count)", value: $count, in: 0...10) }
84+
}
85+
let host = ViewHost(Screen())
86+
var node = host.evaluate()
87+
#expect(node.type == "Stepper")
88+
if case .int(let inc)? = node.props["onIncrement"] { host.callbacks.invokeVoid(Int64(inc)) }
89+
node = host.evaluate()
90+
#expect(firstTextString(node) == "Count: 6")
91+
if case .int(let dec)? = node.props["onDecrement"] { host.callbacks.invokeVoid(Int64(dec)) }
92+
node = host.evaluate()
93+
#expect(firstTextString(node) == "Count: 5")
94+
}
95+
96+
@Test("SecureField emits a secure TextField node")
97+
func secureField() {
98+
struct Screen: View {
99+
@State var password = ""
100+
var body: some View { SecureField("Password", text: $password) }
101+
}
102+
let node = ViewHost(Screen()).evaluate()
103+
#expect(node.type == "TextField")
104+
#expect(node.props["secure"] == .bool(true))
105+
}
106+
107+
@Test("Menu emits its label and item children")
108+
func menu() {
109+
let node = ViewHost(Menu("Options") {
110+
Button("First") {}
111+
Button("Second") {}
112+
}).evaluate()
113+
#expect(node.type == "Menu")
114+
#expect(node.props["label"] == .string("Options"))
115+
#expect(node.children.count == 2)
116+
}
117+
79118
@Test("Environment objects reach @Environment properties in the subtree")
80119
func environmentInjection() {
81120
final class Model { var value = 42 }

0 commit comments

Comments
 (0)