From e3992c41c354e70f2c6762690b428f0ebbe362f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 19 Nov 2015 22:16:02 -0800 Subject: [iOS] Wait for didChange notifications instead of timer --- test/ios/MapViewTests.m | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'test/ios') diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m index 01c2beafe2..149e2e8be0 100644 --- a/test/ios/MapViewTests.m +++ b/test/ios/MapViewTests.m @@ -9,15 +9,25 @@ #import #import -const NSTimeInterval MGLAnimationDurationDefault = 0.3; -const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefault * 2; - @interface MapViewTests : KIFTestCase @end @implementation MapViewTests +- (NSNotification *)waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:(void (^)())block { + [[NSNotificationCenter defaultCenter] addObserverForName:@"regionDidChangeAnimated" + object:tester.mapView + queue:nil + usingBlock:^(NSNotification * _Nonnull note) {}]; + NSNotification *notification = [system waitForNotificationName:@"regionDidChangeAnimated" + object:tester.mapView whileExecutingBlock:block]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:@"regionDidChangeAnimated" + object:tester.mapView]; + return notification; +} + - (void)beforeEach { [system simulateDeviceRotationToOrientation:UIDeviceOrientationPortrait]; [tester.viewController resetMapView]; @@ -36,8 +46,6 @@ const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefau tester.viewController.navigationController.toolbarHidden = YES; tester.mapView.delegate = self; - - [tester waitForTimeInterval:0.5]; } - (void)approveLocationIfNeeded { @@ -50,8 +58,9 @@ const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefau } - (void)testDirectionSet { - [tester.mapView setDirection:270 animated:YES]; - [tester waitForTimeInterval:MGLAnimationDurationOverDefault]; + [self waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:^{ + [tester.mapView setDirection:270 animated:YES]; + }]; XCTAssertEqual(tester.mapView.direction, 270, @@ -68,15 +77,17 @@ const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefau } - (void)testCompassTap { - [tester.mapView setDirection:180 animated:YES]; - [tester waitForTimeInterval:MGLAnimationDurationOverDefault]; + [self waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:^{ + [tester.mapView setDirection:180 animated:YES]; + }]; XCTAssertEqual(tester.mapView.direction, 180, @"setting direction should take effect"); - [tester.compass tap]; - [tester waitForTimeInterval:MGLAnimationDurationOverDefault]; + [self waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:^{ + [tester.compass tap]; + }]; XCTAssertEqual(tester.mapView.direction, 0, @@ -92,15 +103,17 @@ const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefau } - (void)testDirectionReset { - [tester.mapView setDirection:90 animated:YES]; - [tester waitForTimeInterval:MGLAnimationDurationOverDefault]; + [self waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:^{ + [tester.mapView setDirection:90 animated:YES]; + }]; XCTAssertEqual(tester.mapView.direction, 90, @"setting direction should take effect"); - [tester.mapView resetNorth]; - [tester waitForTimeInterval:MGLAnimationDurationOverDefault]; + [self waitForNotificationThatRegionDidChangeAnimatedWhileExecutingBlock:^{ + [tester.mapView resetNorth]; + }]; XCTAssertEqual(tester.mapView.direction, 0, -- cgit v1.2.1