|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -#import <UIKit/UIKit.h> |
9 | 8 | #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!" |
| 9 | +#import "OCMock/OCMock.h" |
| 10 | +#import "Instabug/Instabug.h" |
| 11 | +#import "Instabug/IBGSurvey.h" |
| 12 | +#import "InstabugReactBridge.h" |
16 | 13 |
|
17 | 14 | @interface InstabugSampleTests : XCTestCase
|
18 |
| - |
| 15 | +@property InstabugReactBridge *instabugBridge; |
19 | 16 | @end
|
20 | 17 |
|
21 | 18 | @implementation InstabugSampleTests
|
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; |
| 20 | +- (void)setUp { |
| 21 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 22 | + self.instabugBridge = [[InstabugReactBridge alloc] init]; |
34 | 23 | }
|
35 | 24 |
|
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); |
| 25 | +- (void)testShowingSurveyWithToken { |
| 26 | + NSString *token = @"token"; |
| 27 | + id mock = OCMClassMock([IBGSurveys class]); |
| 28 | + |
| 29 | + [[[mock stub] classMethod] showSurveyWithToken:token]; |
| 30 | + [self.instabugBridge showSurveyWithToken:token]; |
| 31 | + [[[mock verify] classMethod] showSurveyWithToken:token]; |
65 | 32 | }
|
66 | 33 |
|
67 |
| - |
68 | 34 | @end
|
0 commit comments