Skip to content

Commit c39c276

Browse files
authored
[iOS Native Tests] - Feature Requests & Replies Modules (#342)
1 parent 69d8f7f commit c39c276

File tree

3 files changed

+193
-66
lines changed

3 files changed

+193
-66
lines changed

InstabugSample/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,38 @@ - (void) testgivenBoolean$setViewHierarchyEnabled_whenQuery_thenShouldCallNative
518518
XCTAssertTrue(IBGBugReporting.shouldCaptureViewHierarchy);
519519
}
520520

521+
/*
522+
+------------------------------------------------------------------------+
523+
| Feature Requets Module |
524+
+------------------------------------------------------------------------+
525+
*/
526+
527+
- (void) testgivenArgs$setEmailFieldRequiredForFeatureRequests_whenQuery_thenShouldCallNativeApi {
528+
id mock = OCMClassMock([IBGFeatureRequests class]);
529+
BOOL required = true;
530+
NSArray *actionTypesArray = [NSArray arrayWithObjects: @(IBGActionReportBug), nil];
531+
IBGAction actionTypes = 0;
532+
for (NSNumber *boxedValue in actionTypesArray) {
533+
actionTypes |= [boxedValue intValue];
534+
}
535+
OCMStub([mock setEmailFieldRequired:required forAction:actionTypes]);
536+
[self.instabugBridge setEmailFieldRequiredForFeatureRequests:required forAction:actionTypesArray];
537+
OCMVerify([mock setEmailFieldRequired:required forAction:actionTypes]);
538+
}
539+
540+
- (void) testgive$showFeatureRequests_whenQuery_thenShouldCallNativeApi {
541+
id mock = OCMClassMock([IBGFeatureRequests class]);
542+
OCMStub([mock show]);
543+
[self.instabugBridge showFeatureRequests];
544+
XCTestExpectation *expectation = [self expectationWithDescription:@"Test ME PLX"];
545+
546+
[[NSRunLoop mainRunLoop] performBlock:^{
547+
OCMVerify([mock show]);
548+
[expectation fulfill];
549+
}];
550+
551+
[self waitForExpectationsWithTimeout:EXPECTATION_TIMEOUT handler:nil];
552+
}
521553
/*
522554
+------------------------------------------------------------------------+
523555
| Crash Reporting Module |
@@ -565,6 +597,67 @@ - (void)testShowChats {
565597
[self waitForExpectationsWithTimeout:EXPECTATION_TIMEOUT handler:nil];
566598
}
567599

600+
601+
/*
602+
+------------------------------------------------------------------------+
603+
| Replies module |
604+
+------------------------------------------------------------------------+
605+
*/
606+
607+
608+
- (void) testgivenBoolean$setRepliesEnabled_whenQuery_thenShouldCallNativeApi {
609+
BOOL enabled = false;
610+
[self.instabugBridge setRepliesEnabled:enabled];
611+
XCTAssertFalse(IBGReplies.enabled);
612+
}
613+
614+
// Since there is no way to check the invocation of the block 'callback' inside the block, 'IBGReplies.enabled' is set to false
615+
// and the value is checked after callback execution to verify.
616+
- (void) testgivenCallback$hasChats_whenQuery_thenShouldCallNativeApi {
617+
IBGReplies.enabled = true;
618+
RCTResponseSenderBlock callback = ^(NSArray *response) { IBGReplies.enabled = false; };
619+
[self.instabugBridge hasChats:callback];
620+
XCTAssertFalse(IBGReplies.enabled);
621+
}
622+
623+
624+
- (void) testgive$showReplies_whenQuery_thenShouldCallNativeApi {
625+
id mock = OCMClassMock([IBGReplies class]);
626+
OCMStub([mock show]);
627+
[self.instabugBridge showReplies];
628+
XCTestExpectation *expectation = [self expectationWithDescription:@"Test ME PLX"];
629+
630+
[[NSRunLoop mainRunLoop] performBlock:^{
631+
OCMVerify([mock show]);
632+
[expectation fulfill];
633+
}];
634+
635+
[self waitForExpectationsWithTimeout:EXPECTATION_TIMEOUT handler:nil];
636+
}
637+
638+
- (void) testgivenOnNewReplyReceivedCallback$setOnNewReplyReceivedCallback_whenQuery_thenShouldCallNativeApi {
639+
id partialMock = OCMPartialMock(self.instabugBridge);
640+
RCTResponseSenderBlock callback = ^(NSArray *response) {};
641+
[partialMock setOnNewReplyReceivedCallback:callback];
642+
XCTAssertNotNil(IBGReplies.didReceiveReplyHandler);
643+
644+
OCMStub([partialMock sendEventWithName:@"IBGOnNewReplyReceivedCallback" body:nil]);
645+
IBGReplies.didReceiveReplyHandler();
646+
OCMVerify([partialMock sendEventWithName:@"IBGOnNewReplyReceivedCallback" body:nil]);
647+
}
648+
649+
- (void) testgivenCallback$getUnreadMessagesCount_whenQuery_thenShouldCallNativeApi {
650+
IBGReplies.enabled = true;
651+
RCTResponseSenderBlock callback = ^(NSArray *response) { IBGReplies.enabled = false; };
652+
[self.instabugBridge getUnreadMessagesCount:callback];
653+
XCTAssertFalse(IBGReplies.enabled);
654+
}
655+
656+
- (void) testgivenBoolean$setChatNotificationEnabled_whenQuery_thenShouldCallNativeApi {
657+
BOOL enabled = false;
658+
[self.instabugBridge setChatNotificationEnabled:enabled];
659+
XCTAssertFalse(IBGReplies.inAppNotificationsEnabled);
660+
}
568661
/*
569662
+------------------------------------------------------------------------+
570663
| Log Module |

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@
8585

8686
- (void)showSurveyWithToken:(NSString *)surveyToken;
8787

88-
/***********Bug Reporting*****************/
88+
/*
89+
+------------------------------------------------------------------------+
90+
| BugReporting Module |
91+
+------------------------------------------------------------------------+
92+
*/
8993

9094
- (void)setBugReportingEnabled:(BOOL)isEnabled;
9195

@@ -150,4 +154,34 @@
150154
- (void)logError:(NSString *)log;
151155
- (void)clearLogs;
152156

157+
158+
/*
159+
+------------------------------------------------------------------------+
160+
| Feature Requests Module |
161+
+------------------------------------------------------------------------+
162+
*/
163+
164+
- (void)setEmailFieldRequiredForFeatureRequests:(BOOL)isEmailFieldRequired forAction:(NSArray *)actionTypesArray;
165+
166+
- (void)showFeatureRequests;
167+
168+
/*
169+
+------------------------------------------------------------------------+
170+
| Replies Module |
171+
+------------------------------------------------------------------------+
172+
*/
173+
174+
- (void)setRepliesEnabled:(BOOL) isEnabled;
175+
176+
- (void)hasChats:(RCTResponseSenderBlock) callback;
177+
178+
- (void)showReplies;
179+
180+
- (void)setOnNewReplyReceivedCallback:(RCTResponseSenderBlock) callback;
181+
182+
- (void)getUnreadMessagesCount:(RCTResponseSenderBlock)callBack;
183+
184+
- (void)setChatNotificationEnabled:(BOOL)isChatNotificationEnabled;
185+
186+
153187
@end

0 commit comments

Comments
 (0)