8
8
import com .facebook .react .bridge .ReactApplicationContext ;
9
9
import com .facebook .react .bridge .WritableMap ;
10
10
import com .instabug .bug .BugReporting ;
11
+ import com .instabug .bug .ProactiveReportingConfigs ;
11
12
import com .instabug .library .Feature ;
12
13
import com .instabug .library .OnSdkDismissCallback ;
13
14
import com .instabug .library .extendedbugreport .ExtendedBugReport ;
21
22
import org .junit .After ;
22
23
import org .junit .Before ;
23
24
import org .junit .Test ;
25
+ import org .mockito .ArgumentCaptor ;
24
26
import org .mockito .MockedStatic ;
25
27
import org .mockito .internal .verification .VerificationModeFactory ;
26
28
import org .mockito .invocation .InvocationOnMock ;
30
32
import java .util .concurrent .Executors ;
31
33
import java .util .concurrent .ScheduledExecutorService ;
32
34
35
+ import static org .junit .Assert .assertEquals ;
36
+ import static org .junit .Assert .assertTrue ;
33
37
import static org .mockito .ArgumentMatchers .any ;
38
+ import static org .mockito .ArgumentMatchers .argThat ;
34
39
import static org .mockito .Mockito .doAnswer ;
35
40
import static org .mockito .Mockito .mock ;
36
41
import static org .mockito .Mockito .mockStatic ;
@@ -45,9 +50,9 @@ public class RNInstabugBugReportingModuleTest {
45
50
46
51
// Mock Objects
47
52
private MockedStatic <Looper > mockLooper ;
48
- private MockedStatic <MainThreadHandler > mockMainThreadHandler ;
49
- private MockedStatic <BugReporting > mockBugReporting ;
50
- private MockedStatic <InstabugUtil > mockInstabugUtil ;
53
+ private MockedStatic <MainThreadHandler > mockMainThreadHandler ;
54
+ private MockedStatic <BugReporting > mockBugReporting ;
55
+ private MockedStatic <InstabugUtil > mockInstabugUtil ;
51
56
52
57
@ Before
53
58
public void mockMainThreadHandler () throws Exception {
@@ -72,6 +77,7 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
72
77
doAnswer (handlerPostAnswer ).when (MainThreadHandler .class );
73
78
MainThreadHandler .runOnMainThread (any (Runnable .class ));
74
79
}
80
+
75
81
@ After
76
82
public void tearDown () {
77
83
// Remove static mocks
@@ -91,7 +97,7 @@ public void tearDown() {
91
97
// when
92
98
bugReportingModule .setShakingThresholdForAndroid (shakingThreshold );
93
99
// then
94
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
100
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
95
101
BugReporting .setShakingThreshold (shakingThreshold );
96
102
}
97
103
@@ -102,7 +108,7 @@ public void tearDown() {
102
108
// when
103
109
bugReportingModule .setEnabled (false );
104
110
// then
105
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
111
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
106
112
107
113
BugReporting .setState (Feature .State .DISABLED );
108
114
}
@@ -114,7 +120,7 @@ public void tearDown() {
114
120
// when
115
121
bugReportingModule .setEnabled (true );
116
122
// then
117
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
123
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
118
124
119
125
BugReporting .setState (Feature .State .ENABLED );
120
126
}
@@ -126,7 +132,7 @@ public void tearDown() {
126
132
// when
127
133
bugReportingModule .setAutoScreenRecordingEnabled (true );
128
134
// then
129
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
135
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
130
136
131
137
BugReporting .setAutoScreenRecordingEnabled (true );
132
138
}
@@ -138,7 +144,7 @@ public void tearDown() {
138
144
// when
139
145
bugReportingModule .setViewHierarchyEnabled (true );
140
146
// then
141
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
147
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
142
148
143
149
BugReporting .setViewHierarchyState (Feature .State .ENABLED );
144
150
}
@@ -150,7 +156,7 @@ public void tearDown() {
150
156
// when
151
157
bugReportingModule .setViewHierarchyEnabled (false );
152
158
// then
153
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
159
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
154
160
155
161
BugReporting .setViewHierarchyState (Feature .State .DISABLED );
156
162
}
@@ -162,7 +168,7 @@ public void tearDown() {
162
168
// when
163
169
bugReportingModule .setEnabledAttachmentTypes (true , true , false , true );
164
170
// then
165
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
171
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
166
172
167
173
BugReporting .setAttachmentTypesEnabled (true , true , false , true );
168
174
}
@@ -179,7 +185,7 @@ public void tearDown() {
179
185
180
186
// then
181
187
for (ExtendedBugReport .State extendedBugReportMode : args .values ()) {
182
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
188
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
183
189
BugReporting .setExtendedBugReportState (extendedBugReportMode );
184
190
}
185
191
}
@@ -198,7 +204,7 @@ public void tearDown() {
198
204
bugReportingModule .setInvocationEvents (actualArray );
199
205
200
206
// then
201
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
207
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
202
208
BugReporting .setInvocationEvents (args .values ().toArray (new InstabugInvocationEvent [0 ]));
203
209
}
204
210
@@ -215,11 +221,11 @@ public void tearDown() {
215
221
bugReportingModule .setOptions (actualArray );
216
222
217
223
// then
218
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
224
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
219
225
int option1 = args .get (keysArray [0 ]);
220
226
int option2 = args .get (keysArray [1 ]);
221
227
BugReporting .setOptions (option1 );
222
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
228
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
223
229
BugReporting .setOptions (option2 );
224
230
}
225
231
@@ -255,7 +261,8 @@ public Object answer(InvocationOnMock invocation) {
255
261
((OnSdkDismissCallback ) invocation .getArguments ()[0 ])
256
262
.call (OnSdkDismissCallback .DismissType .CANCEL , OnSdkDismissCallback .ReportType .BUG );
257
263
return null ;
258
- }});
264
+ }
265
+ });
259
266
bugReportingModule .setOnSDKDismissedHandler (null );
260
267
261
268
// then
@@ -280,7 +287,7 @@ public Object answer(InvocationOnMock invocation) {
280
287
bugReportingModule .setReportTypes (actualArray );
281
288
282
289
// then
283
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
290
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
284
291
285
292
int type1 = args .get (keysArray [0 ]);
286
293
int type2 = args .get (keysArray [1 ]);
@@ -295,9 +302,9 @@ public Object answer(InvocationOnMock invocation) {
295
302
296
303
// when
297
304
bugReportingModule .setVideoRecordingFloatingButtonPosition (keysArray [0 ]);
298
-
305
+
299
306
// then
300
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
307
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
301
308
InstabugVideoRecordingButtonPosition position = (InstabugVideoRecordingButtonPosition ) args .get (keysArray [0 ]);
302
309
BugReporting .setVideoRecordingFloatingButtonPosition (position );
303
310
}
@@ -319,13 +326,13 @@ public Object answer(InvocationOnMock invocation) {
319
326
// then
320
327
int option1 = optionsArgs .get (keysArray [0 ]);
321
328
int option2 = optionsArgs .get (keysArray [1 ]);
322
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
329
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
323
330
324
331
BugReporting .setOptions (option1 );
325
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
332
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
326
333
327
334
BugReporting .setOptions (option2 );
328
- verify (BugReporting .class ,VerificationModeFactory .times (1 ));
335
+ verify (BugReporting .class , VerificationModeFactory .times (1 ));
329
336
330
337
BugReporting .show (reportTypeArgs .get (reportTypeKeys [0 ]));
331
338
}
@@ -359,7 +366,27 @@ public Object answer(InvocationOnMock invocation) {
359
366
// then
360
367
verify (BugReporting .class , VerificationModeFactory .times (1 ));
361
368
int type1 = args .get (keysArray [0 ]);
362
-
369
+
363
370
BugReporting .setCommentMinimumCharacterCount (count , type1 );
364
371
}
372
+
373
+ @ Test
374
+ public void testSetProactiveReportingConfigurations () {
375
+ // given
376
+ boolean enabled = true ;
377
+ int gapBetweekDialogs = 20 ;
378
+ int modeDelay = 30 ;
379
+
380
+ // when
381
+ bugReportingModule .setProactiveReportingConfigurations (enabled , gapBetweekDialogs , modeDelay );
382
+
383
+ // then
384
+ mockBugReporting .verify (() -> BugReporting .setProactiveReportingConfigurations (argThat (config ->
385
+ config .getModalsGap () == gapBetweekDialogs &&
386
+ config .getDetectionGap () == modeDelay &&
387
+ config .isEnabled () == enabled
388
+ )));
389
+
390
+
391
+ }
365
392
}
0 commit comments