diff options
Diffstat (limited to 'platform/ios/test/MGLMapViewScaleBarTests.m')
-rw-r--r-- | platform/ios/test/MGLMapViewScaleBarTests.m | 62 |
1 files changed, 62 insertions, 0 deletions
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 |