From a642f52d519543d9ece4bb525e99ebc281fa6887 Mon Sep 17 00:00:00 2001 From: Leon Jiang Date: Wed, 24 Jun 2020 00:23:26 -0700 Subject: initial commit, add react-native/typescript boilerplate --- ios/FrontendTests/FrontendTests.m | 65 +++++++++++++++++++++++++++++++++++++++ ios/FrontendTests/Info.plist | 24 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 ios/FrontendTests/FrontendTests.m create mode 100644 ios/FrontendTests/Info.plist (limited to 'ios/FrontendTests') diff --git a/ios/FrontendTests/FrontendTests.m b/ios/FrontendTests/FrontendTests.m new file mode 100644 index 00000000..af1c8342 --- /dev/null +++ b/ios/FrontendTests/FrontendTests.m @@ -0,0 +1,65 @@ +#import +#import + +#import +#import + +#define TIMEOUT_SECONDS 600 +#define TEXT_TO_LOOK_FOR @"Welcome to React" + +@interface FrontendTests : XCTestCase + +@end + +@implementation FrontendTests + +- (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 +{ + UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; + NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; + BOOL foundElement = NO; + + __block NSString *redboxError = nil; +#ifdef DEBUG + RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { + if (level >= RCTLogLevelError) { + redboxError = message; + } + }); +#endif + + 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; + }]; + } + +#ifdef DEBUG + RCTSetLogFunction(RCTDefaultLogFunction); +#endif + + XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); + XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); +} + + +@end diff --git a/ios/FrontendTests/Info.plist b/ios/FrontendTests/Info.plist new file mode 100644 index 00000000..ba72822e --- /dev/null +++ b/ios/FrontendTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + -- cgit v1.2.3-70-g09d2