Skip to content

Commit 29a00a3

Browse files
authored
✨ Surveys iOS tests (#341)
* ✨ Add surveys ios tests * ✨ add API definitions in header file
1 parent c39c276 commit 29a00a3

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

InstabugSample/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ - (void)setLocale:(IBGLocale)locale;
2323

2424
@end
2525

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+
2636
@interface InstabugSampleTests : XCTestCase
2737
@property (nonatomic, retain) InstabugReactBridge *instabugBridge;
2838
@end
@@ -321,6 +331,99 @@ - (void)testShowingSurveyWithToken {
321331
OCMVerify([mock showSurveyWithToken:token]);
322332
}
323333

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+
324427
/*
325428
+------------------------------------------------------------------------+
326429
| Bug Reporting Module |
@@ -421,7 +524,7 @@ - (void) testgivenPostInvocationHandlerSUBMIT$setPostInvocationHandler_whenQuery
421524
XCTAssertNotNil(IBGBugReporting.didDismissHandler);
422525

423526
NSDictionary *result = @{ @"dismissType": @"SUBMIT",
424-
@"reportType": @"feedback"};
527+
@"reportType": @"feedback"};
425528
OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
426529
IBGBugReporting.didDismissHandler(IBGDismissTypeSubmit,IBGReportTypeFeedback);
427530
OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
@@ -433,7 +536,7 @@ - (void) testgivenPostInvocationHandlerADD_ATTACHMENT$setPostInvocationHandler_w
433536
[partialMock setPostInvocationHandler:callback];
434537
XCTAssertNotNil(IBGBugReporting.didDismissHandler);
435538
NSDictionary *result = @{ @"dismissType": @"ADD_ATTACHMENT",
436-
@"reportType": @"feedback"};
539+
@"reportType": @"feedback"};
437540
OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);
438541
IBGBugReporting.didDismissHandler(IBGDismissTypeAddAttachment,IBGReportTypeFeedback);
439542
OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]);

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,27 @@
8282
| Surveys Module |
8383
+------------------------------------------------------------------------+
8484
*/
85-
85+
8686
- (void)showSurveyWithToken:(NSString *)surveyToken;
8787

88+
- (void)showSurveysIfAvailable;
89+
90+
- (void)setWillShowSurveyHandler:(RCTResponseSenderBlock)callBack;
91+
92+
- (void)setDidDismissSurveyHandler:(RCTResponseSenderBlock)callBack;
93+
94+
- (void)setAutoShowingSurveysEnabled:(BOOL)autoShowingSurveysEnabled;
95+
96+
- (void)setThresholdForReshowingSurveyAfterDismiss:(NSInteger)sessionCount daysCount:(NSInteger)daysCount;
97+
98+
- (void)setShouldShowSurveysWelcomeScreen:(BOOL)shouldShowWelcomeScreen;
99+
100+
- (void)hasRespondedToSurveyWithToken:(NSString *)surveyToken callback:(RCTResponseSenderBlock)callback;
101+
102+
- (void)getAvailableSurveys:(RCTResponseSenderBlock)callback;
103+
104+
- (void)setSurveysEnabled:(BOOL)surveysEnabled;
105+
88106
/*
89107
+------------------------------------------------------------------------+
90108
| BugReporting Module |

0 commit comments

Comments
 (0)