@@ -17,6 +17,8 @@ @interface InstabugSampleTests : XCTestCase
1717
1818@implementation InstabugSampleTests
1919
20+ NSTimeInterval EXPECTATION_TIMEOUT = 10 ;
21+
2022- (void )setUp {
2123 // Put setup code here. This method is called before the invocation of each test method in the class.
2224 self.instabugBridge = [[InstabugReactBridge alloc ] init ];
@@ -26,9 +28,204 @@ - (void)testShowingSurveyWithToken {
2628 NSString *token = @" token" ;
2729 id mock = OCMClassMock ([IBGSurveys class ]);
2830
29- [[[ mock stub ] classMethod ] showSurveyWithToken: token];
31+ OCMStub ([ mock showSurveyWithToken: token]) ;
3032 [self .instabugBridge showSurveyWithToken: token];
31- [[[mock verify ] classMethod ] showSurveyWithToken: token];
33+ OCMVerify ([mock showSurveyWithToken: token]);
34+ }
35+
36+
37+ /* **********Bug Reporting*****************/
38+
39+ - (void ) testgivenBoolean $setBugReportingEnabled_whenQuery_thenShouldCallNativeApi {
40+ BOOL enabled = false ;
41+ [self .instabugBridge setBugReportingEnabled: enabled];
42+ XCTAssertFalse (IBGBugReporting.enabled );
43+ }
44+
45+ - (void ) testgivenInvocationEvent $setInvocationEvents_whenQuery_thenShouldCallNativeApiWithArgs {
46+ NSArray *invocationEventsArr;
47+ invocationEventsArr = [NSArray arrayWithObjects: @(IBGInvocationEventScreenshot), nil ];
48+
49+ [self .instabugBridge setInvocationEvents: invocationEventsArr];
50+ IBGInvocationEvent invocationEvents = 0 ;
51+ for (NSNumber *boxedValue in invocationEventsArr) {
52+ invocationEvents |= [boxedValue intValue ];
53+ }
54+ XCTAssertEqual (IBGBugReporting.invocationEvents , invocationEvents);
3255}
3356
57+ - (void )testgiven $invoke_whenQuery_thenShouldCallNativeApi {
58+ id mock = OCMClassMock ([IBGBugReporting class ]);
59+
60+ OCMStub ([mock invoke ]);
61+ [self .instabugBridge invoke ];
62+ XCTestExpectation *expectation = [self expectationWithDescription: @" Test ME PLX" ];
63+
64+ [[NSRunLoop mainRunLoop ] performBlock: ^{
65+ OCMVerify ([mock invoke ]);
66+ [expectation fulfill ];
67+ }];
68+
69+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
70+ }
71+
72+ - (void ) testgivenOptions $setInvocationOptions_whenQuery_thenShouldCallNativeApiWithArgs {
73+ NSArray *invocationOptionsArr = [NSArray arrayWithObjects: @(IBGBugReportingInvocationOptionEmailFieldHidden), nil ];
74+
75+ [self .instabugBridge setInvocationOptions: invocationOptionsArr];
76+ IBGBugReportingInvocationOption invocationOptions = 0 ;
77+ for (NSNumber *boxedValue in invocationOptionsArr) {
78+ invocationOptions |= [boxedValue intValue ];
79+ }
80+ XCTAssertEqual (IBGBugReporting.invocationOptions , invocationOptions);
81+ }
82+
83+ - (void ) testgivenInvocationModeAndOptiond $invokeWithModeOptions_whenQuery_thenShouldCallNativeApiWithArgs {
84+ NSArray *invocationOptionsArr = [NSArray arrayWithObjects: @(IBGBugReportingInvocationOptionEmailFieldHidden), nil ];
85+ IBGBugReportingInvocationOption invocationOptions = 0 ;
86+ for (NSNumber *boxedValue in invocationOptionsArr) {
87+ invocationOptions |= [boxedValue intValue ];
88+ }
89+ IBGInvocationMode invocationMode = IBGInvocationModeNewBug;
90+ id mock = OCMClassMock ([IBGBugReporting class ]);
91+ OCMStub ([mock invokeWithMode: invocationMode options: invocationOptions]);
92+ [self .instabugBridge invokeWithInvocationModeAndOptions: invocationMode options: invocationOptionsArr];
93+ XCTestExpectation *expectation = [self expectationWithDescription: @" Test ME PLX" ];
94+
95+ [[NSRunLoop mainRunLoop ] performBlock: ^{
96+ OCMVerify ([mock invokeWithMode: invocationMode options: invocationOptions]);
97+ [expectation fulfill ];
98+ }];
99+
100+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
101+ }
102+
103+ - (void ) testgivenPreInvocationHandler $setPreInvocationHandler_whenQuery_thenShouldCallNativeApi {
104+ id partialMock = OCMPartialMock (self.instabugBridge );
105+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
106+ [partialMock setPreInvocationHandler: callback];
107+ XCTAssertNotNil (IBGBugReporting.willInvokeHandler );
108+ OCMStub ([partialMock sendEventWithName: @" IBGpreInvocationHandler" body: nil ]);
109+ IBGBugReporting.willInvokeHandler ();
110+ OCMVerify ([partialMock sendEventWithName: @" IBGpreInvocationHandler" body: nil ]);
111+ }
112+
113+
114+ - (void ) testgivenPostInvocationHandlerCANCEL $setPostInvocationHandler_whenQuery_thenShouldCallNativeApi {
115+ id partialMock = OCMPartialMock (self.instabugBridge );
116+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
117+ [partialMock setPostInvocationHandler: callback];
118+ XCTAssertNotNil (IBGBugReporting.didDismissHandler );
119+ NSDictionary *result = @{ @" dismissType" : @" CANCEL" ,
120+ @" reportType" : @" bug" };
121+ OCMStub ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
122+ IBGBugReporting.didDismissHandler (IBGDismissTypeCancel,IBGReportTypeBug);
123+ OCMVerify ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
124+ }
125+
126+ - (void ) testgivenPostInvocationHandlerSUBMIT $setPostInvocationHandler_whenQuery_thenShouldCallNativeApi {
127+ id partialMock = OCMPartialMock (self.instabugBridge );
128+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
129+ [partialMock setPostInvocationHandler: callback];
130+ XCTAssertNotNil (IBGBugReporting.didDismissHandler );
131+
132+ NSDictionary *result = @{ @" dismissType" : @" SUBMIT" ,
133+ @" reportType" : @" feedback" };
134+ OCMStub ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
135+ IBGBugReporting.didDismissHandler (IBGDismissTypeSubmit,IBGReportTypeFeedback);
136+ OCMVerify ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
137+ }
138+
139+ - (void ) testgivenPostInvocationHandlerADD_ATTACHMENT $setPostInvocationHandler_whenQuery_thenShouldCallNativeApi {
140+ id partialMock = OCMPartialMock (self.instabugBridge );
141+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
142+ [partialMock setPostInvocationHandler: callback];
143+ XCTAssertNotNil (IBGBugReporting.didDismissHandler );
144+ NSDictionary *result = @{ @" dismissType" : @" ADD_ATTACHMENT" ,
145+ @" reportType" : @" feedback" };
146+ OCMStub ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
147+ IBGBugReporting.didDismissHandler (IBGDismissTypeAddAttachment,IBGReportTypeFeedback);
148+ OCMVerify ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
149+ }
150+
151+ - (void ) testgivenBooleans $setPromptOptionsEnabled_whenQuery_thenShouldCallNativeApi {
152+ id mock = OCMClassMock ([IBGBugReporting class ]);
153+ BOOL enabled = true ;
154+ IBGPromptOption promptOption = IBGPromptOptionNone + IBGPromptOptionChat + IBGPromptOptionBug + IBGPromptOptionFeedback;
155+ OCMStub ([mock setPromptOptions: promptOption]);
156+ [self .instabugBridge setPromptOptionsEnabled: enabled feedback: enabled chat: enabled];
157+ OCMVerify ([mock setPromptOptions: promptOption]);
158+ }
159+
160+ - (void ) testgivenDouble $setShakingThresholdForiPhone_whenQuery_thenShouldCallNativeApi {
161+ double threshold = 12 ;
162+ [self .instabugBridge setShakingThresholdForiPhone: threshold];
163+ XCTAssertEqual (IBGBugReporting.shakingThresholdForiPhone , threshold);
164+ }
165+
166+ - (void ) testgivenDouble $setShakingThresholdForiPad_whenQuery_thenShouldCallNativeApi {
167+ double threshold = 12 ;
168+ [self .instabugBridge setShakingThresholdForiPad: threshold];
169+ XCTAssertEqual (IBGBugReporting.shakingThresholdForiPad , threshold);
170+ }
171+
172+ - (void ) testgivenExtendedBugReportMode $setExtendedBugReportMode_whenQuery_thenShouldCallNativeApi {
173+ IBGExtendedBugReportMode extendedBugReportMode = IBGExtendedBugReportModeEnabledWithOptionalFields;
174+ [self .instabugBridge setExtendedBugReportMode: extendedBugReportMode];
175+ XCTAssertEqual (IBGBugReporting.extendedBugReportMode , extendedBugReportMode);
176+ }
177+
178+ - (void ) testgivenArray $setReportTypes_whenQuery_thenShouldCallNativeApi {
179+ id mock = OCMClassMock ([IBGBugReporting class ]);
180+ NSArray *reportTypesArr = [NSArray arrayWithObjects: @(IBGReportTypeBug), nil ];
181+ IBGBugReportingReportType reportTypes = 0 ;
182+ for (NSNumber *boxedValue in reportTypesArr) {
183+ reportTypes |= [boxedValue intValue ];
184+ }
185+ OCMStub ([mock setPromptOptionsEnabledReportTypes: reportTypes]);
186+ [self .instabugBridge setReportTypes: reportTypesArr];
187+ OCMVerify ([mock setPromptOptionsEnabledReportTypes: reportTypes]);
188+ }
189+
190+
191+ - (void ) testgivenArgs $showBugReportingWithReportTypeAndOptions_whenQuery_thenShouldCallNativeApi {
192+ id mock = OCMClassMock ([IBGBugReporting class ]);
193+ IBGBugReportingReportType reportType = IBGBugReportingReportTypeBug;
194+ NSArray *options = [NSArray arrayWithObjects: @(IBGBugReportingOptionEmailFieldOptional), nil ];
195+ IBGBugReportingOption parsedOptions = 0 ;
196+ for (NSNumber *boxedValue in options) {
197+ parsedOptions |= [boxedValue intValue ];
198+ }
199+ OCMStub ([mock showWithReportType: reportType options: parsedOptions]);
200+ [self .instabugBridge showBugReportingWithReportTypeAndOptions: reportType :options];
201+
202+ XCTestExpectation *expectation = [self expectationWithDescription: @" Test ME PLX" ];
203+
204+ [[NSRunLoop mainRunLoop ] performBlock: ^{
205+ OCMVerify ([mock showWithReportType: reportType options: parsedOptions]);
206+ [expectation fulfill ];
207+ }];
208+
209+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
210+ }
211+
212+ - (void ) testgivenBoolean $setAutoScreenRecordingEnabled_whenQuery_thenShouldCallNativeApi {
213+ BOOL enabled = false ;
214+ [self .instabugBridge setAutoScreenRecordingEnabled: enabled];
215+ XCTAssertFalse (IBGBugReporting.autoScreenRecordingEnabled );
216+ }
217+
218+ - (void ) testgivenArgs $setAutoScreenRecordingMaxDuration_whenQuery_thenShouldCallNativeApi {
219+ CGFloat duration = 12.3 ;
220+ [self .instabugBridge setAutoScreenRecordingMaxDuration: duration];
221+ XCTAssertEqual (IBGBugReporting.autoScreenRecordingDuration , duration);
222+ }
223+
224+ - (void ) testgivenBoolean $setViewHierarchyEnabled_whenQuery_thenShouldCallNativeApi {
225+ BOOL enabled = false ;
226+ [self .instabugBridge setViewHierarchyEnabled: enabled];
227+ XCTAssertFalse (IBGBugReporting.shouldCaptureViewHierarchy );
228+ }
229+
230+
34231@end
0 commit comments