From c9b14125d826d2f9990f1366d13823b8714ee4d8 Mon Sep 17 00:00:00 2001 From: Adam Hunter Date: Mon, 14 Sep 2015 12:02:35 -0700 Subject: [PATCH 1/2] Add test that setting the center coordinate cancels animations --- test/ios/MapViewTests.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m index 98636d1a9..516ff1df8 100644 --- a/test/ios/MapViewTests.m +++ b/test/ios/MapViewTests.m @@ -220,6 +220,26 @@ @"panning map right should decrease center longitude"); } +- (void)testSetCenterCancelsTransitions { + CLLocationCoordinate2D dc = CLLocationCoordinate2DMake(38.894368, -77.036487); + CLLocationCoordinate2D dc_west = CLLocationCoordinate2DMake(38.894368, -77.076487); + [tester.mapView setCenterCoordinate:dc animated:NO]; + [tester.mapView setCenterCoordinate:dc_west animated:YES]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.15 * NSEC_PER_SEC), + dispatch_get_main_queue(), + ^{ + [tester.mapView setCenterCoordinate:dc animated:NO]; + XCTAssertEqualWithAccuracy(dc.latitude, + tester.mapView.centerCoordinate.latitude, + 0.0005, + @"setting center coordinate should cancel transitions"); + XCTAssertEqualWithAccuracy(dc.longitude, + tester.mapView.centerCoordinate.longitude, + 0.0005, + @"setting center coordinate should cancel transitions"); + }); +} + - (void)testPanDisabled { tester.mapView.scrollEnabled = NO; CLLocationCoordinate2D centerCoordinate = tester.mapView.centerCoordinate; From 620e554f677d05edd0a588b56f343435516c05a8 Mon Sep 17 00:00:00 2001 From: Adam Hunter Date: Tue, 15 Sep 2015 11:33:01 -0700 Subject: [PATCH 2/2] Fixes the test for setting center canceling animations. A good submit to look at for writing asynchronous tests. --- test/ios/MapViewTests.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m index 516ff1df8..d0913670c 100644 --- a/test/ios/MapViewTests.m +++ b/test/ios/MapViewTests.m @@ -221,6 +221,8 @@ } - (void)testSetCenterCancelsTransitions { + XCTestExpectation *cameraIsInDCExpectation = [self expectationWithDescription:@"camera reset to DC"]; + CLLocationCoordinate2D dc = CLLocationCoordinate2DMake(38.894368, -77.036487); CLLocationCoordinate2D dc_west = CLLocationCoordinate2DMake(38.894368, -77.076487); [tester.mapView setCenterCoordinate:dc animated:NO]; @@ -237,7 +239,12 @@ tester.mapView.centerCoordinate.longitude, 0.0005, @"setting center coordinate should cancel transitions"); + [cameraIsInDCExpectation fulfill]; }); + + [self waitForExpectationsWithTimeout:1.0 handler:^(NSError *error) { + ; + }]; } - (void)testPanDisabled {