Skip to content

Commit

Permalink
restore FBSnapshot helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
bg-stripe committed Dec 15, 2017
1 parent 30b9fba commit da29424
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Tests/Tests/FBSnapshotTestCase+STPViewControllerLoading.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

@interface FBSnapshotTestCase (STPViewControllerLoading)

/**
Embeds the given controller in a navigation controller, prepares it for
snapshot testing and returns the view controller's view.
*/
- (UIView *)stp_preparedAndSizedViewForSnapshotTestFromViewController:(UIViewController *viewController)viewController;

/**
Returns a navigation controller initialized with the given root view controller
and prepares it for snapshot testing (adding it to a UIWindow and loading views)
Expand Down
5 changes: 5 additions & 0 deletions Tests/Tests/FBSnapshotTestCase+STPViewControllerLoading.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

@implementation FBSnapshotTestCase (STPViewControllerLoading)

- (UIView *)stp_preparedAndSizedViewForSnapshotTestFromViewController:(UIViewController *)viewController {
UINavigationController *navController = [self stp_navigationControllerForSnapshotTestWithRootVC:viewController];
return [self stp_preparedAndSizedViewForSnapshotTestFromNavigationController:navController];
}

- (UINavigationController *)stp_navigationControllerForSnapshotTestWithRootVC:(UIViewController *)viewController {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
UIWindow *testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
Expand Down
3 changes: 1 addition & 2 deletions Tests/Tests/STPAddCardViewControllerLocalizationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ - (void)performSnapshotTestForLanguage:(NSString *)language delivery:(BOOL)deliv
addCardVC.shippingAddress = [STPAddress new];
addCardVC.shippingAddress.line1 = @"1"; // trigger "use shipping address" button

UINavigationController *navController = [self stp_navigationControllerForSnapshotTestWithRootVC:addCardVC];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromNavigationController:navController];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromViewController:addCardVC];

if (delivery) {
addCardVC.addressViewModel.addressFieldTableViewCountryCode = @"INVALID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ - (void)performSnapshotTestForLanguage:(NSString *)language {
delegate:delegate];


UINavigationController *navController = [self stp_navigationControllerForSnapshotTestWithRootVC:paymentMethodsVC];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromNavigationController:navController];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromViewController:paymentMethodsVC];

FBSnapshotVerifyView(viewToTest, nil);
[STPLocalizationUtils overrideLanguageTo:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ - (void)performSnapshotTestForLanguage:(NSString *)language shippingType:(STPShi
*/
shippingVC.addressViewModel.addressFieldTableViewCountryCode = @"INVALID";

UINavigationController *navController = [self stp_navigationControllerForSnapshotTestWithRootVC:shippingVC];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromNavigationController:navController];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromViewController:shippingVC];

FBSnapshotVerifyView(viewToTest, identifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ - (void)performSnapshotTestForLanguage:(NSString *)language {
method2.identifier = @"fedex";

STPShippingMethodsViewController *shippingVC = [[STPShippingMethodsViewController alloc] initWithShippingMethods:@[method1, method2] selectedShippingMethod:method1 currency:@"usd" theme:[STPTheme defaultTheme]];
UINavigationController *navController = [self stp_navigationControllerForSnapshotTestWithRootVC:shippingVC];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromNavigationController:navController];
UIView *viewToTest = [self stp_preparedAndSizedViewForSnapshotTestFromViewController:shippingVC];
FBSnapshotVerifyView(viewToTest, nil);
[STPLocalizationUtils overrideLanguageTo:nil];
}
Expand Down

0 comments on commit da29424

Please sign in to comment.