diff options
Diffstat (limited to 'platform/ios/Integration Tests/MGLMapViewIntegrationTest.m')
-rw-r--r-- | platform/ios/Integration Tests/MGLMapViewIntegrationTest.m | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m new file mode 100644 index 0000000000..fc3229c83b --- /dev/null +++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m @@ -0,0 +1,79 @@ +#import "MGLMapViewIntegrationTest.h" + +@implementation MGLMapViewIntegrationTest + +- (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]; + self.mapView.delegate = self; + + UIView *superView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + [superView addSubview:self.mapView]; + UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; + [window addSubview:superView]; + [window makeKeyAndVisible]; + + if (!self.mapView.style) { + [self waitForMapViewToFinishLoadingStyleWithTimeout:1]; + } +} + +- (void)tearDown { + self.styleLoadingExpectation = nil; + self.renderFinishedExpectation = nil; + self.mapView = nil; + self.style = nil; + + [super tearDown]; +} + +#pragma mark - MGLMapViewDelegate + +- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { + XCTAssertNotNil(mapView.style); + XCTAssertEqual(mapView.style, style); + + [self.styleLoadingExpectation fulfill]; +} + +- (void)mapViewDidFinishRenderingFrame:(MGLMapView *)mapView fullyRendered:(__unused BOOL)fullyRendered { + [self.renderFinishedExpectation fulfill]; + self.renderFinishedExpectation = nil; +} + +- (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated { + if (self.regionDidChange) { + self.regionDidChange(mapView, animated); + } +} + +- (void)mapViewRegionIsChanging:(MGLMapView *)mapView { + if (self.regionIsChanging) { + self.regionIsChanging(mapView); + } +} + +#pragma mark - Utilities + +- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout { + XCTAssertNil(self.styleLoadingExpectation); + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self waitForExpectations:@[self.styleLoadingExpectation] timeout:timeout]; +} + +- (void)waitForMapViewToBeRenderedWithTimeout:(NSTimeInterval)timeout { + XCTAssertNil(self.renderFinishedExpectation); + [self.mapView setNeedsDisplay]; + self.renderFinishedExpectation = [self expectationWithDescription:@"Map view should be rendered"]; + [self waitForExpectations:@[self.renderFinishedExpectation] timeout:timeout]; +} + +- (MGLStyle *)style { + return self.mapView.style; +} + +@end |