diff options
author | Lloyd Sheng <i@lloydsheng.com> | 2019-03-11 23:06:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 23:06:16 +0800 |
commit | 60ceac5efc3d77199f773f08400fe1d53d5a1b90 (patch) | |
tree | 782c821978c8d4b7da2aff2aef9ab24b3c70e88e /platform/ios/test | |
parent | 5ccc5b7c360827fe58698c28cae4df399310e4d1 (diff) | |
download | qtlocation-mapboxgl-60ceac5efc3d77199f773f08400fe1d53d5a1b90.tar.gz |
[iOS] Enable developers to change position of ornaments (#13911)
* APIs for change position of ornaments
* Use anchors APIs and emove iOS8 layout code
* Add ornaments layout tests
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/MGLMapViewLayoutTests.m | 124 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewScaleBarTests.m | 6 |
2 files changed, 127 insertions, 3 deletions
diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m index 48e9bedc4f..5d9c0339b5 100644 --- a/platform/ios/test/MGLMapViewLayoutTests.m +++ b/platform/ios/test/MGLMapViewLayoutTests.m @@ -4,6 +4,27 @@ #import "MGLAccountManager.h" +@interface MGLOrnamentTestData : NSObject + +@property (nonatomic) MGLOrnamentPosition position; +@property (nonatomic) CGPoint offset; +@property (nonatomic) CGPoint expectedOrigin; + +@end + +@implementation MGLOrnamentTestData + ++ (instancetype)createWithPosition:(MGLOrnamentPosition)position offset:(CGPoint)offset expectedOrigin:(CGPoint)expectedOrigin { + MGLOrnamentTestData *data = [[MGLOrnamentTestData alloc] init]; + data.position = position; + data.offset = offset; + data.expectedOrigin = expectedOrigin; + return data; +} + +@end + + @interface MGLMapViewLayoutTests : XCTestCase<MGLMapViewDelegate> @property (nonatomic) UIView *superView; @@ -107,4 +128,107 @@ XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), expectedLogoOriginY, accuracy); } +- (NSArray *)makeTestDataListWithView:(UIView *)view margin:(CGFloat)margin { + CGFloat bottomSafeAreaInset = 0.0; + if (@available(iOS 11.0, *)) { + bottomSafeAreaInset = self.mapView.safeAreaInsets.bottom; + } + + return @[ + [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopLeft + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(margin, margin)], + [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopRight + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), 4)], + [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomLeft + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(margin, CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))], + [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomRight + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), + CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))] + ]; +} + +- (void)testCompassPlacement { + double accuracy = 0.01; + CGFloat margin = 4.0; + + UIView *compassView = self.mapView.compassView; + NSArray *testDataList = [self makeTestDataListWithView:compassView margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.compassViewPosition = testData.position; + self.mapView.compassViewMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + [self.superView layoutIfNeeded]; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(compassView.frame), testData.expectedOrigin.x, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(compassView.frame), testData.expectedOrigin.y, accuracy); + } +} + +- (void)testScalebarPlacement { + double accuracy = 0.01; + CGFloat margin = 4.0; + + UIView *scaleBar = self.mapView.scaleBar; + NSArray *testDataList = [self makeTestDataListWithView:scaleBar margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.scaleBarPosition = testData.position; + self.mapView.scaleBarMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + [self.superView layoutIfNeeded]; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(scaleBar.frame), testData.expectedOrigin.x, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(scaleBar.frame), testData.expectedOrigin.y, accuracy); + } +} + +- (void)testAttributionButtonPlacement { + double accuracy = 0.01; + CGFloat margin = 4.0; + + UIView *attributionButton = self.mapView.attributionButton; + NSArray *testDataList = [self makeTestDataListWithView:attributionButton margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.attributionButtonPosition = testData.position; + self.mapView.attributionButtonMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + [self.superView layoutIfNeeded]; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(attributionButton.frame), testData.expectedOrigin.x, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(attributionButton.frame), testData.expectedOrigin.y, accuracy); + } +} + +- (void)testLogoPlacement { + double accuracy = 0.01; + CGFloat margin = 4.0; + + UIView *logoView = self.mapView.logoView; + NSArray *testDataList = [self makeTestDataListWithView:logoView margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.logoViewPosition = testData.position; + self.mapView.logoViewMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + [self.superView layoutIfNeeded]; + + XCTAssertEqualWithAccuracy(CGRectGetMinX(logoView.frame), testData.expectedOrigin.x, accuracy); + XCTAssertEqualWithAccuracy(CGRectGetMinY(logoView.frame), testData.expectedOrigin.y, accuracy); + } +} + @end diff --git a/platform/ios/test/MGLMapViewScaleBarTests.m b/platform/ios/test/MGLMapViewScaleBarTests.m index 966d9c6c54..29acc75d7f 100644 --- a/platform/ios/test/MGLMapViewScaleBarTests.m +++ b/platform/ios/test/MGLMapViewScaleBarTests.m @@ -36,7 +36,7 @@ XCTAssertFalse(scaleBar.hidden); // Scale bar should not be visible at default zoom (~z0), but it should be ready. - XCTAssertFalse(CGRectIsEmpty(scaleBar.frame)); + XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); XCTAssertEqual(scaleBar.alpha, 0); self.mapView.zoomLevel = 15; @@ -50,11 +50,11 @@ XCTAssertFalse(scaleBar.hidden); // Directly setting `.hidden` after the map has finished initializing will not update the scale bar. - XCTAssertTrue(CGRectIsEmpty(scaleBar.frame)); + XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); // ... but triggering any camera event will update it. self.mapView.zoomLevel = 1; - XCTAssertFalse(CGRectIsEmpty(scaleBar.frame)); + XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero)); XCTAssertEqual(scaleBar.alpha, 0); self.mapView.zoomLevel = 15; |