Skip to content

Commit b7ece9e

Browse files
authored
[MOB-8360] Add Expirements APIs (#219)
* Add Experiments APIs (Flutter) * Add Experiments APIs (Android) * Add Experiments APIs (iOS) * Update Changelog * Add Experiments APIs tests
1 parent 51f1368 commit b7ece9e

File tree

9 files changed

+236
-0
lines changed

9 files changed

+236
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## master
22

33
* Fixes iOS platform calls not completing with `void` return type
4+
* Adds Experiments APIs.
45

56
## v10.11.0 (2022-01-04)
67

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,31 @@ public ArrayList<String> getTags() {
303303
return Instabug.getTags();
304304
}
305305

306+
/**
307+
* Adds experiments to the next report.
308+
*
309+
* @param experiments An array of experiments to add.
310+
*/
311+
public void addExperiments(ArrayList<String> experiments) {
312+
Instabug.addExperiments(experiments);
313+
}
314+
315+
/**
316+
* Removes certain experiments from the next report.
317+
*
318+
* @param experiments An array of experiments to remove.
319+
*/
320+
public void removeExperiments(ArrayList<String> experiments) {
321+
Instabug.removeExperiments(experiments);
322+
}
323+
324+
/**
325+
* Clears all experiments from the next report.
326+
*/
327+
public void clearAllExperiments() {
328+
Instabug.clearAllExperiments();
329+
}
330+
306331
/**
307332
* Set custom user attributes that are going to be sent with each feedback, bug
308333
* or crash.

example/android/app/src/main/kotlin/com/example/InstabugSample/OnMethodCallTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,37 @@ public void testAppendTags() {
7777
verify(instabugMock).appendTags(tags);
7878
}
7979

80+
public void testAddExperiments() {
81+
String methodName = "addExperiments";
82+
ArrayList<Object> argsList = new ArrayList<>();
83+
ArrayList<String> experiments = new ArrayList<>();
84+
experiments.add("exp1");
85+
experiments.add("exp2");
86+
argsList.add(experiments);
87+
Mockito.doNothing().when(instabugMock).addExperiments(any(ArrayList.class));
88+
testMethodCall(methodName, argsList);
89+
verify(instabugMock).addExperiments(experiments);
90+
}
91+
92+
public void testRemoveExperiments() {
93+
String methodName = "removeExperiments";
94+
ArrayList<Object> argsList = new ArrayList<>();
95+
ArrayList<String> experiments = new ArrayList<>();
96+
experiments.add("exp1");
97+
experiments.add("exp2");
98+
argsList.add(experiments);
99+
Mockito.doNothing().when(instabugMock).removeExperiments(any(ArrayList.class));
100+
testMethodCall(methodName, argsList);
101+
verify(instabugMock).removeExperiments(experiments);
102+
}
103+
104+
public void testClearAllExperiments() {
105+
String methodName = "clearAllExperiments";
106+
Mockito.doNothing().when(instabugMock).clearAllExperiments();
107+
testMethodCall(methodName, null);
108+
verify(instabugMock).clearAllExperiments();
109+
}
110+
80111
public void testShowBugReportingWithReportTypeAndOptions() {
81112
String methodName = "showBugReportingWithReportTypeAndOptions";
82113
ArrayList<Object> argsList = new ArrayList<>();

example/android/app/src/test/java/com/example/InstabugSample/InstabugFlutterPluginTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ public void testAppendTags() {
4141
new OnMethodCallTests().testAppendTags();
4242
}
4343

44+
/**
45+
* (ArrayList<String>)
46+
*/
47+
@Test
48+
public void testAddExperiments() {
49+
new OnMethodCallTests().testAddExperiments();
50+
}
51+
52+
/**
53+
* (ArrayList<String>)
54+
*/
55+
@Test
56+
public void testRemoveExperiments() {
57+
new OnMethodCallTests().testRemoveExperiments();
58+
}
59+
60+
/**
61+
* ()
62+
*/
63+
@Test
64+
public void testClearAllExperiments() {
65+
new OnMethodCallTests().testClearAllExperiments();
66+
}
67+
4468
/**
4569
* (String, ArrayList<String>)
4670
*/

example/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,61 @@ - (void)testAppendTags {
8989
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
9090
}
9191

92+
- (void)testAddExperiments {
93+
id mock = OCMClassMock([InstabugFlutterPlugin class]);
94+
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];
95+
96+
NSArray *experiments = [NSArray arrayWithObjects:@"exp1", @"exp2", nil];
97+
NSArray *arguments = [NSArray arrayWithObjects: experiments, nil];
98+
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"addExperiments:" arguments:arguments];
99+
[[[mock stub] classMethod] addExperiments:experiments];
100+
101+
XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
102+
[instabug handleMethodCall:call result:^(id _Nullable result) {
103+
XCTAssertNil(result);
104+
[expectation fulfill];
105+
}];
106+
107+
[[[mock verify] classMethod] addExperiments:experiments];
108+
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
109+
}
110+
111+
- (void)testRemoveExperiments {
112+
id mock = OCMClassMock([InstabugFlutterPlugin class]);
113+
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];
114+
115+
NSArray *experiments = [NSArray arrayWithObjects:@"exp1", @"exp2", nil];
116+
NSArray *arguments = [NSArray arrayWithObjects: experiments, nil];
117+
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"removeExperiments:" arguments:arguments];
118+
[[[mock stub] classMethod] removeExperiments:experiments];
119+
120+
XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
121+
[instabug handleMethodCall:call result:^(id _Nullable result) {
122+
XCTAssertNil(result);
123+
[expectation fulfill];
124+
}];
125+
126+
[[[mock verify] classMethod] removeExperiments:experiments];
127+
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
128+
}
129+
130+
- (void)testClearAllExperiments {
131+
id mock = OCMClassMock([InstabugFlutterPlugin class]);
132+
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];
133+
134+
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"clearAllExperiments" arguments:NULL];
135+
[[[mock stub] classMethod] clearAllExperiments];
136+
137+
XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
138+
[instabug handleMethodCall:call result:^(id _Nullable result) {
139+
XCTAssertNil(result);
140+
[expectation fulfill];
141+
}];
142+
143+
[[[mock verify] classMethod] clearAllExperiments];
144+
[self waitForExpectationsWithTimeout:kTimeout handler:nil];
145+
}
146+
92147
- (void)testShowBugReportingWithReportTypeAndOptions {
93148
id mock = OCMClassMock([InstabugFlutterPlugin class]);
94149
InstabugFlutterPlugin *instabug = [[InstabugFlutterPlugin alloc] init];

ios/Classes/InstabugFlutterPlugin.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@
119119
*/
120120
+ (NSArray *)getTags;
121121

122+
/**
123+
* Adds experiments to the next report.
124+
* @param experiments An array of experiments to add.
125+
*/
126+
+ (void)addExperiments:(NSArray *)experiments;
127+
128+
/**
129+
* Removes certain experiments from the next report.
130+
* @param experiments An array of experiments to remove.
131+
*/
132+
+ (void)removeExperiments:(NSArray *)experiments;
133+
134+
/**
135+
* Clears all experiments from the next report.
136+
*/
137+
+ (void)clearAllExperiments;
138+
122139
/**
123140
* Set custom user attributes that are going to be sent with each feedback, bug or crash.
124141
* @param value User attribute value.

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@ + (NSArray*)getTags {
235235
return [Instabug getTags];
236236
}
237237

238+
/**
239+
* Adds experiments to the next report.
240+
* @param experiments An array of experiments to add.
241+
*/
242+
+ (void)addExperiments:(NSArray *)experiments {
243+
[Instabug addExperiments:experiments];
244+
}
245+
246+
/**
247+
* Removes certain experiments from the next report.
248+
* @param experiments An array of experiments to remove.
249+
*/
250+
+ (void)removeExperiments:(NSArray *)experiments {
251+
[Instabug removeExperiments:experiments];
252+
}
253+
254+
/**
255+
* Clears all experiments from the next report.
256+
*/
257+
+ (void)clearAllExperiments {
258+
[Instabug clearAllExperiments];
259+
}
260+
238261
/**
239262
* Set custom user attributes that are going to be sent with each feedback, bug or crash.
240263
* @param value User attribute value.

lib/Instabug.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ class Instabug {
178178
return tags?.cast<String>();
179179
}
180180

181+
/// Adds experiments to the next report.
182+
static Future<void> addExperiments(List<String> experiments) async {
183+
final params = <dynamic>[experiments];
184+
await _channel.invokeMethod<Object>('addExperiments:', params);
185+
}
186+
187+
/// Removes certain experiments from the next report.
188+
static Future<void> removeExperiments(List<String> experiments) async {
189+
final params = <dynamic>[experiments];
190+
await _channel.invokeMethod<Object>('removeExperiments:', params);
191+
}
192+
193+
/// Clears all experiments from the next report.
194+
static Future<void> clearAllExperiments() async {
195+
await _channel.invokeMethod<Object>('clearAllExperiments');
196+
}
197+
181198
/// Add custom user attribute [value] with a [key] that is going to be sent with each feedback, bug or crash.
182199
static Future<void> setUserAttribute(String value, String key) async {
183200
final List<dynamic> params = <dynamic>[value, key];

test/instabug_flutter_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,49 @@ void main() {
280280
expect(tags, ['tag1', 'tag2']);
281281
});
282282

283+
test(
284+
'test addExperiments should be called with argument List of strings',
285+
() async {
286+
const experiments = ['exp1', 'exp2'];
287+
Instabug.addExperiments(experiments);
288+
final args = <dynamic>[experiments];
289+
expect(log, <Matcher>[
290+
isMethodCall(
291+
'addExperiments:',
292+
arguments: args,
293+
)
294+
]);
295+
},
296+
);
297+
298+
test(
299+
'test removeExperiments should be called with argument List of strings',
300+
() async {
301+
const experiments = ['exp1', 'exp2'];
302+
Instabug.removeExperiments(experiments);
303+
final args = <dynamic>[experiments];
304+
expect(log, <Matcher>[
305+
isMethodCall(
306+
'removeExperiments:',
307+
arguments: args,
308+
)
309+
]);
310+
},
311+
);
312+
313+
test(
314+
'test clearAllExperiments should be called with no arguments',
315+
() async {
316+
Instabug.clearAllExperiments();
317+
expect(log, <Matcher>[
318+
isMethodCall(
319+
'clearAllExperiments',
320+
arguments: null,
321+
)
322+
]);
323+
},
324+
);
325+
283326
test(
284327
'test setUserAttributeWithKey should be called with two string arguments',
285328
() async {

0 commit comments

Comments
 (0)