diff options
Diffstat (limited to 'test/ios/MapViewTests.m')
-rw-r--r-- | test/ios/MapViewTests.m | 114 |
1 files changed, 112 insertions, 2 deletions
diff --git a/test/ios/MapViewTests.m b/test/ios/MapViewTests.m index 05eafa381c..3755da0bcd 100644 --- a/test/ios/MapViewTests.m +++ b/test/ios/MapViewTests.m @@ -6,6 +6,15 @@ #import "MapboxGL.h" #import "MGLTViewController.h" +#import "LocationMocker/LocationMocker.h" +#import <CoreLocation/CoreLocation.h> + +@interface MGLMapView (LocationManager) + +@property (nonatomic) CLLocationManager *locationManager; + +@end + @interface MapViewTests : KIFTestCase <MGLMapViewDelegate> @end @@ -13,8 +22,6 @@ @implementation MapViewTests - (void)beforeEach { - [tester acknowledgeSystemAlert]; - [system simulateDeviceRotationToOrientation:UIDeviceOrientationPortrait]; [tester.viewController resetMapView]; @@ -443,4 +450,107 @@ userInfo:@{ @"animated" : @(animated) }]; } +- (void)testDelegatesStartStopLocatingUser { + NSNotification *notification = [system waitForNotificationName:@"mapViewWillStartLocatingUser" + object:tester.mapView + whileExecutingBlock:^{ + tester.mapView.showsUserLocation = YES; + }]; + + XCTAssertEqualObjects(notification.name, + @"mapViewWillStartLocatingUser", + @"mapViewWillStartLocatingUser delegate should receive message"); + XCTAssertNotNil(tester.mapView.locationManager, + "map view location manager should not be nil"); + + notification = [system waitForNotificationName:@"mapViewDidStopLocatingUser" + object:tester.mapView + whileExecutingBlock:^{ + tester.mapView.showsUserLocation = NO; + }]; + + XCTAssertEqualObjects(notification.name, + @"mapViewDidStopLocatingUser", + @"mapViewDidStopLocatingUser delegate should receive message"); + XCTAssertEqual(tester.mapView.userTrackingMode, + MGLUserTrackingModeNone, + @"user tracking mode should be none"); + XCTAssertNil(tester.mapView.locationManager, + "map view location manager should be nil"); +} + +- (void)mapViewWillStartLocatingUser:(MGLMapView *)mapView { + [[NSNotificationCenter defaultCenter] postNotificationName:@"mapViewWillStartLocatingUser" object:mapView]; +} + +- (void)mapViewDidStopLocatingUser:(MGLMapView *)mapView { + [[NSNotificationCenter defaultCenter] postNotificationName:@"mapViewDidStopLocatingUser" object:mapView]; +} + +- (void)testUserTrackingModeFollow { + tester.mapView.userTrackingMode = MGLUserTrackingModeFollow; + + [tester waitForTimeInterval:1]; + + XCTAssertEqual(tester.mapView.userLocationVisible, + YES, + @"user location should be visible"); + XCTAssertEqual(tester.mapView.userLocation.coordinate.latitude, + kMockedLatitude, + @"user location latitude should match mocked latitude"); + XCTAssertEqual(tester.mapView.userLocation.coordinate.longitude, + kMockedLongitude, + @"user location longitude should match mocked longitude"); + + [tester.mapView dragFromPoint:CGPointMake(10, 10) toPoint:CGPointMake(50, 100) steps:10]; + + XCTAssertEqual(tester.mapView.userLocationVisible, + YES, + @"user location should still be visible after panning"); + XCTAssertEqual(tester.mapView.userTrackingMode, + MGLUserTrackingModeNone, + @"user tracking mode should reset to none"); +} + +// DOES NOT CURRENTLY PASS, bug with tracking mode not being set properly (or reset) +- (void)testUserTrackingModeFollowWithHeading { + tester.mapView.userTrackingMode = MGLUserTrackingModeFollowWithHeading; + + [tester waitForTimeInterval:1]; + + XCTAssertEqual(tester.mapView.userLocationVisible, + YES, + @"user location should be visible"); + XCTAssertEqual(tester.mapView.userLocation.coordinate.latitude, + kMockedLatitude, + @"user location latitude should match mocked latitude"); + XCTAssertEqual(tester.mapView.userLocation.coordinate.longitude, + kMockedLongitude, + @"user location longitude should match mocked longitude"); + + XCTAssertEqual(tester.mapView.userTrackingMode, + MGLUserTrackingModeFollowWithHeading, + @"user tracking mode should be follow with heading"); + XCTAssertEqual(tester.mapView.userLocation.heading.trueHeading, + kMockedHeadingTrueHeading, + @"user true heading should match mocked true heading"); + XCTAssertEqual(tester.mapView.userLocation.heading.headingAccuracy, + kMockedHeadingAccuracy, + @"user heading accuracy should match mocked accuracy"); + + [tester.compass tap]; + + [tester waitForTimeInterval:1]; + + XCTAssertEqual(tester.mapView.userLocationVisible, + YES, + @"user location should be visible"); + XCTAssertEqual(tester.mapView.userTrackingMode, + MGLUserTrackingModeFollow, + @"user tracking mode should be follow"); + XCTAssertEqual(tester.mapView.direction, + 0, + @"user heading should be reset to zero/north"); +} + @end |