@@ -23,6 +23,16 @@ - (void)setLocale:(IBGLocale)locale;
23
23
24
24
@end
25
25
26
+ @protocol SurveysCPTestProtocol <NSObject >
27
+ /* *
28
+ * This protocol helps in correctly mapping Surveys mocked methods
29
+ * when their method name matches another method in a different
30
+ * module that differs in method signature.
31
+ */
32
+ - (void )setEnabled : (BOOL )isEnabled ;
33
+
34
+ @end
35
+
26
36
@interface InstabugSampleTests : XCTestCase
27
37
@property (nonatomic , retain ) InstabugReactBridge *instabugBridge;
28
38
@end
@@ -321,6 +331,99 @@ - (void)testShowingSurveyWithToken {
321
331
OCMVerify ([mock showSurveyWithToken: token]);
322
332
}
323
333
334
+
335
+ - (void ) testShowSurveyIfAvailable {
336
+ id mock = OCMClassMock ([IBGSurveys class ]);
337
+
338
+ OCMStub ([mock showSurveyIfAvailable ]);
339
+ [self .instabugBridge showSurveysIfAvailable ];
340
+ OCMVerify ([mock showSurveyIfAvailable ]);
341
+ }
342
+
343
+ - (void ) testAutoShowingSurveysEnabled {
344
+ id mock = OCMClassMock ([IBGSurveys class ]);
345
+ BOOL isEnabled = YES ;
346
+
347
+ OCMStub ([mock setAutoShowingEnabled: isEnabled]);
348
+ [self .instabugBridge setAutoShowingSurveysEnabled: isEnabled];
349
+ OCMVerify ([mock setAutoShowingEnabled: isEnabled]);
350
+ }
351
+
352
+ - (void ) testSetThresholdForReshowingSurveyAfterDismiss {
353
+ id mock = OCMClassMock ([IBGSurveys class ]);
354
+ NSInteger sessionCount = 1 ;
355
+ NSInteger daysCount = 2 ;
356
+
357
+ OCMStub ([mock setThresholdForReshowingSurveyAfterDismiss: sessionCount daysCount: daysCount]);
358
+ [self .instabugBridge setThresholdForReshowingSurveyAfterDismiss: sessionCount daysCount: daysCount];
359
+ OCMVerify ([mock setThresholdForReshowingSurveyAfterDismiss: sessionCount daysCount: daysCount]);
360
+ }
361
+
362
+ - (void ) testSetShouldShowSurveysWelcomeScreen {
363
+ id mock = OCMClassMock ([IBGSurveys class ]);
364
+ BOOL isEnabled = YES ;
365
+
366
+ OCMStub ([mock setShouldShowWelcomeScreen: isEnabled]);
367
+ [self .instabugBridge setShouldShowSurveysWelcomeScreen: isEnabled];
368
+ OCMVerify ([mock setShouldShowWelcomeScreen: isEnabled]);
369
+ }
370
+
371
+ - (void ) testSetSurveysEnabled {
372
+ id <SurveysCPTestProtocol> mock = OCMClassMock ([IBGSurveys class ]);
373
+ BOOL isEnabled = YES ;
374
+
375
+ OCMStub ([mock setEnabled: isEnabled]);
376
+ [self .instabugBridge setSurveysEnabled: isEnabled];
377
+ OCMVerify ([mock setEnabled: isEnabled]);
378
+ }
379
+
380
+ - (void ) testHasRespondedToSurveyWithToken {
381
+ id mock = OCMClassMock ([IBGSurveys class ]);
382
+ NSString *surveyToken = @" survey_token" ;
383
+ XCTestExpectation *expectation = [self expectationWithDescription: @" Testing hasRespondedToSurveyWithToken callback" ];
384
+ RCTResponseSenderBlock callback = ^void (NSArray *response) {
385
+ BOOL actualValue = [response[0 ] boolValue ];
386
+ XCTAssertTrue (actualValue);
387
+ [expectation fulfill ];
388
+ };
389
+
390
+ OCMStub ([mock hasRespondedToSurveyWithToken: surveyToken]).andReturn (YES );
391
+ [self .instabugBridge hasRespondedToSurveyWithToken: surveyToken callback: callback];
392
+ OCMVerify ([mock hasRespondedToSurveyWithToken: surveyToken]);
393
+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
394
+ }
395
+
396
+ - (void ) testGetAvailableSurveys {
397
+ id mock = OCMClassMock ([IBGSurveys class ]);
398
+ NSString *surveyToken = @" survey_token" ;
399
+ RCTResponseSenderBlock callback = ^void (NSArray *response) {};
400
+
401
+ OCMStub ([mock availableSurveys ]);
402
+ [self .instabugBridge getAvailableSurveys: callback];
403
+ OCMVerify ([mock availableSurveys ]);
404
+
405
+ }
406
+
407
+ - (void ) testSetWillShowSurveyHandler {
408
+ id partialMock = OCMPartialMock (self.instabugBridge );
409
+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
410
+ [partialMock setWillShowSurveyHandler: callback];
411
+ XCTAssertNotNil (IBGSurveys.willShowSurveyHandler );
412
+ OCMStub ([partialMock sendEventWithName: OCMOCK_ANY body: nil ]);
413
+ IBGSurveys.willShowSurveyHandler ();
414
+ OCMVerify ([partialMock sendEventWithName: @" IBGWillShowSurvey" body: nil ]);
415
+ }
416
+
417
+ - (void ) testSetDidDismissSurveyHandler {
418
+ id partialMock = OCMPartialMock (self.instabugBridge );
419
+ RCTResponseSenderBlock callback = ^(NSArray *response) {};
420
+ [partialMock setDidDismissSurveyHandler: callback];
421
+ XCTAssertNotNil (IBGSurveys.didDismissSurveyHandler );
422
+ OCMStub ([partialMock sendEventWithName: OCMOCK_ANY body: nil ]);
423
+ IBGSurveys.didDismissSurveyHandler ();
424
+ OCMVerify ([partialMock sendEventWithName: @" IBGDidDismissSurvey" body: nil ]);
425
+ }
426
+
324
427
/*
325
428
+------------------------------------------------------------------------+
326
429
| Bug Reporting Module |
@@ -421,7 +524,7 @@ - (void) testgivenPostInvocationHandlerSUBMIT$setPostInvocationHandler_whenQuery
421
524
XCTAssertNotNil (IBGBugReporting.didDismissHandler );
422
525
423
526
NSDictionary *result = @{ @" dismissType" : @" SUBMIT" ,
424
- @" reportType" : @" feedback" };
527
+ @" reportType" : @" feedback" };
425
528
OCMStub ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
426
529
IBGBugReporting.didDismissHandler (IBGDismissTypeSubmit,IBGReportTypeFeedback);
427
530
OCMVerify ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
@@ -433,7 +536,7 @@ - (void) testgivenPostInvocationHandlerADD_ATTACHMENT$setPostInvocationHandler_w
433
536
[partialMock setPostInvocationHandler: callback];
434
537
XCTAssertNotNil (IBGBugReporting.didDismissHandler );
435
538
NSDictionary *result = @{ @" dismissType" : @" ADD_ATTACHMENT" ,
436
- @" reportType" : @" feedback" };
539
+ @" reportType" : @" feedback" };
437
540
OCMStub ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
438
541
IBGBugReporting.didDismissHandler (IBGDismissTypeAddAttachment,IBGReportTypeFeedback);
439
542
OCMVerify ([partialMock sendEventWithName: @" IBGpostInvocationHandler" body: result]);
0 commit comments