Test inset MGLMapView

Verify that the ornaments hug the `MGLMapView` when it’s smaller than the view controller’s root view.
This commit is contained in:
Minh Nguyễn
2015-04-24 13:30:50 -07:00
parent 2c436444d7
commit 1dc2cbc280
5 changed files with 41 additions and 8 deletions

View File

@@ -1,12 +1,12 @@
#import <UIKit/UIKit.h>
#import <KIF/KIF.h>
@class MGLMapView;
@class MGLTViewController, MGLMapView;
@interface KIFTestActor (MapboxGL)
@property (nonatomic, readonly) UIWindow *window;
@property (nonatomic, readonly) UIViewController *viewController;
@property (nonatomic, readonly) MGLTViewController *viewController;
@property (nonatomic, readonly) MGLMapView *mapView;
@property (nonatomic, readonly) UIView *compass;

View File

@@ -10,8 +10,8 @@
return [[UIApplication sharedApplication] statusBarWindow];
}
- (UIViewController *)viewController {
return (UIViewController *)[[tester.mapView nextResponder] nextResponder];
- (MGLTViewController *)viewController {
return (MGLTViewController *)[[tester.mapView nextResponder] nextResponder];
}
- (MGLMapView *)mapView {

View File

@@ -2,4 +2,6 @@
@interface MGLTViewController : UIViewController
- (void)insetMapView;
@end

View File

@@ -2,17 +2,25 @@
#import "MapboxGL.h"
@implementation MGLTViewController
{
MGLMapView *_mapView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds
_mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds
accessToken:@"pk.eyJ1IjoianVzdGluIiwiYSI6Ik9RX3RRQzAifQ.dmOg_BAp1ywuDZMM7YsXRg"];
mapView.viewControllerForLayoutGuides = self;
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_mapView.viewControllerForLayoutGuides = self;
_mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:mapView];
[self.view addSubview:_mapView];
}
- (void)insetMapView
{
_mapView.frame = CGRectInset(_mapView.frame, 50, 50);
}
@end

View File

@@ -4,6 +4,7 @@
#import "KIFTestActor+MapboxGL.h"
#import "MapboxGL.h"
#import "MGLTViewController.h"
@interface MapViewTests : KIFTestCase <MGLMapViewDelegate>
@@ -297,6 +298,28 @@
@"rotated device should not have attribution button under toolbar");
}
- (void)testInsetMapView {
[tester.viewController insetMapView];
[tester waitForAnimationsToFinish];
UIView *logoBug = (UIView *)[tester waitForViewWithAccessibilityLabel:@"Mapbox logo"];
UIView *attributionButton = (UIView *)[tester waitForViewWithAccessibilityLabel:@"Attribution info"];
CGRect mapViewFrame = [tester.mapView.superview convertRect:tester.mapView.frame toView:nil];
CGRect logoBugFrame = [logoBug.superview convertRect:logoBug.frame toView:nil];
XCTAssertTrue(CGRectIntersectsRect(logoBugFrame, mapViewFrame),
@"logo bug should lie inside shrunken map view");
CGRect attributionButtonFrame = [attributionButton.superview convertRect:attributionButton.frame toView:nil];
XCTAssertTrue(CGRectIntersectsRect(attributionButtonFrame, mapViewFrame),
@"attribution button should lie inside shrunken map view");
CGRect compassFrame = [tester.compass.superview convertRect:tester.compass.frame toView:nil];
XCTAssertTrue(CGRectIntersectsRect(compassFrame, mapViewFrame),
@"compass should lie inside shrunken map view");
}
- (void)testDelegateRegionWillChange {
__block NSUInteger unanimatedCount;
__block NSUInteger animatedCount;