@@ -87,73 +87,90 @@ final class InteractionsTests: IntegrationTestCase {
8787 return true
8888 } )
8989
90- let anyLongPressExpectation = expectation ( description: " Any Long press " )
91- anyLongPressExpectation. expectedFulfillmentCount = 1
92- anyLongPressExpectation. isInverted = true
93-
9490 map. addInteraction ( LongPressInteraction { _ in
95- anyLongPressExpectation . fulfill ( )
91+ XCTFail ( " Long press handler should not be called for tap events " )
9692 return false
9793 } )
9894
9995 map. addInteraction ( LongPressInteraction ( . layer( " circle-1 " ) ) { _, _ in
100- anyLongPressExpectation . fulfill ( )
96+ XCTFail ( " Long press handler should not be called for tap events " )
10197 return false
10298 } )
10399
104100 map. addInteraction ( LongPressInteraction ( . featureset( " poi " , importId: " nested " ) ) { _, _ in
105- anyLongPressExpectation . fulfill ( )
101+ XCTFail ( " Long press handler should not be called for tap events " )
106102 return false
107103 } )
108104
109105 // Layer tap
110106 coord = CLLocationCoordinate2D ( latitude: 0 , longitude: 0 )
111107 point = map. point ( for: coord)
112108 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
113- wait ( for: [ layerExpectation] , timeout: 2 .0)
109+ wait ( for: [ layerExpectation] , timeout: 5 .0)
114110
115111 // POI tap
116112 coord = CLLocationCoordinate2D ( latitude: 0.01 , longitude: 0.01 )
117113 point = map. point ( for: coord)
118114 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
119- wait ( for: [ poiExpectation] , timeout: 2 .0)
115+ wait ( for: [ poiExpectation] , timeout: 5 .0)
120116
121117 // Map tap
122118 coord = CLLocationCoordinate2D ( latitude: - 0.01 , longitude: - 0.01 )
123119 point = map. point ( for: coord)
124120 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
125- wait ( for: [ mapExpectation] , timeout: 2 .0)
121+ wait ( for: [ mapExpectation] , timeout: 5 .0)
126122
127- // No long press invoked
128- wait ( for: [ anyLongPressExpectation] , timeout: 2.0 )
123+ // Verify no long press was invoked - give events time to process
124+ let verifyExpectation = expectation ( description: " verify no long press " )
125+ DispatchQueue . main. async {
126+ verifyExpectation. fulfill ( )
127+ }
128+ wait ( for: [ verifyExpectation] , timeout: 2.0 )
129129 }
130130
131131 func testTapInteractionWithRadius( ) {
132132 let tap1 = expectation ( description: " tap 1 " )
133133 let tap2 = expectation ( description: " tap 2 " )
134- let tap3 = expectation ( description: " tap 3 " )
135- tap3. isInverted = true
136134
137- var queue = [ tap3 , tap2 , tap1 ]
135+ var tapCount = 0
138136
139137 map. addInteraction ( TapInteraction ( . featureset( " poi " , importId: " nested " ) , radius: 5 ) { _, _ in
140- queue. popLast ( ) ? . fulfill ( )
138+ tapCount += 1
139+ if tapCount == 1 {
140+ tap1. fulfill ( )
141+ } else if tapCount == 2 {
142+ tap2. fulfill ( )
143+ }
141144 return true
142145 } )
143146
144147 let coord = CLLocationCoordinate2D ( latitude: 0.01 , longitude: 0.01 )
145148 var point = map. point ( for: coord)
149+
150+ // First tap: directly on feature (should trigger)
146151 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
147- wait ( for: [ tap1] , timeout: 2 .0)
152+ wait ( for: [ tap1] , timeout: 5 .0)
148153
149- // circle radius is 5, adding 3 to check tap with the radius
154+ // Second tap: 8 pixels away (within radius of 5 + feature size, should trigger)
150155 point. x += 8
151156 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
152- wait ( for: [ tap2] , timeout: 2 .0)
157+ wait ( for: [ tap2] , timeout: 5 .0)
153158
159+ // Third tap: 5 additional pixels away (13 total, outside radius, should NOT trigger)
154160 point. x += 5
161+ let initialTapCount = tapCount
162+
163+ // Dispatch the event
155164 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
156- wait ( for: [ tap3] , timeout: 2.0 )
165+
166+ // Wait for any pending main queue operations to complete
167+ let verifyExpectation = expectation ( description: " verify no tap " )
168+ // Give event processing one full runloop cycle to complete
169+ DispatchQueue . main. async {
170+ XCTAssertEqual ( tapCount, initialTapCount, " Handler should not be called for tap outside radius " )
171+ verifyExpectation. fulfill ( )
172+ }
173+ wait ( for: [ verifyExpectation] , timeout: 2.0 )
157174 }
158175
159176 func testTapWithFilter( ) {
@@ -184,7 +201,7 @@ final class InteractionsTests: IntegrationTestCase {
184201
185202 // POI click
186203 map. dispatch ( event: CorePlatformEventInfo ( type: . click, screenCoordinate: point. screenCoordinate) )
187- wait ( for: [ poiExpectation] , timeout: 2 .0)
204+ wait ( for: [ poiExpectation] , timeout: 5 .0)
188205 }
189206
190207 func testLongPressInteraction( ) {
@@ -239,44 +256,44 @@ final class InteractionsTests: IntegrationTestCase {
239256 return true
240257 } )
241258
242- let anyTapExpectation = expectation ( description: " Any Long press " )
243- anyTapExpectation. expectedFulfillmentCount = 1
244- anyTapExpectation. isInverted = true
245-
246259 map. addInteraction ( TapInteraction { _ in
247- anyTapExpectation . fulfill ( )
260+ XCTFail ( " Tap handler should not be called for long press events " )
248261 return false
249262 } )
250263
251264 map. addInteraction ( TapInteraction ( . layer( " circle-1 " ) ) { _, _ in
252- anyTapExpectation . fulfill ( )
265+ XCTFail ( " Tap handler should not be called for long press events " )
253266 return false
254267 } )
255268
256269 map. addInteraction ( TapInteraction ( . featureset( " poi " , importId: " nested " ) ) { _, _ in
257- anyTapExpectation . fulfill ( )
270+ XCTFail ( " Tap handler should not be called for long press events " )
258271 return false
259272 } )
260273
261274 // Layer long press
262275 coord = CLLocationCoordinate2D ( latitude: 0 , longitude: 0 )
263276 point = map. point ( for: coord)
264277 map. dispatch ( event: CorePlatformEventInfo ( type: . longClick, screenCoordinate: point. screenCoordinate) )
265- wait ( for: [ layerExpectation] , timeout: 2 .0)
278+ wait ( for: [ layerExpectation] , timeout: 5 .0)
266279
267280 // POI long press
268281 coord = CLLocationCoordinate2D ( latitude: 0.01 , longitude: 0.01 )
269282 point = map. point ( for: coord)
270283 map. dispatch ( event: CorePlatformEventInfo ( type: . longClick, screenCoordinate: point. screenCoordinate) )
271- wait ( for: [ poiExpectation] , timeout: 2 .0)
284+ wait ( for: [ poiExpectation] , timeout: 5 .0)
272285
273286 // Map long press
274287 coord = CLLocationCoordinate2D ( latitude: - 0.01 , longitude: - 0.01 )
275288 point = map. point ( for: coord)
276289 map. dispatch ( event: CorePlatformEventInfo ( type: . longClick, screenCoordinate: point. screenCoordinate) )
277- wait ( for: [ mapExpectation] , timeout: 2 .0)
290+ wait ( for: [ mapExpectation] , timeout: 5 .0)
278291
279- // No tap is invoked
280- wait ( for: [ anyTapExpectation] , timeout: 2.0 )
292+ // Verify no tap was invoked - give events time to process
293+ let verifyExpectation = expectation ( description: " verify no tap " )
294+ DispatchQueue . main. async {
295+ verifyExpectation. fulfill ( )
296+ }
297+ wait ( for: [ verifyExpectation] , timeout: 2.0 )
281298 }
282299}
0 commit comments