master
 1/**
 2 * Copyright (c) 2015-present, Facebook, Inc.
 3 * All rights reserved.
 4 *
 5 * This source code is licensed under the BSD-style license found in the
 6 * LICENSE file in the root directory of this source tree. An additional grant
 7 * of patent rights can be found in the PATENTS file in the same directory.
 8 */
 9
10#import <UIKit/UIKit.h>
11#import <XCTest/XCTest.h>
12
13#import <React/RCTLog.h>
14#import <React/RCTRootView.h>
15
16#define TIMEOUT_SECONDS 600
17#define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
18
19@interface strongliftersTests : XCTestCase
20
21@end
22
23@implementation strongliftersTests
24
25- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
26{
27  if (test(view)) {
28    return YES;
29  }
30  for (UIView *subview in [view subviews]) {
31    if ([self findSubviewInView:subview matching:test]) {
32      return YES;
33    }
34  }
35  return NO;
36}
37
38- (void)testRendersWelcomeScreen
39{
40  UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
41  NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
42  BOOL foundElement = NO;
43
44  __block NSString *redboxError = nil;
45  RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
46    if (level >= RCTLogLevelError) {
47      redboxError = message;
48    }
49  });
50
51  while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
52    [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
53    [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
54
55    foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
56      if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
57        return YES;
58      }
59      return NO;
60    }];
61  }
62
63  RCTSetLogFunction(RCTDefaultLogFunction);
64
65  XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
66  XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
67}
68
69
70@end