Skip to content

Commit 0e8ccb8

Browse files
author
AliAbdelfattah
authored
Merge pull request #325 from Instabug/fix/ios-tests-pods
iOS Native Tests with pods
2 parents 4981c93 + 72826eb commit 0e8ccb8

File tree

9 files changed

+49
-735
lines changed

9 files changed

+49
-735
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,32 @@ jobs:
117117
name: Run UnitTest
118118
command: cd android && ./gradlew test
119119

120+
121+
ios_test:
122+
macos:
123+
xcode: "10.2.0"
124+
working_directory: ~/project/InstabugSample/ios
125+
environment:
126+
FL_OUTPUT_DIR: output
127+
steps:
128+
- checkout:
129+
path: ~/project
130+
- run:
131+
name: Install node_modules
132+
command: cd .. && yarn
133+
- run:
134+
name: Remove instabug.framework
135+
command: rm -rf ../node_modules/instabug-reactnative/ios/Instabug.framework
136+
- run:
137+
name: Fetch CocoaPods Specs
138+
command: curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf
139+
- run:
140+
name: Install CocoaPods
141+
command: pod install
142+
- run:
143+
name: Build and run tests
144+
command: xcodebuild -workspace InstabugSample.xcworkspace -scheme InstabugSample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone X,OS=12.2' test | xcpretty
145+
120146
publish:
121147
macos:
122148
xcode: "10.1.0"
@@ -136,11 +162,13 @@ workflows:
136162
- test_module
137163
- test_sample
138164
- test_android
165+
- ios_test
139166
- hold:
140167
requires:
141168
- test_module
142169
- test_sample
143170
- test_android
171+
- ios_test
144172
type: approval
145173
filters:
146174
branches:

InstabugSample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ DerivedData
2121
*.ipa
2222
*.xcuserstate
2323
project.xcworkspace
24+
InstabugSample.xcworkspace
2425

2526
# Android/IntelliJ
2627
#

InstabugSample/ios/InstabugSample-tvOS/Info.plist

Lines changed: 0 additions & 53 deletions
This file was deleted.

InstabugSample/ios/InstabugSample-tvOSTests/Info.plist

Lines changed: 0 additions & 24 deletions
This file was deleted.

InstabugSample/ios/InstabugSample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 470 deletions
Large diffs are not rendered by default.

InstabugSample/ios/InstabugSample.xcodeproj/xcshareddata/xcschemes/InstabugSample-tvOS.xcscheme

Lines changed: 0 additions & 129 deletions
This file was deleted.

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

InstabugSample/ios/Podfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ target 'InstabugSample' do
2323
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
2424
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
2525
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
26+
27+
pod 'OCMock', '~> 3.4'
2628

2729
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
2830
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
@@ -35,13 +37,3 @@ target 'InstabugSample' do
3537

3638
use_native_modules!
3739
end
38-
39-
target 'InstabugSample-tvOS' do
40-
# Pods for InstabugSample-tvOS
41-
42-
target 'InstabugSample-tvOSTests' do
43-
inherit! :search_paths
44-
# Pods for testing
45-
end
46-
47-
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)