diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2019-07-11 16:06:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-11 16:06:54 -0700 |
commit | 5b488225fb720ef607c13a33ff6509d92bb7de95 (patch) | |
tree | 6b3f61c1d27110fb3f4bd2ea51e4be5697443c22 /platform/ios/test | |
parent | de71ff5102987d66ce7578216b32ae13ecf9622f (diff) | |
download | qtlocation-mapboxgl-5b488225fb720ef607c13a33ff6509d92bb7de95.tar.gz |
[ios] Add MGLCompassButton and MGLOrnamentVisibility
Diffstat (limited to 'platform/ios/test')
-rw-r--r-- | platform/ios/test/MGLCompassButtonTests.m | 84 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewDirectionTests.mm | 33 |
2 files changed, 117 insertions, 0 deletions
diff --git a/platform/ios/test/MGLCompassButtonTests.m b/platform/ios/test/MGLCompassButtonTests.m new file mode 100644 index 0000000000..f41de0a2e2 --- /dev/null +++ b/platform/ios/test/MGLCompassButtonTests.m @@ -0,0 +1,84 @@ +#import <Mapbox/Mapbox.h> +#import <XCTest/XCTest.h> + +#import "../../ios/src/MGLCompassButton_Private.h" + +@interface MGLMapView (MGLCompassButtonTests) + +- (void)resetNorthAnimated:(BOOL)animated; + +@end + +@interface MGLCompassButtonTests : XCTestCase + +@property (nonatomic) MGLMapView *mapView; + +@end + +@implementation MGLCompassButtonTests + +- (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; + [MGLAccountManager setAccessToken:nil]; + + [super tearDown]; +} + +- (void)testCompassButton { + XCTAssertNotNil(self.mapView.compassView); + XCTAssertTrue(self.mapView.compassView.userInteractionEnabled); + XCTAssertEqual(self.mapView.compassView.gestureRecognizers.count, 1); + XCTAssertEqual(self.mapView.compassView.accessibilityTraits, UIAccessibilityTraitButton); + XCTAssertNotNil(self.mapView.compassView.accessibilityLabel); + XCTAssertNotNil(self.mapView.compassView.accessibilityHint); +} + +- (void)testVisibilityAdaptive { + XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityAdaptive, @"Adaptive should be the default visibility setting."); + XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should not initially be visible."); + + self.mapView.zoomLevel = 15.f; + [self.mapView setDirection:45.f animated:false]; + XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); + XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should become visible when direction changes."); + + [self.mapView resetNorthAnimated:NO]; + XCTAssertEqual(self.mapView.direction, 0); + XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should hide itself when direction is north."); +} + +- (void)testVisibilityHidden { + self.mapView.compassView.compassVisibility = MGLOrnamentVisibilityHidden; + XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityHidden); + XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should not initially be visible."); + + self.mapView.zoomLevel = 15.f; + [self.mapView setDirection:45.f animated:false]; + XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); + XCTAssertEqual(self.mapView.compassView.alpha, 0, @"Compass should stay hidden when direction changes."); +} + +- (void)testVisibilityVisible { + self.mapView.compassView.compassVisibility = MGLOrnamentVisibilityVisible; + XCTAssertEqual(self.mapView.compassView.compassVisibility, MGLOrnamentVisibilityVisible); + XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should initially be visible."); + + self.mapView.zoomLevel = 15.f; + [self.mapView setDirection:45.f animated:false]; + XCTAssertEqualWithAccuracy(self.mapView.direction, 45, 0.001); + XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should continue to be visible when direction changes."); + + [self.mapView resetNorthAnimated:NO]; + XCTAssertEqual(self.mapView.direction, 0); + XCTAssertEqual(self.mapView.compassView.alpha, 1, @"Compass should continue to be visible when direction is north."); +} + +@end diff --git a/platform/ios/test/MGLMapViewDirectionTests.mm b/platform/ios/test/MGLMapViewDirectionTests.mm index 7f7e0903e3..d3990b581b 100644 --- a/platform/ios/test/MGLMapViewDirectionTests.mm +++ b/platform/ios/test/MGLMapViewDirectionTests.mm @@ -51,6 +51,39 @@ static MGLMapView *mapView; XCTAssertEqual(mapView.direction, 0, @"Reset-to-north should set direction to 0°."); } +- (void)testRotateEnabled { + mapView.zoomLevel = 10; + + UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] initWithTarget:nil action:nil]; + gesture.state = UIGestureRecognizerStateBegan; + gesture.rotation = MGLRadiansFromDegrees(30); + CGFloat wrappedRotation = mbgl::util::wrap(-MGLDegreesFromRadians(gesture.rotation), 0., 360.); + + // Disabled + { + mapView.rotateEnabled = NO; + XCTAssertEqual(mapView.allowsRotating, NO); + + [mapView handleRotateGesture:gesture]; + XCTAssertNotEqual(mapView.direction, wrappedRotation, @"Gestural rotation should not work when rotation is disabled."); + + mapView.direction = 45.f; + XCTAssertEqualWithAccuracy(mapView.direction, 45, 0.001, @"Programmatic rotation is allowed when rotateEnabled = NO."); + } + + // Enabled + { + [mapView resetNorthAnimated:NO]; + mapView.rotateEnabled = YES; + XCTAssertEqual(mapView.allowsRotating, YES); + + gesture.state = UIGestureRecognizerStateChanged; + gesture.rotation = MGLRadiansFromDegrees(30); + [mapView handleRotateGesture:gesture]; + XCTAssertEqualWithAccuracy(mapView.direction, wrappedRotation, 0.001, @"Gestural rotation should work when rotation is enabled."); + } +} + - (void)testRotateGesture { mapView.zoomLevel = 15; |