10
10
#import " Instabug/Instabug.h"
11
11
#import " Instabug/IBGSurvey.h"
12
12
#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
13
25
14
26
@interface InstabugSampleTests : XCTestCase
15
- @property InstabugReactBridge *instabugBridge;
27
+ @property ( nonatomic , retain ) InstabugReactBridge *instabugBridge;
16
28
@end
17
29
18
30
@implementation InstabugSampleTests
@@ -24,17 +36,290 @@ - (void)setUp {
24
36
self.instabugBridge = [[InstabugReactBridge alloc ] init ];
25
37
}
26
38
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 =
@" [email protected] " ;
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
+
27
309
- (void )testShowingSurveyWithToken {
28
- NSString *token = @" token" ;
29
310
id mock = OCMClassMock ([IBGSurveys class ]);
311
+ NSString *token = @" token" ;
30
312
31
313
OCMStub ([mock showSurveyWithToken: token]);
32
314
[self .instabugBridge showSurveyWithToken: token];
33
315
OCMVerify ([mock showSurveyWithToken: token]);
34
316
}
35
317
36
-
37
- /* **********Bug Reporting*****************/
318
+ /*
319
+ +------------------------------------------------------------------------+
320
+ | Bug Reporting Module |
321
+ +------------------------------------------------------------------------+
322
+ */
38
323
39
324
- (void ) testgivenBoolean $setBugReportingEnabled_whenQuery_thenShouldCallNativeApi {
40
325
BOOL enabled = false ;
0 commit comments