summaryrefslogtreecommitdiff
path: root/platform/ios/test
diff options
context:
space:
mode:
authorJason Wray <friedbunny@users.noreply.github.com>2018-03-02 13:13:57 -0500
committerGitHub <noreply@github.com>2018-03-02 13:13:57 -0500
commit4919099ea9c7e5d2a0ed261b169c7c6a0e86a43f (patch)
tree3cc8f47f1caf4d0c4cefa561bf35dd2a83f9bd10 /platform/ios/test
parent4408e2f0bc00019bd6da07514a1117a129cca96f (diff)
downloadqtlocation-mapboxgl-4919099ea9c7e5d2a0ed261b169c7c6a0e86a43f.tar.gz
[ios] Add MGLMapView.showsScale to control scale bar visibility (#11335)
- Fixes scale bar not being visible until a camera change event. - Adds IBInspectable for scale bar visibility. - Add tests of the scale bar being added to the map view
Diffstat (limited to 'platform/ios/test')
-rw-r--r--platform/ios/test/MGLMapViewLayoutTests.m5
-rw-r--r--platform/ios/test/MGLMapViewScaleBarTests.m62
2 files changed, 65 insertions, 2 deletions
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