Skip to content

Commit 5d6b174

Browse files
a7medevHeshamMegid
authored andcommitted
feat: add new repro steps api (#388)
Jira ID: MOB-13005
1 parent fde6c3d commit 5d6b174

File tree

13 files changed

+184
-6
lines changed

13 files changed

+184
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
- Add network logs obfuscation support using the new `NetworkLogger.obfuscateLog` API ([#380](https://github.com/Instabug/Instabug-Flutter/pull/380)).
88
- Add network logs omission support using the new `NetworkLogger.omitLog` API ([#382](https://github.com/Instabug/Instabug-Flutter/pull/382)).
9+
- Add the new repro steps configuration API `Instabug.setReproStepsConfig` ([#388](https://github.com/Instabug/Instabug-Flutter/pull/388)).
910

1011
### Changed
1112

1213
- Bump Instabug Android SDK to v11.14.0 ([#384](https://github.com/Instabug/Instabug-Flutter/pull/384)). [See release notes](https://github.com/Instabug/Instabug-Android/releases/tag/v11.14.0).
1314
- Bump Instabug iOS SDK to v11.14.0 ([#383](https://github.com/Instabug/Instabug-Flutter/pull/383)). [See release notes](https://github.com/Instabug/Instabug-iOS/releases/tag/11.14.0).
1415

16+
### Deprecated
17+
18+
- Deprecate `Instabug.setReproStepsMode` in favor of the new `Instabug.setReproStepsConfig` ([#388](https://github.com/Instabug/Instabug-Flutter/pull/388)).
19+
1520
## [11.13.0](https://github.com/Instabug/Instabug-Flutter/compare/v11.12.0...v11.13.0) (July 10, 2023)
1621

1722
### Changed

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import com.instabug.library.Instabug;
2020
import com.instabug.library.InstabugColorTheme;
2121
import com.instabug.library.InstabugCustomTextPlaceHolder;
22+
import com.instabug.library.IssueType;
2223
import com.instabug.library.Platform;
24+
import com.instabug.library.ReproConfigurations;
2325
import com.instabug.library.internal.module.InstabugLocale;
2426
import com.instabug.library.invocation.InstabugInvocationEvent;
2527
import com.instabug.library.model.NetworkLog;
@@ -283,7 +285,9 @@ public void setSdkDebugLogsLevel(@NonNull String level) {
283285
// iOS Only
284286
}
285287

288+
@SuppressWarnings("deprecation")
286289
@Override
290+
@Deprecated()
287291
public void setReproStepsMode(@NonNull String mode) {
288292
try {
289293
final State resolvedMode = ArgsRegistry.reproStates.get(mode);
@@ -293,6 +297,29 @@ public void setReproStepsMode(@NonNull String mode) {
293297
}
294298
}
295299

300+
@Override
301+
public void setReproStepsConfig(@Nullable String bugMode, @Nullable String crashMode) {
302+
try {
303+
final ReproConfigurations.Builder builder = new ReproConfigurations.Builder();
304+
305+
if (bugMode != null) {
306+
final Integer resolvedBugMode = ArgsRegistry.reproModes.get(bugMode);
307+
builder.setIssueMode(IssueType.Bug, resolvedBugMode);
308+
}
309+
310+
if (crashMode != null) {
311+
final Integer resolvedCrashMode = ArgsRegistry.reproModes.get(crashMode);
312+
builder.setIssueMode(IssueType.Crash, resolvedCrashMode);
313+
}
314+
315+
final ReproConfigurations config = builder.build();
316+
317+
Instabug.setReproConfigurations(config);
318+
} catch (Exception e) {
319+
e.printStackTrace();
320+
}
321+
}
322+
296323
@Override
297324
public void reportScreenChange(@NonNull String screenName) {
298325
try {

android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.instabug.library.InstabugColorTheme;
1010
import com.instabug.library.InstabugCustomTextPlaceHolder.Key;
1111
import com.instabug.library.OnSdkDismissCallback.DismissType;
12+
import com.instabug.library.ReproMode;
1213
import com.instabug.library.extendedbugreport.ExtendedBugReport;
1314
import com.instabug.library.internal.module.InstabugLocale;
1415
import com.instabug.library.invocation.InstabugInvocationEvent;
@@ -111,12 +112,19 @@ public T get(Object key) {
111112
put("ExtendedBugReportMode.disabled", ExtendedBugReport.State.DISABLED);
112113
}};
113114

115+
@Deprecated()
114116
public static final ArgsMap<State> reproStates = new ArgsMap<State>() {{
115117
put("ReproStepsMode.enabledWithNoScreenshots", State.ENABLED_WITH_NO_SCREENSHOTS);
116118
put("ReproStepsMode.enabled", State.ENABLED);
117119
put("ReproStepsMode.disabled", State.DISABLED);
118120
}};
119121

122+
public static final ArgsMap<Integer> reproModes = new ArgsMap<Integer>() {{
123+
put("ReproStepsMode.enabledWithNoScreenshots", ReproMode.EnableWithNoScreenshots);
124+
put("ReproStepsMode.enabled", ReproMode.EnableWithScreenshots);
125+
put("ReproStepsMode.disabled", ReproMode.Disable);
126+
}};
127+
120128
public static final ArgsMap<InstabugLocale> locales = new ArgsMap<InstabugLocale>() {{
121129
put("IBGLocale.arabic", InstabugLocale.ARABIC);
122130
put("IBGLocale.azerbaijani", InstabugLocale.AZERBAIJANI);
@@ -214,4 +222,4 @@ public T get(Object key) {
214222
put("CustomTextPlaceHolderKey.messagesNotificationAndOthers", Key.CHATS_MULTIPLE_MESSAGE_NOTIFICATION);
215223
put("CustomTextPlaceHolderKey.insufficientContentMessage", Key.COMMENT_FIELD_INSUFFICIENT_CONTENT);
216224
}};
217-
}
225+
}

android/src/test/java/com/instabug/flutter/ArgsRegistryTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.instabug.library.InstabugColorTheme;
1111
import com.instabug.library.InstabugCustomTextPlaceHolder.Key;
1212
import com.instabug.library.OnSdkDismissCallback.DismissType;
13+
import com.instabug.library.ReproMode;
1314
import com.instabug.library.extendedbugreport.ExtendedBugReport;
1415
import com.instabug.library.internal.module.InstabugLocale;
1516
import com.instabug.library.invocation.InstabugInvocationEvent;
@@ -183,6 +184,7 @@ public void testExtendedBugReportStates() {
183184
}
184185

185186

187+
@SuppressWarnings("deprecation")
186188
@Test
187189
public void testReproStates() {
188190
State[] values = {
@@ -196,6 +198,19 @@ public void testReproStates() {
196198
}
197199
}
198200

201+
@Test
202+
public void testReproModes() {
203+
Integer[] values = {
204+
ReproMode.Disable,
205+
ReproMode.EnableWithScreenshots,
206+
ReproMode.EnableWithNoScreenshots,
207+
};
208+
209+
for (Integer value : values) {
210+
assertTrue(ArgsRegistry.reproModes.containsValue(value));
211+
}
212+
}
213+
199214

200215
@Test
201216
public void testLocales() {

android/src/test/java/com/instabug/flutter/InstabugApiTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.mockito.ArgumentMatchers.any;
88
import static org.mockito.ArgumentMatchers.anyInt;
99
import static org.mockito.ArgumentMatchers.anyString;
10+
import static org.mockito.ArgumentMatchers.argThat;
1011
import static org.mockito.ArgumentMatchers.eq;
1112
import static org.mockito.Mockito.doReturn;
1213
import static org.mockito.Mockito.mock;
@@ -30,8 +31,11 @@
3031
import com.instabug.library.Instabug;
3132
import com.instabug.library.InstabugColorTheme;
3233
import com.instabug.library.InstabugCustomTextPlaceHolder;
34+
import com.instabug.library.IssueType;
3335
import com.instabug.library.LogLevel;
3436
import com.instabug.library.Platform;
37+
import com.instabug.library.ReproConfigurations;
38+
import com.instabug.library.ReproMode;
3539
import com.instabug.library.invocation.InstabugInvocationEvent;
3640
import com.instabug.library.model.NetworkLog;
3741
import com.instabug.library.ui.onboarding.WelcomeMessage;
@@ -383,6 +387,7 @@ public void testSetDebugEnabled() {
383387
mInstabug.verify(() -> Instabug.setDebugEnabled(isEnabled));
384388
}
385389

390+
@SuppressWarnings("deprecation")
386391
@Test
387392
public void testSetReproStepsMode() {
388393
String mode = "ReproStepsMode.enabled";
@@ -392,6 +397,28 @@ public void testSetReproStepsMode() {
392397
mInstabug.verify(() -> Instabug.setReproStepsState(State.ENABLED));
393398
}
394399

400+
@Test
401+
public void testSetReproStepsConfig() {
402+
String bug = "ReproStepsMode.enabled";
403+
String crash = "ReproStepsMode.disabled";
404+
405+
ReproConfigurations config = mock(ReproConfigurations.class);
406+
MockedConstruction<ReproConfigurations.Builder> mReproConfigurationsBuilder = mockConstruction(ReproConfigurations.Builder.class, (mock, context) -> {
407+
when(mock.setIssueMode(anyInt(), anyInt())).thenReturn(mock);
408+
when(mock.build()).thenReturn(config);
409+
});
410+
411+
api.setReproStepsConfig(bug, crash);
412+
413+
ReproConfigurations.Builder builder = mReproConfigurationsBuilder.constructed().get(0);
414+
415+
verify(builder).setIssueMode(IssueType.Bug, ReproMode.EnableWithScreenshots);
416+
verify(builder).setIssueMode(IssueType.Crash, ReproMode.Disable);
417+
verify(builder).build();
418+
419+
mInstabug.verify(() -> Instabug.setReproConfigurations(config));
420+
}
421+
395422
@Test
396423
public void testReportScreenChange() {
397424
String screenName = "HomeScreen";

example/ios/InstabugTests/ArgsRegistryTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ - (void)testExtendedBugReportStates {
157157
}
158158
}
159159

160-
- (void)testReproStates {
160+
- (void)testReproModes {
161161
NSArray *values = @[
162162
@(IBGUserStepsModeEnable),
163163
@(IBGUserStepsModeDisable),
164164
@(IBGUserStepsModeEnabledWithNoScreenshots)
165165
];
166166

167167
for (NSNumber *value in values) {
168-
XCTAssertTrue([[ArgsRegistry.reproStates allValues] containsObject:value]);
168+
XCTAssertTrue([[ArgsRegistry.reproModes allValues] containsObject:value]);
169169
}
170170
}
171171

example/ios/InstabugTests/InstabugApiTests.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,17 @@ - (void)testSetReproStepsMode {
300300
OCMVerify([self.mInstabug setReproStepsMode:IBGUserStepsModeEnable]);
301301
}
302302

303+
- (void)testSetReproStepsConfig {
304+
NSString *bugMode = @"ReproStepsMode.enabled";
305+
NSString *crashMode = @"ReproStepsMode.disabled";
306+
FlutterError *error;
307+
308+
[self.api setReproStepsConfigBugMode:bugMode crashMode:crashMode error:&error];
309+
310+
OCMVerify([self.mInstabug setReproStepsFor:IBGIssueTypeBug withMode:IBGUserStepsModeEnable]);
311+
OCMVerify([self.mInstabug setReproStepsFor:IBGIssueTypeCrash withMode:IBGUserStepsModeDisable]);
312+
}
313+
303314
- (void)testReportScreenChange {
304315
NSString *screenName = @"HomeScreen";
305316
FlutterError *error;

ios/Classes/Modules/InstabugApi.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,22 @@ - (void)setSdkDebugLogsLevelLevel:(NSString *)level error:(FlutterError *_Nullab
159159
}
160160

161161
- (void)setReproStepsModeMode:(NSString *)mode error:(FlutterError *_Nullable *_Nonnull)error {
162-
IBGUserStepsMode resolvedMode = (ArgsRegistry.reproStates[mode]).integerValue;
162+
IBGUserStepsMode resolvedMode = (ArgsRegistry.reproModes[mode]).integerValue;
163163
[Instabug setReproStepsMode:resolvedMode];
164164
}
165165

166+
- (void)setReproStepsConfigBugMode:(nullable NSString *)bugMode crashMode:(nullable NSString *)crashMode error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
167+
if (bugMode != nil) {
168+
IBGUserStepsMode resolvedBugMode = ArgsRegistry.reproModes[bugMode].integerValue;
169+
[Instabug setReproStepsFor:IBGIssueTypeBug withMode:resolvedBugMode];
170+
}
171+
172+
if (crashMode != nil) {
173+
IBGUserStepsMode resolvedCrashMode = ArgsRegistry.reproModes[crashMode].integerValue;
174+
[Instabug setReproStepsFor:IBGIssueTypeCrash withMode:resolvedCrashMode];
175+
}
176+
}
177+
166178
- (UIImage *)getImageForAsset:(NSString *)assetName {
167179
NSString *key = [FlutterDartProject lookupKeyForAsset:assetName];
168180
NSString *path = [[NSBundle mainBundle] pathForResource:key ofType:nil];

ios/Classes/Util/ArgsRegistry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef NSDictionary<NSString *, NSNumber *> ArgsDictionary;
1717
+ (ArgsDictionary *)dismissTypes;
1818
+ (ArgsDictionary *)actionTypes;
1919
+ (ArgsDictionary *)extendedBugReportStates;
20-
+ (ArgsDictionary *)reproStates;
20+
+ (ArgsDictionary *)reproModes;
2121
+ (ArgsDictionary *)locales;
2222
+ (NSDictionary<NSString *, NSString *> *)placeholders;
2323

ios/Classes/Util/ArgsRegistry.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ + (ArgsDictionary *)extendedBugReportStates {
112112
};
113113
}
114114

115-
+ (ArgsDictionary *)reproStates {
115+
+ (ArgsDictionary *)reproModes {
116116
return @{
117117
@"ReproStepsMode.enabled" : @(IBGUserStepsModeEnable),
118118
@"ReproStepsMode.disabled" : @(IBGUserStepsModeDisable),

0 commit comments

Comments
 (0)