summaryrefslogtreecommitdiff
path: root/platform/macos/test/MGLAnnotationTests.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/macos/test/MGLAnnotationTests.m
parent7d1e52a3255d4eecdcd37e4fb600eb76fa9333f8 (diff)
parent146057adf90e85e3edc80446f02d20e5f6cab378 (diff)
downloadqtlocation-mapboxgl-30376f3ce1d17522d9e64901b1bbc52906ee5267.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/macos/test/MGLAnnotationTests.m')
-rw-r--r--platform/macos/test/MGLAnnotationTests.m52
1 files changed, 52 insertions, 0 deletions
diff --git a/platform/macos/test/MGLAnnotationTests.m b/platform/macos/test/MGLAnnotationTests.m
new file mode 100644
index 0000000000..36a7aef9f0
--- /dev/null
+++ b/platform/macos/test/MGLAnnotationTests.m
@@ -0,0 +1,52 @@
+#import <Mapbox/Mapbox.h>
+#import <XCTest/XCTest.h>
+
+@interface MGLAnnotationTests : XCTestCase <MGLMapViewDelegate>
+@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) BOOL centerCoordinateDidChange;
+@end
+
+@implementation MGLAnnotationTests
+
+- (void)setUp
+{
+ [super setUp];
+ _mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
+ _mapView.delegate = self;
+}
+
+- (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
+ // NSZeroRect
+
+ self.mapView.contentInsets = NSEdgeInsetsMake(10.0, 10.0, 10.0, 10.0);
+
+ // 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");
+
+ [self.mapView addObserver:self forKeyPath:@"centerCoordinate" options:NSKeyValueObservingOptionNew context:_cmd];
+ XCTAssertFalse(self.centerCoordinateDidChange, @"Center coordinate should not have changed at this point");
+
+ // Select on screen annotation (DO NOT ADD FIRST).
+ [self.mapView selectAnnotation:point];
+
+ XCTAssertFalse(self.centerCoordinateDidChange, @"Center coordinate should not have changed after selecting a visible annotation");
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
+ if ((context == @selector(testSelectingOnscreenAnnotationThatHasNotBeenAdded)) &&
+ (object == self.mapView)) {
+ self.centerCoordinateDidChange = YES;
+ }
+}
+
+@end