1010#import " Instabug/Instabug.h"
1111#import " Instabug/IBGSurvey.h"
1212#import " InstabugReactBridge.h"
13+ #import < Instabug/IBGTypes.h>
14+
15+ @protocol InstabugCPTestProtocol <NSObject >
16+ /* *
17+ * This protocol helps in correctly mapping Instabug mocked methods
18+ * when their method name matches another method in a different
19+ * module that differs in method signature.
20+ */
21+ - (void )startWithToken : (NSString *)token invocationEvents : (IBGInvocationEvent)invocationEvents ;
22+ - (void )setLocale : (IBGLocale)locale ;
23+
24+ @end
1325
1426@interface InstabugSampleTests : XCTestCase
15- @property InstabugReactBridge *instabugBridge;
27+ @property ( nonatomic , retain ) InstabugReactBridge *instabugBridge;
1628@end
1729
1830@implementation InstabugSampleTests
@@ -24,17 +36,290 @@ - (void)setUp {
2436 self.instabugBridge = [[InstabugReactBridge alloc ] init ];
2537}
2638
39+ /*
40+ +------------------------------------------------------------------------+
41+ | Instabug Module |
42+ +------------------------------------------------------------------------+
43+ */
44+
45+ - (void )testStartWithToken {
46+ id <InstabugCPTestProtocol> mock = OCMClassMock ([Instabug class ]);
47+ IBGInvocationEvent floatingButtonInvocationEvent = IBGInvocationEventFloatingButton;
48+ NSString *appToken = @" app_token" ;
49+ NSArray *invocationEvents = [NSArray arrayWithObjects: [NSNumber numberWithInteger: floatingButtonInvocationEvent], nil ];
50+ XCTestExpectation *expectation = [self expectationWithDescription: @" Testing [Instabug startWithToken]" ];
51+
52+ OCMStub ([mock startWithToken: appToken invocationEvents: floatingButtonInvocationEvent]);
53+ [self .instabugBridge startWithToken: appToken invocationEvents: invocationEvents];
54+
55+ [[NSRunLoop mainRunLoop ] performBlock: ^{
56+ OCMVerify ([mock startWithToken: appToken invocationEvents: floatingButtonInvocationEvent]);
57+ [expectation fulfill ];
58+ }];
59+
60+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
61+ }
62+
63+ - (void )testSetUserData {
64+ id mock = OCMClassMock ([Instabug class ]);
65+ NSString *userData = @" user_data" ;
66+
67+ OCMStub ([mock setUserData: userData]);
68+ [self .instabugBridge setUserData: userData];
69+ OCMVerify ([mock setUserData: userData]);
70+ }
71+
72+ - (void )testSetTrackUserSteps {
73+ id mock = OCMClassMock ([Instabug class ]);
74+ BOOL isEnabled = true ;
75+
76+ OCMStub ([mock setTrackUserSteps: isEnabled]);
77+ [self .instabugBridge setTrackUserSteps: isEnabled];
78+ OCMVerify ([mock setTrackUserSteps: isEnabled]);
79+ }
80+
81+ - (void )testSetSessionProfilerEnabled {
82+ id mock = OCMClassMock ([Instabug class ]);
83+ BOOL sessionProfilerEnabled = true ;
84+
85+ OCMStub ([mock setSessionProfilerEnabled: sessionProfilerEnabled]);
86+ [self .instabugBridge setSessionProfilerEnabled: sessionProfilerEnabled];
87+ OCMVerify ([mock setSessionProfilerEnabled: sessionProfilerEnabled]);
88+ }
89+
90+ - (void )testSetPushNotificationsEnabled {
91+ id mock = OCMClassMock ([Instabug class ]);
92+ BOOL isPushNotificationEnabled = true ;
93+
94+ OCMStub ([mock setPushNotificationsEnabled: isPushNotificationEnabled]);
95+ [self .instabugBridge setPushNotificationsEnabled: isPushNotificationEnabled];
96+ OCMVerify ([mock setPushNotificationsEnabled: isPushNotificationEnabled]);
97+ }
98+
99+ - (void )testSetLocale {
100+ id <InstabugCPTestProtocol> mock = OCMClassMock ([Instabug class ]);
101+
102+ OCMStub ([mock setLocale: IBGLocaleCzech]);
103+ [self .instabugBridge setLocale: IBGLocaleCzech];
104+ OCMVerify ([mock setLocale: IBGLocaleCzech]);
105+ }
106+
107+ - (void )testSetColorTheme {
108+ id mock = OCMClassMock ([Instabug class ]);
109+ IBGColorTheme colorTheme = IBGColorThemeLight;
110+ XCTestExpectation *expectation = [self expectationWithDescription: @" Testing [Instabug setColorTheme]" ];
111+
112+ OCMStub ([mock setColorTheme: colorTheme]);
113+ [self .instabugBridge setColorTheme: colorTheme];
114+
115+ [[NSRunLoop mainRunLoop ] performBlock: ^{
116+ OCMVerify ([mock setColorTheme: colorTheme]);
117+ [expectation fulfill ];
118+ }];
119+
120+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
121+ }
122+
123+ - (void )testSetPrimaryColor {
124+ UIColor *color = [UIColor whiteColor ];
125+ XCTestExpectation *expectation = [self expectationWithDescription: @" Testing [Instabug setPrimaryColor]" ];
126+
127+ [self .instabugBridge setPrimaryColor: color];
128+ [[NSRunLoop mainRunLoop ] performBlock: ^{
129+ XCTAssertEqualObjects (Instabug.tintColor , color);
130+ [expectation fulfill ];
131+ }];
132+
133+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
134+ }
135+
136+ - (void )testAppendTags {
137+ id mock = OCMClassMock ([Instabug class ]);
138+ NSArray *tags = @[@" tag1" , @" tag2" ];
139+
140+ OCMStub ([mock appendTags: tags]);
141+ [self .instabugBridge appendTags: tags];
142+ OCMVerify ([mock appendTags: tags]);
143+ }
144+
145+ - (void )testResetTags {
146+ id mock = OCMClassMock ([Instabug class ]);
147+
148+ OCMStub ([mock resetTags ]);
149+ [self .instabugBridge resetTags ];
150+ OCMVerify ([mock resetTags ]);
151+ }
152+
153+ - (void )testGetTags {
154+ id mock = OCMClassMock ([Instabug class ]);
155+ RCTResponseSenderBlock callbackBlock = ^void (NSArray *response) {};
156+ NSDictionary *dictionary = @{ @" someKey" : @" someValue" };
157+
158+ OCMStub ([mock getTags ]).andReturn (dictionary);
159+ [self .instabugBridge getTags: callbackBlock];
160+ OCMVerify ([mock getTags ]);
161+ }
162+
163+ - (void )testSetString {
164+ id mock = OCMClassMock ([Instabug class ]);
165+ NSString *value = @" string_value" ;
166+ NSString *key = @" KEY" ;
167+
168+ OCMStub ([mock setValue: value forStringWithKey: key]);
169+ [self .instabugBridge setString: value toKey: key];
170+ OCMVerify ([mock setValue: value forStringWithKey: key]);
171+ }
172+
173+ - (void )testIdentifyUserWithEmail {
174+ id mock = OCMClassMock ([Instabug class ]);
175+ NSString *email = @" em@il.com" ;
176+ NSString *name = @" this is my name" ;
177+
178+ OCMStub ([mock identifyUserWithEmail: email name: name]);
179+ [self .instabugBridge identifyUserWithEmail: email name: name];
180+ OCMVerify ([mock identifyUserWithEmail: email name: name]);
181+ }
182+
183+ - (void )testLogOut {
184+ id mock = OCMClassMock ([Instabug class ]);
185+
186+ OCMStub ([mock logOut ]);
187+ [self .instabugBridge logOut ];
188+ OCMVerify ([mock logOut ]);
189+ }
190+
191+ - (void )testLogUserEventWithName {
192+ id mock = OCMClassMock ([Instabug class ]);
193+ NSString *name = @" event name" ;
194+
195+ OCMStub ([mock logUserEventWithName: name]);
196+ [self .instabugBridge logUserEventWithName: name];
197+ OCMVerify ([mock logUserEventWithName: name]);
198+ }
199+
200+ - (void )testSetReproStepsMode {
201+ id mock = OCMClassMock ([Instabug class ]);
202+ IBGUserStepsMode reproStepsMode = IBGUserStepsModeEnabledWithNoScreenshots;
203+
204+ OCMStub ([mock setReproStepsMode: reproStepsMode]);
205+ [self .instabugBridge setReproStepsMode: reproStepsMode];
206+ OCMVerify ([mock setReproStepsMode: reproStepsMode]);
207+ }
208+
209+ - (void )testSetUserAttribute {
210+ id mock = OCMClassMock ([Instabug class ]);
211+ NSString *key = @" key" ;
212+ NSString *value = @" value" ;
213+
214+ OCMStub ([mock setUserAttribute: value withKey: key]);
215+ [self .instabugBridge setUserAttribute: key withValue: value];
216+ OCMVerify ([mock setUserAttribute: value withKey: key]);
217+ }
218+
219+ - (void )testGetUserAttribute {
220+ id mock = OCMClassMock ([Instabug class ]);
221+ NSString *key = @" someKey" ;
222+ RCTResponseSenderBlock callbackBlock = ^void (NSArray *response) {};
223+
224+ OCMStub ([mock userAttributeForKey: key]).andReturn (@" someValue" );
225+ [self .instabugBridge getUserAttribute: key callback: callbackBlock];
226+ OCMVerify ([mock userAttributeForKey: key]);
227+ }
228+
229+ - (void )testRemoveUserAttribute {
230+ id mock = OCMClassMock ([Instabug class ]);
231+ NSString *key = @" someKey" ;
232+
233+ OCMStub ([mock removeUserAttributeForKey: key]);
234+ [self .instabugBridge removeUserAttribute: key];
235+ OCMVerify ([mock removeUserAttributeForKey: key]);
236+ }
237+
238+ - (void )testGetAllUserAttributes {
239+ id mock = OCMClassMock ([Instabug class ]);
240+ RCTResponseSenderBlock callbackBlock = ^void (NSArray *response) {};
241+ NSDictionary *dictionary = @{ @" someKey" : @" someValue" };
242+
243+ OCMStub ([mock userAttributes ]).andReturn (dictionary);
244+ [self .instabugBridge getAllUserAttributes: callbackBlock];
245+ OCMVerify ([mock userAttributes ]);
246+ }
247+
248+ - (void )testClearAllUserAttributes {
249+ id mock = OCMClassMock ([Instabug class ]);
250+ NSString *key = @" someKey" ;
251+ NSDictionary *dictionary = @{ @" someKey" : @" someValue" };
252+
253+ OCMStub ([mock userAttributes ]).andReturn (dictionary);
254+ OCMStub ([mock removeUserAttributeForKey: key]);
255+ [self .instabugBridge clearAllUserAttributes ];
256+ OCMVerify ([mock removeUserAttributeForKey: key]);
257+ }
258+
259+ - (void )testShowWelcomeMessageWithMode {
260+ id mock = OCMClassMock ([Instabug class ]);
261+ IBGWelcomeMessageMode welcomeMessageMode = IBGWelcomeMessageModeBeta;
262+
263+ OCMStub ([mock showWelcomeMessageWithMode: welcomeMessageMode]);
264+ [self .instabugBridge showWelcomeMessageWithMode: welcomeMessageMode];
265+ OCMVerify ([mock showWelcomeMessageWithMode: welcomeMessageMode]);
266+ }
267+
268+ - (void )testSetWelcomeMessageMode {
269+ id mock = OCMClassMock ([Instabug class ]);
270+ IBGWelcomeMessageMode welcomeMessageMode = IBGWelcomeMessageModeBeta;
271+
272+ OCMStub ([mock setWelcomeMessageMode: welcomeMessageMode]);
273+ [self .instabugBridge setWelcomeMessageMode: welcomeMessageMode];
274+ OCMVerify ([mock setWelcomeMessageMode: welcomeMessageMode]);
275+ }
276+
277+ - (void )testSetFileAttachment {
278+ id mock = OCMClassMock ([Instabug class ]);
279+ NSString *fileLocation = @" test" ;
280+ NSURL *url = [NSURL URLWithString: fileLocation];
281+
282+ OCMStub ([mock addFileAttachmentWithURL: url]);
283+ [self .instabugBridge setFileAttachment: fileLocation];
284+ OCMVerify ([mock addFileAttachmentWithURL: url]);
285+ }
286+
287+ - (void )testShow {
288+ id mock = OCMClassMock ([Instabug class ]);
289+
290+ OCMStub ([mock show ]);
291+ [self .instabugBridge show ];
292+
293+ XCTestExpectation *expectation = [self expectationWithDescription: @" Testing [Instabug show]" ];
294+
295+ [[NSRunLoop mainRunLoop ] performBlock: ^{
296+ OCMVerify ([mock show ]);
297+ [expectation fulfill ];
298+ }];
299+
300+ [self waitForExpectationsWithTimeout: EXPECTATION_TIMEOUT handler: nil ];
301+ }
302+
303+ /*
304+ +------------------------------------------------------------------------+
305+ | Surveys Module |
306+ +------------------------------------------------------------------------+
307+ */
308+
27309- (void )testShowingSurveyWithToken {
28- NSString *token = @" token" ;
29310 id mock = OCMClassMock ([IBGSurveys class ]);
311+ NSString *token = @" token" ;
30312
31313 OCMStub ([mock showSurveyWithToken: token]);
32314 [self .instabugBridge showSurveyWithToken: token];
33315 OCMVerify ([mock showSurveyWithToken: token]);
34316}
35317
36-
37- /* **********Bug Reporting*****************/
318+ /*
319+ +------------------------------------------------------------------------+
320+ | Bug Reporting Module |
321+ +------------------------------------------------------------------------+
322+ */
38323
39324- (void ) testgivenBoolean $setBugReportingEnabled_whenQuery_thenShouldCallNativeApi {
40325 BOOL enabled = false ;
0 commit comments