diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2018-01-10 14:28:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-10 14:28:55 -0600 |
commit | 0542ece0bf2456db3ca7f0140bb6ac43c4697a97 (patch) | |
tree | cbc281b9d139ada533bae743612359209b524097 /platform/ios/test/MGLMapViewLayoutTests.m | |
parent | a3c497f100b488802aba7c04b2096e0617271cdf (diff) | |
download | qtlocation-mapboxgl-0542ece0bf2456db3ca7f0140bb6ac43c4697a97.tar.gz |
[ios] Fix the layout constraints on iOS 11 for iPhone X (#10858)
* [ios] Fix the layout constraints on iOS 11 for iPhone X for the bottom ornaments.
* WIP adding tests for layout of map view attribution logo and other ornaments
* Rename
* First pass at tests for mapview ornament layout
* Additional code changes from call with Fabian and Jason
* [ios] Fix ornaments insets margin space.
* [ios] Fix map view layout test for pre iOS 11.
* [ios] Refactor MGLMapView ornaments layout constraints for iOS 11.
* [ios] Remove NSLogs from MGLMapViewLayoutTests
Diffstat (limited to 'platform/ios/test/MGLMapViewLayoutTests.m')
-rw-r--r-- | platform/ios/test/MGLMapViewLayoutTests.m | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m new file mode 100644 index 0000000000..a41e7695f9 --- /dev/null +++ b/platform/ios/test/MGLMapViewLayoutTests.m @@ -0,0 +1,108 @@ +#import <XCTest/XCTest.h> +#import "MGLMapView.h" +#import "MGLMapViewDelegate.h" +#import "MGLAccountManager.h" + + +@interface MGLMapViewLayoutTests : XCTestCase<MGLMapViewDelegate> + +@property (nonatomic) UIView *superView; +@property (nonatomic) MGLMapView *mapView; +@property (nonatomic) XCTestExpectation *styleLoadingExpectation; + +@end + +@implementation MGLMapViewLayoutTests + +- (void)setUp { + [super setUp]; + + [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + + self.superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + + self.mapView = [[MGLMapView alloc] initWithFrame:UIScreen.mainScreen.bounds styleURL:styleURL]; + self.mapView.delegate = self; + + [self.superView addSubview:self.mapView]; + + UIView *mapView = self.mapView; + NSDictionary *bindings = NSDictionaryOfVariableBindings(mapView); + NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings]; + NSArray *horizonatalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[mapView]-0-|" options:0 metrics:nil views:bindings]; + + [self.superView addConstraints:[verticalConstraints arrayByAddingObjectsFromArray:horizonatalConstraints]]; + + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + + //set zoom and heading so that scale bar and compass will be shown + [self.mapView setZoomLevel:4.5 animated:NO]; + [self.mapView.camera setHeading:12.0]; + + //invoke layout + [self.superView setNeedsLayout]; + [self.superView layoutIfNeeded]; + +} + +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + XCTAssertNotNil(mapView.style); + XCTAssertEqual(mapView.style, style); + + [self.styleLoadingExpectation fulfill]; +} + +- (void)tearDown { + self.styleLoadingExpectation = nil; + self.mapView = nil; + + [super tearDown]; +} + +- (void)testOrnamentPlacement { + + CGFloat margin = 8.0; + CGFloat bottomSafeAreaInset = 0.0; + double accuracy = 0.01; + + if ( [self.mapView respondsToSelector:@selector(safeAreaInsets)] ) { + bottomSafeAreaInset = self.mapView.safeAreaInsets.bottom; + } + + //compass + UIImageView *compassView = self.mapView.compassView; + + CGFloat expectedCompassOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(compassView.frame); + CGFloat expectedCompassOriginY = margin; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(compassView.frame), expectedCompassOriginX, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(compassView.frame), expectedCompassOriginY, accuracy); + + //scale bar + UIView *scaleBar = self.mapView.scaleBar; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), margin, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), margin, accuracy); + + //attribution button + UIButton *attributionButton = self.mapView.attributionButton; + + CGFloat expectedButtonOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(attributionButton.frame); + CGFloat expectedButtonOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(attributionButton.frame); + + XCTAssertEqualWithAccuracy(CGRectGetMinX(attributionButton.frame), expectedButtonOriginX, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(attributionButton.frame), expectedButtonOriginY, accuracy); + + //mapbox logo + UIImageView *logoView = self.mapView.logoView; + + CGFloat expectedLogoOriginX = margin; + CGFloat expectedLogoOriginY = CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(logoView.frame); + + XCTAssertEqualWithAccuracy(CGRectGetMinX(logoView.frame), expectedLogoOriginX, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), expectedLogoOriginY, accuracy); +} + +@end |