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