@@ -10,12 +10,14 @@ private struct TestMeasurer: ViewGraphGeometryMeasurer {
1010 typealias Proposal = CGSize
1111 typealias Size = CGFloat
1212
13+ static var mockValue : CGFloat ?
14+
1315 static func measure( given proposal: CGSize , in graph: ViewGraph ) -> CGFloat {
14- max ( proposal. width, proposal. height)
16+ mockValue ?? max ( proposal. width, proposal. height)
1517 }
1618
1719 static func measure( proposal: CGSize , layoutComputer: LayoutComputer , insets: EdgeInsets ) -> CGFloat {
18- max ( proposal. width, proposal. height)
20+ mockValue ?? max ( proposal. width, proposal. height)
1921 }
2022
2123 static var invalidValue : CGFloat = . nan
@@ -28,14 +30,19 @@ struct ViewGraphGeometryObserversTests {
2830 @MainActor
2931 @Test
3032 func observeCallback( ) async throws {
31- // TODO: when the callback got called.
32- await confirmation ( expectedCount: 0 ) { confirm in
33+ await confirmation ( expectedCount: 1 ) { confirm in
3334 var observers = Observers ( )
34- observers. addObserver ( for: CGSize ( width: 10 , height: 20 ) ) { _ , _ in
35+ observers. addObserver ( for: CGSize ( width: 10 , height: 20 ) ) { oldSize , newSize in
3536 confirm ( )
37+ #expect( oldSize. isApproximatelyEqual ( to: 20.0 ) )
38+ #expect( newSize. isApproximatelyEqual ( to: 30.0 ) )
3639 }
3740 let emptyViewGraph = ViewGraph ( rootViewType: EmptyView . self)
3841 _ = observers. needsUpdate ( graph: emptyViewGraph)
42+ TestMeasurer . mockValue = 30.0
43+ defer { TestMeasurer . mockValue = nil }
44+ _ = observers. needsUpdate ( graph: emptyViewGraph)
45+ observers. notify ( )
3946 }
4047 }
4148 #endif
0 commit comments