diff options
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/MGLAnnotationViewTests.m | 63 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewLayoutTests.m | 5 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewScaleBarTests.m | 62 | ||||
-rw-r--r-- | platform/ios/test/MGLNSOrthographyAdditionsTests.m | 4 |
4 files changed, 129 insertions, 5 deletions
diff --git a/platform/ios/test/MGLAnnotationViewTests.m b/platform/ios/test/MGLAnnotationViewTests.m index fc4f35a9e1..2f5963e66e 100644 --- a/platform/ios/test/MGLAnnotationViewTests.m +++ b/platform/ios/test/MGLAnnotationViewTests.m @@ -49,7 +49,7 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu _didCallDismissCalloutAnimated = YES; } -- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated { } +- (void)presentCalloutFromRect:(CGRect)rect inView:(nonnull UIView *)view constrainedToRect:(CGRect)constrainedRect animated:(BOOL)animated {} @end @@ -57,6 +57,7 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu @property (nonatomic) XCTestExpectation *expectation; @property (nonatomic) MGLMapView *mapView; @property (nonatomic, weak) MGLAnnotationView *annotationView; +@property (nonatomic) NSInteger annotationSelectedCount; @end @implementation MGLAnnotationViewTests @@ -98,6 +99,61 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu XCTAssertNotNil(customAnnotationView); } +- (void)testSelectingOffscreenAnnotation +{ + // Partial test for https://github.com/mapbox/mapbox-gl-native/issues/9790 + + // This isn't quite the same as in updateAnnotationViews, but should be sufficient for this test. + MGLCoordinateBounds coordinateBounds = [_mapView convertRect:_mapView.bounds toCoordinateBoundsFromView:_mapView]; + + // -90 latitude is invalid. TBD. + BOOL anyOffscreen = NO; + NSInteger selectionCount = 0; + + for (NSInteger latitude = -89; latitude <= 90; latitude += 10) + { + for (NSInteger longitude = -180; longitude <= 180; longitude += 10) + { + MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init]; + + annotation.coordinate = CLLocationCoordinate2DMake(latitude, longitude); + [_mapView addAnnotation:annotation]; + + if (!(MGLCoordinateInCoordinateBounds(annotation.coordinate, coordinateBounds))) + anyOffscreen = YES; + + XCTAssertNil(_mapView.selectedAnnotations.firstObject, @"There should be no selected annotation"); + + // First selection + [_mapView selectAnnotation:annotation animated:NO]; + selectionCount++; + + XCTAssert(_mapView.selectedAnnotations.count == 1, @"There should only be 1 selected annotation"); + XCTAssertEqualObjects(_mapView.selectedAnnotations.firstObject, annotation, @"The annotation should be selected"); + + // Deselect + [_mapView deselectAnnotation:annotation animated:NO]; + XCTAssert(_mapView.selectedAnnotations.count == 0, @"There should be no selected annotations"); + + // Second selection + _mapView.selectedAnnotations = @[annotation]; + selectionCount++; + + XCTAssert(_mapView.selectedAnnotations.count == 1, @"There should be 1 selected annotation"); + XCTAssertEqualObjects(_mapView.selectedAnnotations.firstObject, annotation, @"The annotation should be selected"); + + // Deselect + [_mapView deselectAnnotation:annotation animated:NO]; + XCTAssert(_mapView.selectedAnnotations.count == 0, @"There should be no selected annotations"); + } + } + + XCTAssert(anyOffscreen, @"At least one of these annotations should be offscreen"); + XCTAssertEqual(selectionCount, self.annotationSelectedCount, @"-mapView:didSelectAnnotation: should be called for each selection"); +} + +#pragma mark - MGLMapViewDelegate - + - (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation { MGLAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:MGLTestAnnotationReuseIdentifer]; @@ -117,4 +173,9 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu [_expectation fulfill]; } +- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation +{ + self.annotationSelectedCount++; +} + @end diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m index e707cfdb41..16f6cdada3 100644 --- a/platform/ios/test/MGLMapViewLayoutTests.m +++ b/platform/ios/test/MGLMapViewLayoutTests.m @@ -37,14 +37,15 @@ self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; [self waitForExpectationsWithTimeout:1 handler:nil]; + self.mapView.showsScale = YES; + //set zoom and heading so that scale bar and compass will be shown - [self.mapView setZoomLevel:4.5 animated:NO]; + [self.mapView setZoomLevel:10.0 animated:NO]; [self.mapView.camera setHeading:12.0]; //invoke layout [self.superView setNeedsLayout]; [self.superView layoutIfNeeded]; - } - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { diff --git a/platform/ios/test/MGLMapViewScaleBarTests.m b/platform/ios/test/MGLMapViewScaleBarTests.m new file mode 100644 index 0000000000..11d1187263 --- /dev/null +++ b/platform/ios/test/MGLMapViewScaleBarTests.m @@ -0,0 +1,62 @@ +#import <Mapbox/Mapbox.h> +#import <XCTest/XCTest.h> + +@interface MGLMapViewScaleBarTests : XCTestCase + +@property (nonatomic) MGLMapView *mapView; + +@end + +@implementation MGLMapViewScaleBarTests + +- (void)setUp { + [super setUp]; + + [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]; +} + +- (void)tearDown { + self.mapView = nil; + + [super tearDown]; +} + +- (void)testShowsScale { + UIView *scaleBar = self.mapView.scaleBar; + + // Scale bar should not be enabled by default. + XCTAssertFalse(self.mapView.showsScale); + XCTAssertTrue(scaleBar.hidden); + + self.mapView.showsScale = YES; + + XCTAssertFalse(scaleBar.hidden); + + // Scale bar should not be visible at default zoom (~z0), but it should be ready. + XCTAssertFalse(CGRectIsEmpty(scaleBar.frame)); + XCTAssertEqual(scaleBar.alpha, 0); + + self.mapView.zoomLevel = 15; + XCTAssertGreaterThan(scaleBar.alpha, 0); +} + +- (void)testDirectlySettingScaleBarViewHiddenProperty { + UIView *scaleBar = self.mapView.scaleBar; + + scaleBar.hidden = NO; + XCTAssertFalse(scaleBar.hidden); + + // Directly setting `.hidden` after the map has finished initializing will not update the scale bar. + XCTAssertTrue(CGRectIsEmpty(scaleBar.frame)); + + // ... but triggering any camera event will update it. + self.mapView.zoomLevel = 1; + XCTAssertFalse(CGRectIsEmpty(scaleBar.frame)); + XCTAssertEqual(scaleBar.alpha, 0); + + self.mapView.zoomLevel = 15; + XCTAssertGreaterThan(scaleBar.alpha, 0); +} +@end diff --git a/platform/ios/test/MGLNSOrthographyAdditionsTests.m b/platform/ios/test/MGLNSOrthographyAdditionsTests.m index 351fe4227e..f30553e8f6 100644 --- a/platform/ios/test/MGLNSOrthographyAdditionsTests.m +++ b/platform/ios/test/MGLNSOrthographyAdditionsTests.m @@ -1,7 +1,7 @@ #import <XCTest/XCTest.h> #import "NSOrthography+MGLAdditions.h" -#import "MGLVectorSource_Private.h" +#import "MGLVectorTileSource_Private.h" @interface MGLNSOrthographyAdditionsTests : XCTestCase @@ -10,7 +10,7 @@ @implementation MGLNSOrthographyAdditionsTests - (void)testStreetsLanguages { - for (NSString *language in [MGLVectorSource mapboxStreetsLanguages]) { + for (NSString *language in [MGLVectorTileSource mapboxStreetsLanguages]) { NSString *dominantScript = [NSOrthography mgl_dominantScriptForMapboxStreetsLanguage:language]; XCTAssertNotEqualObjects(dominantScript, @"Zyyy", @"Mapbox Streets languages should have dominant script"); } |