diff options
-rw-r--r-- | platform/ios/test/MGLMapViewCompassViewTests.mm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/platform/ios/test/MGLMapViewCompassViewTests.mm b/platform/ios/test/MGLMapViewCompassViewTests.mm index 4e00d69a67..e38ba95efe 100644 --- a/platform/ios/test/MGLMapViewCompassViewTests.mm +++ b/platform/ios/test/MGLMapViewCompassViewTests.mm @@ -11,8 +11,9 @@ - (void)handleTapGesture:(__unused UITapGestureRecognizer *)sender; @end -@interface MGLCompassButtonTests : XCTestCase +@interface MGLCompassButtonTests : XCTestCase <MGLMapViewDelegate> @property (nonatomic) MGLMapView *mapView; +@property (nonatomic) XCTestExpectation *regionDidChangeExpectation; @end @implementation MGLCompassButtonTests @@ -23,11 +24,13 @@ [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; + self.mapView.delegate = self; } - (void)tearDown { self.mapView = nil; [MGLAccountManager setAccessToken:nil]; + self.regionDidChangeExpectation = nil; [super tearDown]; } @@ -88,7 +91,10 @@ XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should continue to be visible when direction changes."); + // Resetting to north happens with animation, so wait for it to finish. + self.regionDidChangeExpectation = [[XCTestExpectation alloc] initWithDescription:@"region-did-change"]; [self.mapView.compassView handleTapGesture:nil]; + [self waitForExpectations:@[self.regionDidChangeExpectation] timeout:5.0]; XCTAssertEqual(self.mapView.direction, 0, @"Tapping the compass should reset direction to north."); } @@ -109,4 +115,8 @@ return MGLDegreesFromRadians(angle); } +- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated { + [self.regionDidChangeExpectation fulfill]; +} + @end |