summaryrefslogtreecommitdiff
path: root/platform/ios/test/MGLAnnotationViewTests.m
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-05-17 11:47:31 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-05-17 11:47:31 -0400
commit30376f3ce1d17522d9e64901b1bbc52906ee5267 (patch)
tree1f00d04a223a76a86e16ddebc77f56d2cff88b5b /platform/ios/test/MGLAnnotationViewTests.m
parent7d1e52a3255d4eecdcd37e4fb600eb76fa9333f8 (diff)
parent146057adf90e85e3edc80446f02d20e5f6cab378 (diff)
downloadqtlocation-mapboxgl-upstream/fabian-merge-release-4.0.1-master.tar.gz
Merge branch 'release-boba' into masterupstream/fabian-merge-release-4.0.1-master
# Conflicts: # mapbox-gl-js # platform/android/CHANGELOG.md # platform/android/MapboxGLAndroidSDK/gradle.properties # platform/android/gradle/dependencies.gradle # platform/darwin/src/MGLVectorTileSource.mm # platform/darwin/src/MGLVectorTileSource_Private.h # platform/ios/CHANGELOG.md # src/mbgl/style/expression/compound_expression.cpp
Diffstat (limited to 'platform/ios/test/MGLAnnotationViewTests.m')
-rw-r--r--platform/ios/test/MGLAnnotationViewTests.m89
1 files changed, 89 insertions, 0 deletions
diff --git a/platform/ios/test/MGLAnnotationViewTests.m b/platform/ios/test/MGLAnnotationViewTests.m
index 2f5963e66e..a2cc4227ed 100644
--- a/platform/ios/test/MGLAnnotationViewTests.m
+++ b/platform/ios/test/MGLAnnotationViewTests.m
@@ -3,6 +3,13 @@
static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer";
+
+@interface MGLMapView (Tests)
+@property (nonatomic) MGLCameraChangeReason cameraChangeReasonBitmask;
+@end
+
+
+
@interface MGLCustomAnnotationView : MGLAnnotationView
@end
@@ -58,6 +65,7 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu
@property (nonatomic) MGLMapView *mapView;
@property (nonatomic, weak) MGLAnnotationView *annotationView;
@property (nonatomic) NSInteger annotationSelectedCount;
+@property (nonatomic) void (^prepareAnnotationView)(MGLAnnotationView*);
@end
@implementation MGLAnnotationViewTests
@@ -152,6 +160,83 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu
XCTAssertEqual(selectionCount, self.annotationSelectedCount, @"-mapView:didSelectAnnotation: should be called for each selection");
}
+- (void)testSelectingOnscreenAnnotationThatHasNotBeenAdded {
+ // See https://github.com/mapbox/mapbox-gl-native/issues/11476
+
+ // This bug occurs under the following conditions:
+ //
+ // - There are content insets (e.g. navigation bar) for the compare against
+ // CGRectZero (now CGRectNull)
+ // - annotationView.enabled == NO - Currently this can happen if you use
+ // `-initWithFrame:` rather than one of the provided initializers
+ //
+
+ self.prepareAnnotationView = ^(MGLAnnotationView *view) {
+ view.enabled = NO;
+ };
+
+ self.mapView.contentInset = UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0);
+
+ MGLCameraChangeReason reasonBefore = self.mapView.cameraChangeReasonBitmask;
+ XCTAssert(reasonBefore == MGLCameraChangeReasonNone, @"Camera should not have moved at start of test");
+
+ // Create annotation
+ MGLPointFeature *point = [[MGLPointFeature alloc] init];
+ point.title = NSStringFromSelector(_cmd);
+ point.coordinate = CLLocationCoordinate2DMake(0.0, 0.0);
+
+ MGLCoordinateBounds coordinateBounds = [self.mapView convertRect:self.mapView.bounds toCoordinateBoundsFromView:self.mapView];
+ XCTAssert(MGLCoordinateInCoordinateBounds(point.coordinate, coordinateBounds), @"The test point should be within the visible map view");
+
+ // Select on screen annotation (DO NOT ADD FIRST).
+ [self.mapView selectAnnotation:point animated:YES];
+
+ // Expect - the camera NOT to move.
+ MGLCameraChangeReason reasonAfter = self.mapView.cameraChangeReasonBitmask;
+ XCTAssert(reasonAfter == MGLCameraChangeReasonNone, @"Camera should not have moved");
+}
+
+- (void)checkDefaultPropertiesForAnnotationView:(MGLAnnotationView*)view {
+ XCTAssertNil(view.annotation);
+ XCTAssertNil(view.reuseIdentifier);
+ XCTAssertEqual(view.centerOffset.dx, 0.0);
+ XCTAssertEqual(view.centerOffset.dy, 0.0);
+ XCTAssertFalse(view.scalesWithViewingDistance);
+ XCTAssertFalse(view.rotatesToMatchCamera);
+ XCTAssertFalse(view.isSelected);
+ XCTAssert(view.isEnabled);
+ XCTAssertFalse(view.isDraggable);
+ XCTAssertEqual(view.dragState, MGLAnnotationViewDragStateNone);
+}
+
+- (void)testAnnotationViewInitWithFrame {
+ CGRect frame = CGRectMake(10.0, 10.0, 100.0, 100.0);
+ MGLAnnotationView *view = [[MGLAnnotationView alloc] initWithFrame:frame];
+ [self checkDefaultPropertiesForAnnotationView:view];
+}
+
+- (void)testAnnotationViewInitWithReuseIdentifier {
+ MGLAnnotationView *view = [[MGLAnnotationView alloc] initWithReuseIdentifier:nil];
+ [self checkDefaultPropertiesForAnnotationView:view];
+}
+
+- (void)testSelectingADisabledAnnotationView {
+ self.prepareAnnotationView = ^(MGLAnnotationView *view) {
+ view.enabled = NO;
+ };
+
+ // Create annotation
+ MGLPointFeature *point = [[MGLPointFeature alloc] init];
+ point.title = NSStringFromSelector(_cmd);
+ point.coordinate = CLLocationCoordinate2DMake(0.0, 0.0);
+
+ XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations");
+
+ [self.mapView selectAnnotation:point animated:NO];
+
+ XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations");
+}
+
#pragma mark - MGLMapViewDelegate -
- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation
@@ -163,6 +248,10 @@ static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReu
annotationView = [[MGLAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MGLTestAnnotationReuseIdentifer];
}
+ if (self.prepareAnnotationView) {
+ self.prepareAnnotationView(annotationView);
+ }
+
_annotationView = annotationView;
return annotationView;