2015-10-05 20:41:32 +00:00
|
|
|
/**
|
2019-03-26 18:52:44 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-10-05 20:41:32 +00:00
|
|
|
*
|
2019-03-26 18:52:44 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-10-05 20:41:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
2017-04-10 15:53:33 +00:00
|
|
|
#import <React/RCTLog.h>
|
|
|
|
#import <React/RCTRootView.h>
|
2015-10-05 20:41:32 +00:00
|
|
|
|
2016-06-13 20:40:35 +00:00
|
|
|
#define TIMEOUT_SECONDS 600
|
2015-10-05 20:41:32 +00:00
|
|
|
#define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
|
|
|
|
|
2019-03-26 18:52:44 +00:00
|
|
|
@interface exampleTests : XCTestCase
|
2015-10-05 20:41:32 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2019-03-26 18:52:44 +00:00
|
|
|
@implementation exampleTests
|
2015-10-05 20:41:32 +00:00
|
|
|
|
|
|
|
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
|
|
|
|
{
|
|
|
|
if (test(view)) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
for (UIView *subview in [view subviews]) {
|
|
|
|
if ([self findSubviewInView:subview matching:test]) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testRendersWelcomeScreen
|
|
|
|
{
|
2019-03-26 18:52:44 +00:00
|
|
|
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
|
2015-10-05 20:41:32 +00:00
|
|
|
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
|
|
|
|
BOOL foundElement = NO;
|
|
|
|
|
|
|
|
__block NSString *redboxError = nil;
|
2016-04-11 04:13:01 +00:00
|
|
|
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
|
2015-10-05 20:41:32 +00:00
|
|
|
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]];
|
|
|
|
|
|
|
|
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
|
|
|
|
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTSetLogFunction(RCTDefaultLogFunction);
|
|
|
|
|
|
|
|
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
|
|
|
|
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|