summaryrefslogtreecommitdiffstats
path: root/ios/cyberbadge_mobileTests
diff options
context:
space:
mode:
Diffstat (limited to 'ios/cyberbadge_mobileTests')
-rw-r--r--ios/cyberbadge_mobileTests/Info.plist24
-rw-r--r--ios/cyberbadge_mobileTests/cyberbadge_mobileTests.m66
2 files changed, 90 insertions, 0 deletions
diff --git a/ios/cyberbadge_mobileTests/Info.plist b/ios/cyberbadge_mobileTests/Info.plist
new file mode 100644
index 0000000..ba72822
--- /dev/null
+++ b/ios/cyberbadge_mobileTests/Info.plist
@@ -0,0 +1,24 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3<plist version="1.0">
4<dict>
5 <key>CFBundleDevelopmentRegion</key>
6 <string>en</string>
7 <key>CFBundleExecutable</key>
8 <string>$(EXECUTABLE_NAME)</string>
9 <key>CFBundleIdentifier</key>
10 <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11 <key>CFBundleInfoDictionaryVersion</key>
12 <string>6.0</string>
13 <key>CFBundleName</key>
14 <string>$(PRODUCT_NAME)</string>
15 <key>CFBundlePackageType</key>
16 <string>BNDL</string>
17 <key>CFBundleShortVersionString</key>
18 <string>1.0</string>
19 <key>CFBundleSignature</key>
20 <string>????</string>
21 <key>CFBundleVersion</key>
22 <string>1</string>
23</dict>
24</plist>
diff --git a/ios/cyberbadge_mobileTests/cyberbadge_mobileTests.m b/ios/cyberbadge_mobileTests/cyberbadge_mobileTests.m
new file mode 100644
index 0000000..f3ff562
--- /dev/null
+++ b/ios/cyberbadge_mobileTests/cyberbadge_mobileTests.m
@@ -0,0 +1,66 @@
1#import <UIKit/UIKit.h>
2#import <XCTest/XCTest.h>
3
4#import <React/RCTLog.h>
5#import <React/RCTRootView.h>
6
7#define TIMEOUT_SECONDS 600
8#define TEXT_TO_LOOK_FOR @"Welcome to React"
9
10@interface cyberbadge_mobileTests : XCTestCase
11
12@end
13
14@implementation cyberbadge_mobileTests
15
16- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test
17{
18 if (test(view)) {
19 return YES;
20 }
21 for (UIView *subview in [view subviews]) {
22 if ([self findSubviewInView:subview matching:test]) {
23 return YES;
24 }
25 }
26 return NO;
27}
28
29- (void)testRendersWelcomeScreen
30{
31 UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
32 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
33 BOOL foundElement = NO;
34
35 __block NSString *redboxError = nil;
36#ifdef DEBUG
37 RCTSetLogFunction(
38 ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
39 if (level >= RCTLogLevelError) {
40 redboxError = message;
41 }
42 });
43#endif
44
45 while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
46 [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
47 [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
48
49 foundElement = [self findSubviewInView:vc.view
50 matching:^BOOL(UIView *view) {
51 if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
52 return YES;
53 }
54 return NO;
55 }];
56 }
57
58#ifdef DEBUG
59 RCTSetLogFunction(RCTDefaultLogFunction);
60#endif
61
62 XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
63 XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
64}
65
66@end