Skip to content

Commit 18141e6

Browse files
committed
Test DatePicker emission and round-trip
1 parent f0e5c06 commit 18141e6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests/ControlTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55

66
import Testing
7+
import Foundation
78
@testable import AndroidSwiftUICore
89

910
#if canImport(Observation)
@@ -194,4 +195,23 @@ struct ControlTests {
194195
#expect(node.props["text"] == .string("Coleman"))
195196
}
196197
#endif
198+
199+
@Test("DatePicker emits its selection in milliseconds and round-trips a change")
200+
func datePicker() {
201+
let initial = Date(timeIntervalSince1970: 1_768_435_200) // 2026-01-15T00:00:00Z
202+
let changed = Date(timeIntervalSince1970: 1_772_323_200) // 2026-03-01T00:00:00Z
203+
struct Screen: View {
204+
@State var date: Date
205+
var body: some View { DatePicker("Birthday", selection: $date) }
206+
}
207+
let host = ViewHost(Screen(date: initial))
208+
var node = host.evaluate()
209+
#expect(node.type == "DatePicker")
210+
#expect(node.props["millis"] == .double(initial.timeIntervalSince1970 * 1000))
211+
if case .int(let id)? = node.props["onChange"] {
212+
host.callbacks.invokeDouble(Int64(id), changed.timeIntervalSince1970 * 1000)
213+
}
214+
node = host.evaluate()
215+
#expect(node.props["millis"] == .double(changed.timeIntervalSince1970 * 1000))
216+
}
197217
}

0 commit comments

Comments
 (0)