Skip to content

Commit

Permalink
[cli] Fix iOS app template
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Konicek committed Aug 25, 2015
1 parent 480b5c9 commit 19f922a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions local-cli/generator-ios/templates/app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"<%= name %>"
initialProperties:nil
launchOptions:launchOptions];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand Down
19 changes: 12 additions & 7 deletions local-cli/generator-ios/templates/tests/Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "RCTAssert.h"
#import "RCTRedBox.h"
#import "RCTLog.h"
#import "RCTRootView.h"

#define TIMEOUT_SECONDS 240
Expand All @@ -23,7 +22,6 @@ @interface <%= name %>Tests : XCTestCase

@implementation <%= name %>Tests


- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
{
if (test(view)) {
Expand All @@ -37,18 +35,23 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
return NO;
}

- (void)testRendersWelcomeScreen {
- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
NSString *redboxError = nil;

__block NSString *redboxError = nil;
RCTSetLogFunction(^(RCTLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});

while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];

redboxError = [[RCTRedBox sharedInstance] currentErrorMessage];

foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
Expand All @@ -57,6 +60,8 @@ - (void)testRendersWelcomeScreen {
}];
}

RCTSetLogFunction(RCTDefaultLogFunction);

XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}
Expand Down

0 comments on commit 19f922a

Please sign in to comment.