|
11 | 11 | #import <React/RCTLog.h>
|
12 | 12 | #import <React/RCTRootView.h>
|
13 | 13 |
|
14 |
| -#define TIMEOUT_SECONDS 600 |
15 |
| -#define TEXT_TO_LOOK_FOR @"Welcome to React Native!" |
16 |
| - |
17 | 14 | @interface ecommerceTests : XCTestCase
|
18 | 15 |
|
19 | 16 | @end
|
20 | 17 |
|
21 | 18 | @implementation ecommerceTests
|
22 | 19 |
|
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 | 20 | @end
|
0 commit comments