Skip to content

Commit fb325d7

Browse files
Add ios test for showSurveyWithToken
1 parent bc75dc7 commit fb325d7

File tree

3 files changed

+17
-53
lines changed

3 files changed

+17
-53
lines changed

InstabugSample/ios/InstabugSample.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,16 +548,12 @@
548548
buildActionMask = 2147483647;
549549
files = (
550550
);
551-
inputFileListPaths = (
552-
);
553551
inputPaths = (
554552
"${PODS_ROOT}/Target Support Files/Pods-InstabugSample/Pods-InstabugSample-frameworks.sh",
555553
"${PODS_ROOT}/Instabug/Instabug.framework",
556554
"${PODS_ROOT}/Instabug/Instabug.framework.dSYM",
557555
);
558556
name = "[CP] Embed Pods Frameworks";
559-
outputFileListPaths = (
560-
);
561557
outputPaths = (
562558
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Instabug.framework",
563559
"${DWARF_DSYM_FOLDER_PATH}/Instabug.framework.dSYM",

InstabugSample/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,30 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <UIKit/UIKit.h>
98
#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"
1613

1714
@interface InstabugSampleTests : XCTestCase
18-
15+
@property InstabugReactBridge *instabugBridge;
1916
@end
2017

2118
@implementation InstabugSampleTests
2219

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];
3423
}
3524

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];
6532
}
6633

67-
6834
@end

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
@interface InstabugReactBridge : RCTEventEmitter <RCTBridgeModule>
1414

15+
- (void)showSurveyWithToken:(NSString *)surveyToken;
16+
1517
@end

0 commit comments

Comments
 (0)