Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Speed up UI tests
Browse files Browse the repository at this point in the history
During UI tests, disable UI tests and skip state restoration so we don’t have to reset the position for each test.
  • Loading branch information
1ec5 committed Apr 27, 2016
1 parent dadb197 commit 25e03dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
5 changes: 5 additions & 0 deletions platform/ios/app/MBXAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
[MGLAccountManager setAccessToken:accessToken];
}

// Speed things up if we’re being run by a UI test bundle.
if ([[[NSProcessInfo processInfo] environment][@"MAPBOX_DISABLE_ANIMATIONS"] boolValue]) {
[UIView setAnimationsEnabled:NO];
}

return YES;
}
Expand Down
4 changes: 4 additions & 0 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ - (void)saveState:(__unused NSNotification *)notification

- (void)restoreState:(__unused NSNotification *)notification
{
if ([[[NSProcessInfo processInfo] environment][@"MAPBOX_CLEAN_START"] boolValue]) {
return;
}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"];
MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil;
Expand Down
25 changes: 3 additions & 22 deletions platform/ios/uitest/MGLUITestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,20 @@

@implementation MGLUITestCase

- (instancetype)init {
if (self = [super init]) {
}
return self;
}

- (void)setUp {
[super setUp];

self.continueAfterFailure = NO;
[XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait;

// Launch the application, bypassing the access token prompt.
_app = [[XCUIApplication alloc] init];
NSMutableDictionary <NSString *, NSString *> *environment = _app.launchEnvironment.mutableCopy;
environment[@"MAPBOX_ACCESS_TOKEN"] = MGLUITestsBogusAccessToken;
environment[@"MAPBOX_DISABLE_ANIMATIONS"] = @"1";
environment[@"MAPBOX_CLEAN_START"] = @"1";
_app.launchEnvironment = environment;
[_app launch];

// Reset the viewport.
XCUIElement *settingsElement = _app.navigationBars[@"MBXNavigationBar"].buttons[@"MBXSettingsButton"];
XCUIElementQuery *collectionViewsQuery = _app.sheets[@"Map Settings"].collectionViews;
[settingsElement tap];
[collectionViewsQuery.buttons[@"Reset Position"] tap];

// Remove all annotations.
[settingsElement tap];
[_app.sheets[@"Map Settings"] swipeUp];
[collectionViewsQuery.buttons[@"Remove Annotations"] tap];

}

- (BOOL)continueAfterFailure {
return NO;
}

@end

0 comments on commit 25e03dd

Please sign in to comment.