Files
MapLibreParticleLab/platform/ios/test/MGLMapViewScaleBarTests.m
Julian Rex cab756374f [ios] Fix layout of Scale bar components (#15703)
* [ios] Add failing tests for scale bar updates.

* [ios] Remove borderLayer

* [ios] Ensure bar sections have non-fractional width

* [ios] Add RTL override

* [ios] Update constraints/layout

* [ios] Invalidate scalebars size, after the parent's layout has happened (to ensure the view dimensions are correct when re-laying out the scale bar.

* [ios] Refactor layout

* [ios] Update changelog / remove commented code.

* [ios] Remove whitespace

* [ios] Stop integration tests asserting (when scale bar is hidden). Also reduces the # of calculations (since updateConstraints and layoutSubviews can be called outside of our control).

* [ios] Moves declaration of properties for testing.

* [ios] Removes redundant property attribute

* [ios] Updated change log
2019-10-04 11:15:20 -04:00

71 lines
2.1 KiB
Objective-C

#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;
[MGLAccountManager setAccessToken: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.
// Size is not a measure of readiness here though.
XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero));
XCTAssertEqual(scaleBar.alpha, 0);
self.mapView.zoomLevel = 15;
[self.mapView layoutIfNeeded];
XCTAssertGreaterThan(scaleBar.alpha, 0);
XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero));
}
- (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(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero));
// ... but triggering any camera event will update it.
self.mapView.zoomLevel = 1;
[self.mapView layoutIfNeeded];
XCTAssertTrue(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero));
XCTAssertEqual(scaleBar.alpha, 0);
self.mapView.zoomLevel = 15;
[self.mapView layoutIfNeeded];
XCTAssertGreaterThan(scaleBar.alpha, 0);
XCTAssertFalse(CGSizeEqualToSize(scaleBar.intrinsicContentSize, CGSizeZero));
}@end