summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-11-19 22:16:02 -0800
committerMinh Nguyễn <mxn@1ec5.org>2015-11-25 14:39:32 -0800
commite3992c41c354e70f2c6762690b428f0ebbe362f4 (patch)
tree5159c2db8fb5d97b07c5bb717a97ffb28caa9ae8 /test
parent6916675e61d73c4da2d19aceb4e33471fa3915f1 (diff)
downloadqtlocation-mapboxgl-e3992c41c354e70f2c6762690b428f0ebbe362f4.tar.gz
[iOS] Wait for didChange notifications instead of timer
Diffstat (limited to 'test')
-rw-r--r--test/ios/MapViewTests.m43
1 files changed, 28 insertions, 15 deletions
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 <CoreLocation/CoreLocation.h>
#import <KIF/UIAutomationHelper.h>
-const NSTimeInterval MGLAnimationDurationDefault = 0.3;
-const NSTimeInterval MGLAnimationDurationOverDefault = MGLAnimationDurationDefault * 2;
-
@interface MapViewTests : KIFTestCase <MGLMapViewDelegate>
@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,