Skip to content

Commit da9f9ae

Browse files
added ios tests
1 parent d957e5c commit da9f9ae

File tree

9 files changed

+1124
-52
lines changed

9 files changed

+1124
-52
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// IBGConstants.h
3+
// InstabugSample
4+
//
5+
// Created by Salma Ali on 7/30/19.
6+
// Copyright © 2019 Facebook. All rights reserved.
7+
//
8+
9+
#ifndef IBGConstants_h
10+
#define IBGConstants_h
11+
12+
extern NSTimeInterval const EXPECTATION_TIMEOUT;
13+
14+
#endif /* IBGConstants_h */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// IBGConstants.m
3+
// InstabugSampleTests
4+
//
5+
// Created by Salma Ali on 7/30/19.
6+
// Copyright © 2019 Facebook. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NSTimeInterval const EXPECTATION_TIMEOUT = 10;
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// InstabugAPMTests.m
3+
// InstabugSampleTests
4+
//
5+
// Created by Ali Abdelfattah on 12/12/20.
6+
// Copyright © 2020 Facebook. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "OCMock/OCMock.h"
11+
#import "InstabugAPMBridge.h"
12+
#import <Instabug/IBGTypes.h>
13+
#import <Instabug/IBGAPM.h>
14+
#import "Instabug/Instabug.h"
15+
#import "IBGConstants.h"
16+
17+
@interface InstabugAPMTests : XCTestCase
18+
@property (nonatomic, retain) InstabugAPMBridge *instabugBridge;
19+
@end
20+
21+
@protocol APMCPTestProtocol <NSObject>
22+
/**
23+
* This protocol helps in correctly mapping APM mocked methods
24+
* when their method name matches another method in a different
25+
* module that differs in method signature.
26+
*/
27+
- (void)setEnabled:(BOOL)isEnabled;
28+
29+
@end
30+
31+
@protocol ExecutionTraceCPTestProtocol <NSObject>
32+
/**
33+
* This protocol helps in correctly mapping IBGExecutionTrace mocked methods
34+
* when their method name matches another method in a different
35+
* module that differs in method signature.
36+
*/
37+
- (void)end;
38+
@end
39+
40+
@implementation InstabugAPMTests
41+
42+
- (void)setUp {
43+
// Put setup code here. This method is called before the invocation of each test method in the class.
44+
self.instabugBridge = [[InstabugAPMBridge alloc] init];
45+
}
46+
47+
/*
48+
+------------------------------------------------------------------------+
49+
| APM Module |
50+
+------------------------------------------------------------------------+
51+
*/
52+
53+
- (void) testSetAPMEnabled {
54+
id mock = OCMClassMock([IBGAPM class]);
55+
BOOL isEnabled = YES;
56+
57+
OCMStub([mock setEnabled:isEnabled]);
58+
[self.instabugBridge setEnabled:isEnabled];
59+
OCMVerify([mock setEnabled:isEnabled]);
60+
}
61+
62+
- (void) testSetLogLevel {
63+
id mock = OCMClassMock([IBGAPM class]);
64+
BOOL logLevel = IBGLogLevelVerbose;
65+
66+
OCMStub([mock setLogLevel:logLevel]);
67+
[self.instabugBridge setLogLevel:logLevel];
68+
OCMVerify([mock setLogLevel:logLevel]);
69+
}
70+
71+
- (void) testSetAppLaunchEnabled {
72+
id mock = OCMClassMock([IBGAPM class]);
73+
BOOL isEnabled = YES;
74+
75+
OCMStub([mock setAppLaunchEnabled:isEnabled]);
76+
[self.instabugBridge setAppLaunchEnabled:isEnabled];
77+
OCMVerify([mock setAppLaunchEnabled:isEnabled]);
78+
}
79+
80+
- (void) testSetAutoUITraceEnabled {
81+
id mock = OCMClassMock([IBGAPM class]);
82+
BOOL isEnabled = YES;
83+
84+
OCMStub([mock setAutoUITraceEnabled:isEnabled]);
85+
[self.instabugBridge setAutoUITraceEnabled:isEnabled];
86+
OCMVerify([mock setAutoUITraceEnabled:isEnabled]);
87+
}
88+
89+
- (void) testStartExecutionTrace {
90+
id mock = OCMClassMock([IBGAPM class]);
91+
NSString* traceName = @"Trace_1";
92+
NSString* traceKey = @"1";
93+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
94+
95+
OCMStub([mock startExecutionTraceWithName:traceName]);
96+
[self.instabugBridge startExecutionTrace:traceName :traceKey :callback];
97+
OCMVerify([mock startExecutionTraceWithName:traceName]);
98+
}
99+
100+
- (void) testSetExecutionTraceAttribute {
101+
NSString* traceName = @"Trace_1";
102+
NSString* traceId = @"Id_1";
103+
NSString* traceKey = @"Key_1";
104+
NSString* traceValue = @"1";
105+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
106+
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
107+
id mock = OCMClassMock([IBGAPM class]);
108+
id traceMock = OCMPartialMock(trace);
109+
110+
OCMStub([mock startExecutionTraceWithName:traceName]).andReturn(trace);
111+
[self.instabugBridge startExecutionTrace:traceName :traceId :callback];
112+
113+
OCMStub([traceMock setAttributeWithKey:traceKey value:traceValue]);
114+
[self.instabugBridge setExecutionTraceAttribute:traceId :traceKey :traceValue];
115+
OCMVerify([traceMock setAttributeWithKey:traceKey value:traceValue]);
116+
}
117+
118+
- (void) testEndExecutionTrace {
119+
NSString* traceName = @"Trace_1";
120+
NSString* traceId = @"Id_1";
121+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
122+
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
123+
id apmMock = OCMClassMock([IBGAPM class]);
124+
id<ExecutionTraceCPTestProtocol> traceMock = OCMPartialMock(trace);
125+
126+
OCMStub([apmMock startExecutionTraceWithName:traceName]).andReturn(trace);
127+
[self.instabugBridge startExecutionTrace:traceName :traceId :callback];
128+
129+
OCMStub([traceMock end]);
130+
[self.instabugBridge endExecutionTrace:traceId];
131+
OCMVerify([traceMock end]);
132+
}
133+
134+
- (void) testStartUITrace {
135+
id mock = OCMClassMock([IBGAPM class]);
136+
NSString* traceName = @"UITrace_1";
137+
138+
OCMStub([mock startUITraceWithName:traceName]);
139+
[self.instabugBridge startUITrace:traceName];
140+
OCMVerify([mock startUITraceWithName:traceName]);
141+
}
142+
143+
- (void) testEndUITrace {
144+
id mock = OCMClassMock([IBGAPM class]);
145+
146+
OCMStub([mock endUITrace]);
147+
[self.instabugBridge endUITrace];
148+
OCMVerify([mock endUITrace]);
149+
}
150+
151+
@end
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
//
2+
// InstabugBugReportingTests.m
3+
// InstabugSampleTests
4+
//
5+
// Created by Salma Ali on 7/30/19.
6+
// Copyright © 2019 Facebook. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "OCMock/OCMock.h"
11+
#import "InstabugBugReportingBridge.h"
12+
#import <Instabug/IBGTypes.h>
13+
#import "Instabug/Instabug.h"
14+
#import "IBGConstants.h"
15+
16+
@interface InstabugBugReportingTests : XCTestCase
17+
@property (nonatomic, retain) InstabugBugReportingBridge *instabugBridge;
18+
@end
19+
20+
@implementation InstabugBugReportingTests
21+
22+
- (void)setUp {
23+
// Put setup code here. This method is called before the invocation of each test method in the class.
24+
self.instabugBridge = [[InstabugBugReportingBridge alloc] init];
25+
}
26+
27+
/*
28+
+------------------------------------------------------------------------+
29+
| Bug Reporting Module |
30+
+------------------------------------------------------------------------+
31+
*/
32+
33+
- (void) testgivenBoolean$setBugReportingEnabled_whenQuery_thenShouldCallNativeApi {
34+
BOOL enabled = true;
35+
[self.instabugBridge setEnabled:enabled];
36+
XCTAssertTrue(IBGBugReporting.enabled);
37+
}
38+
39+
- (void) testgivenInvocationEvent$setInvocationEvents_whenQuery_thenShouldCallNativeApiWithArgs {
40+
NSArray *invocationEventsArr;
41+
invocationEventsArr = [NSArray arrayWithObjects: @(IBGInvocationEventScreenshot), nil];
42+
43+
[self.instabugBridge setInvocationEvents:invocationEventsArr];
44+
IBGInvocationEvent invocationEvents = 0;
45+
for (NSNumber *boxedValue in invocationEventsArr) {
46+
invocationEvents |= [boxedValue intValue];
47+
}
48+
XCTAssertEqual(IBGBugReporting.invocationEvents, invocationEvents);
49+
}
50+
51+
- (void) testgivenOptions$setOptions_whenQuery_thenShouldCallNativeApiWithArgs {
52+
NSArray *invocationOptionsArr = [NSArray arrayWithObjects: @(IBGBugReportingInvocationOptionEmailFieldHidden), nil];
53+
54+
[self.instabugBridge setOptions:invocationOptionsArr];
55+
IBGBugReportingOption invocationOptions = 0;
56+
for (NSNumber *boxedValue in invocationOptionsArr) {
57+
invocationOptions |= [boxedValue intValue];
58+
}
59+
XCTAssertEqual(IBGBugReporting.bugReportingOptions, invocationOptions);
60+
}
61+
62+
- (void) testgivenHandler$setOnInvokeHandler_whenQuery_thenShouldCallNativeApi {
63+
id partialMock = OCMPartialMock(self.instabugBridge);
64+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
65+
[partialMock setOnInvokeHandler:callback];
66+
XCTAssertNotNil(IBGBugReporting.willInvokeHandler);
67+
OCMStub([partialMock sendEventWithName:@"IBGpreInvocationHandler" body:nil]);
68+
IBGBugReporting.willInvokeHandler();
69+
OCMVerify([partialMock sendEventWithName:@"IBGpreInvocationHandler" body:nil]);
70+
}
71+
72+
73+
- (void) testgivenHandlerCANCEL$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi {
74+
id partialMock = OCMPartialMock(self.instabugBridge);
75+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
76+
[partialMock setOnSDKDismissedHandler:callback];
77+
XCTAssertNotNil(IBGBugReporting.didDismissHandler);
78+
NSDictionary *result = @{ @"dismissType": @"CANCEL",
79+
@"reportType": @"bug"};
80+
OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
81+
IBGBugReporting.didDismissHandler(IBGDismissTypeCancel,IBGReportTypeBug);
82+
OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
83+
}
84+
85+
- (void) testgivenHandlerSUBMIT$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi {
86+
id partialMock = OCMPartialMock(self.instabugBridge);
87+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
88+
[partialMock setOnSDKDismissedHandler:callback];
89+
XCTAssertNotNil(IBGBugReporting.didDismissHandler);
90+
91+
NSDictionary *result = @{ @"dismissType": @"SUBMIT",
92+
@"reportType": @"feedback"};
93+
OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
94+
IBGBugReporting.didDismissHandler(IBGDismissTypeSubmit,IBGReportTypeFeedback);
95+
OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
96+
}
97+
98+
- (void) testgivenHandlerADD_ATTACHMENT$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi {
99+
id partialMock = OCMPartialMock(self.instabugBridge);
100+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
101+
[partialMock setOnSDKDismissedHandler:callback];
102+
XCTAssertNotNil(IBGBugReporting.didDismissHandler);
103+
NSDictionary *result = @{ @"dismissType": @"ADD_ATTACHMENT",
104+
@"reportType": @"feedback"};
105+
OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
106+
IBGBugReporting.didDismissHandler(IBGDismissTypeAddAttachment,IBGReportTypeFeedback);
107+
OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
108+
}
109+
110+
- (void) skip_testgivenDouble$setShakingThresholdForiPhone_whenQuery_thenShouldCallNativeApi {
111+
double threshold = 12;
112+
[self.instabugBridge setShakingThresholdForiPhone:threshold];
113+
XCTAssertEqual(IBGBugReporting.shakingThresholdForiPhone, threshold);
114+
}
115+
116+
- (void) skip_testgivenDouble$setShakingThresholdForiPad_whenQuery_thenShouldCallNativeApi {
117+
double threshold = 12;
118+
[self.instabugBridge setShakingThresholdForiPad:threshold];
119+
XCTAssertEqual(IBGBugReporting.shakingThresholdForiPad, threshold);
120+
}
121+
122+
- (void) testgivenExtendedBugReportMode$setExtendedBugReportMode_whenQuery_thenShouldCallNativeApi {
123+
IBGExtendedBugReportMode extendedBugReportMode = IBGExtendedBugReportModeEnabledWithOptionalFields;
124+
[self.instabugBridge setExtendedBugReportMode:extendedBugReportMode];
125+
XCTAssertEqual(IBGBugReporting.extendedBugReportMode, extendedBugReportMode);
126+
}
127+
128+
- (void) testgivenArray$setReportTypes_whenQuery_thenShouldCallNativeApi {
129+
id mock = OCMClassMock([IBGBugReporting class]);
130+
NSArray *reportTypesArr = [NSArray arrayWithObjects: @(IBGReportTypeBug), nil];
131+
IBGBugReportingReportType reportTypes = 0;
132+
for (NSNumber *boxedValue in reportTypesArr) {
133+
reportTypes |= [boxedValue intValue];
134+
}
135+
OCMStub([mock setPromptOptionsEnabledReportTypes:reportTypes]);
136+
[self.instabugBridge setReportTypes:reportTypesArr];
137+
OCMVerify([mock setPromptOptionsEnabledReportTypes:reportTypes]);
138+
}
139+
140+
141+
- (void) testgivenArgs$showBugReportingWithReportTypeAndOptions_whenQuery_thenShouldCallNativeApi {
142+
id mock = OCMClassMock([IBGBugReporting class]);
143+
IBGBugReportingReportType reportType = IBGBugReportingReportTypeBug;
144+
NSArray *options = [NSArray arrayWithObjects: @(IBGBugReportingOptionEmailFieldOptional), nil];
145+
IBGBugReportingOption parsedOptions = 0;
146+
for (NSNumber *boxedValue in options) {
147+
parsedOptions |= [boxedValue intValue];
148+
}
149+
OCMStub([mock showWithReportType:reportType options:parsedOptions]);
150+
[self.instabugBridge show:reportType options:options];
151+
152+
XCTestExpectation *expectation = [self expectationWithDescription:@"Test ME PLX"];
153+
154+
[[NSRunLoop mainRunLoop] performBlock:^{
155+
OCMVerify([mock showWithReportType:reportType options:parsedOptions]);
156+
[expectation fulfill];
157+
}];
158+
159+
[self waitForExpectationsWithTimeout:EXPECTATION_TIMEOUT handler:nil];
160+
}
161+
162+
- (void) testgivenBoolean$setAutoScreenRecordingEnabled_whenQuery_thenShouldCallNativeApi {
163+
BOOL enabled = true;
164+
[self.instabugBridge setAutoScreenRecordingEnabled:enabled];
165+
XCTAssertTrue(IBGBugReporting.autoScreenRecordingEnabled);
166+
}
167+
168+
- (void) testgivenArgs$setAutoScreenRecordingMaxDuration_whenQuery_thenShouldCallNativeApi {
169+
CGFloat duration = 12.3;
170+
[self.instabugBridge setAutoScreenRecordingMaxDuration:duration];
171+
XCTAssertEqual(IBGBugReporting.autoScreenRecordingDuration, duration);
172+
}
173+
174+
- (void) testgivenBoolean$setViewHierarchyEnabled_whenQuery_thenShouldCallNativeApi {
175+
BOOL enabled = true;
176+
[self.instabugBridge setViewHierarchyEnabled:enabled];
177+
XCTAssertTrue(IBGBugReporting.shouldCaptureViewHierarchy);
178+
}
179+
180+
@end
181+

0 commit comments

Comments
 (0)