Skip to content

feat: add new repro steps api #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

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

### Changed

- 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).

### Deprecated

- Deprecate `Instabug.setReproStepsMode` in favor of the new `Instabug.setReproStepsConfig` ([#388](https://github.com/Instabug/Instabug-Flutter/pull/388)).

## [11.13.0](https://github.com/Instabug/Instabug-Flutter/compare/v11.12.0...v11.13.0) (July 10, 2023)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder;
import com.instabug.library.IssueType;
import com.instabug.library.Platform;
import com.instabug.library.ReproConfigurations;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.model.NetworkLog;
Expand Down Expand Up @@ -283,7 +285,9 @@ public void setSdkDebugLogsLevel(@NonNull String level) {
// iOS Only
}

@SuppressWarnings("deprecation")
@Override
@Deprecated()
public void setReproStepsMode(@NonNull String mode) {
try {
final State resolvedMode = ArgsRegistry.reproStates.get(mode);
Expand All @@ -293,6 +297,29 @@ public void setReproStepsMode(@NonNull String mode) {
}
}

@Override
public void setReproStepsConfig(@Nullable String bugMode, @Nullable String crashMode) {
try {
final ReproConfigurations.Builder builder = new ReproConfigurations.Builder();

if (bugMode != null) {
final Integer resolvedBugMode = ArgsRegistry.reproModes.get(bugMode);
builder.setIssueMode(IssueType.Bug, resolvedBugMode);
}

if (crashMode != null) {
final Integer resolvedCrashMode = ArgsRegistry.reproModes.get(crashMode);
builder.setIssueMode(IssueType.Crash, resolvedCrashMode);
}

final ReproConfigurations config = builder.build();

Instabug.setReproConfigurations(config);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void reportScreenChange(@NonNull String screenName) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder.Key;
import com.instabug.library.OnSdkDismissCallback.DismissType;
import com.instabug.library.ReproMode;
import com.instabug.library.extendedbugreport.ExtendedBugReport;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
Expand Down Expand Up @@ -111,12 +112,19 @@ public T get(Object key) {
put("ExtendedBugReportMode.disabled", ExtendedBugReport.State.DISABLED);
}};

@Deprecated()
public static final ArgsMap<State> reproStates = new ArgsMap<State>() {{
put("ReproStepsMode.enabledWithNoScreenshots", State.ENABLED_WITH_NO_SCREENSHOTS);
put("ReproStepsMode.enabled", State.ENABLED);
put("ReproStepsMode.disabled", State.DISABLED);
}};

public static final ArgsMap<Integer> reproModes = new ArgsMap<Integer>() {{
put("ReproStepsMode.enabledWithNoScreenshots", ReproMode.EnableWithNoScreenshots);
put("ReproStepsMode.enabled", ReproMode.EnableWithScreenshots);
put("ReproStepsMode.disabled", ReproMode.Disable);
}};

public static final ArgsMap<InstabugLocale> locales = new ArgsMap<InstabugLocale>() {{
put("IBGLocale.arabic", InstabugLocale.ARABIC);
put("IBGLocale.azerbaijani", InstabugLocale.AZERBAIJANI);
Expand Down Expand Up @@ -214,4 +222,4 @@ public T get(Object key) {
put("CustomTextPlaceHolderKey.messagesNotificationAndOthers", Key.CHATS_MULTIPLE_MESSAGE_NOTIFICATION);
put("CustomTextPlaceHolderKey.insufficientContentMessage", Key.COMMENT_FIELD_INSUFFICIENT_CONTENT);
}};
}
}
15 changes: 15 additions & 0 deletions android/src/test/java/com/instabug/flutter/ArgsRegistryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder.Key;
import com.instabug.library.OnSdkDismissCallback.DismissType;
import com.instabug.library.ReproMode;
import com.instabug.library.extendedbugreport.ExtendedBugReport;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.invocation.InstabugInvocationEvent;
Expand Down Expand Up @@ -183,6 +184,7 @@ public void testExtendedBugReportStates() {
}


@SuppressWarnings("deprecation")
@Test
public void testReproStates() {
State[] values = {
Expand All @@ -196,6 +198,19 @@ public void testReproStates() {
}
}

@Test
public void testReproModes() {
Integer[] values = {
ReproMode.Disable,
ReproMode.EnableWithScreenshots,
ReproMode.EnableWithNoScreenshots,
};

for (Integer value : values) {
assertTrue(ArgsRegistry.reproModes.containsValue(value));
}
}


@Test
public void testLocales() {
Expand Down
27 changes: 27 additions & 0 deletions android/src/test/java/com/instabug/flutter/InstabugApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand All @@ -30,8 +31,11 @@
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder;
import com.instabug.library.IssueType;
import com.instabug.library.LogLevel;
import com.instabug.library.Platform;
import com.instabug.library.ReproConfigurations;
import com.instabug.library.ReproMode;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.model.NetworkLog;
import com.instabug.library.ui.onboarding.WelcomeMessage;
Expand Down Expand Up @@ -383,6 +387,7 @@ public void testSetDebugEnabled() {
mInstabug.verify(() -> Instabug.setDebugEnabled(isEnabled));
}

@SuppressWarnings("deprecation")
@Test
public void testSetReproStepsMode() {
String mode = "ReproStepsMode.enabled";
Expand All @@ -392,6 +397,28 @@ public void testSetReproStepsMode() {
mInstabug.verify(() -> Instabug.setReproStepsState(State.ENABLED));
}

@Test
public void testSetReproStepsConfig() {
String bug = "ReproStepsMode.enabled";
String crash = "ReproStepsMode.disabled";

ReproConfigurations config = mock(ReproConfigurations.class);
MockedConstruction<ReproConfigurations.Builder> mReproConfigurationsBuilder = mockConstruction(ReproConfigurations.Builder.class, (mock, context) -> {
when(mock.setIssueMode(anyInt(), anyInt())).thenReturn(mock);
when(mock.build()).thenReturn(config);
});

api.setReproStepsConfig(bug, crash);

ReproConfigurations.Builder builder = mReproConfigurationsBuilder.constructed().get(0);

verify(builder).setIssueMode(IssueType.Bug, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.Crash, ReproMode.Disable);
verify(builder).build();

mInstabug.verify(() -> Instabug.setReproConfigurations(config));
}

@Test
public void testReportScreenChange() {
String screenName = "HomeScreen";
Expand Down
4 changes: 2 additions & 2 deletions example/ios/InstabugTests/ArgsRegistryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ - (void)testExtendedBugReportStates {
}
}

- (void)testReproStates {
- (void)testReproModes {
NSArray *values = @[
@(IBGUserStepsModeEnable),
@(IBGUserStepsModeDisable),
@(IBGUserStepsModeEnabledWithNoScreenshots)
];

for (NSNumber *value in values) {
XCTAssertTrue([[ArgsRegistry.reproStates allValues] containsObject:value]);
XCTAssertTrue([[ArgsRegistry.reproModes allValues] containsObject:value]);
}
}

Expand Down
11 changes: 11 additions & 0 deletions example/ios/InstabugTests/InstabugApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ - (void)testSetReproStepsMode {
OCMVerify([self.mInstabug setReproStepsMode:IBGUserStepsModeEnable]);
}

- (void)testSetReproStepsConfig {
NSString *bugMode = @"ReproStepsMode.enabled";
NSString *crashMode = @"ReproStepsMode.disabled";
FlutterError *error;

[self.api setReproStepsConfigBugMode:bugMode crashMode:crashMode error:&error];

OCMVerify([self.mInstabug setReproStepsFor:IBGIssueTypeBug withMode:IBGUserStepsModeEnable]);
OCMVerify([self.mInstabug setReproStepsFor:IBGIssueTypeCrash withMode:IBGUserStepsModeDisable]);
}

- (void)testReportScreenChange {
NSString *screenName = @"HomeScreen";
FlutterError *error;
Expand Down
14 changes: 13 additions & 1 deletion ios/Classes/Modules/InstabugApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,22 @@ - (void)setSdkDebugLogsLevelLevel:(NSString *)level error:(FlutterError *_Nullab
}

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

- (void)setReproStepsConfigBugMode:(nullable NSString *)bugMode crashMode:(nullable NSString *)crashMode error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
if (bugMode != nil) {
IBGUserStepsMode resolvedBugMode = ArgsRegistry.reproModes[bugMode].integerValue;
[Instabug setReproStepsFor:IBGIssueTypeBug withMode:resolvedBugMode];
}

if (crashMode != nil) {
IBGUserStepsMode resolvedCrashMode = ArgsRegistry.reproModes[crashMode].integerValue;
[Instabug setReproStepsFor:IBGIssueTypeCrash withMode:resolvedCrashMode];
}
}

- (UIImage *)getImageForAsset:(NSString *)assetName {
NSString *key = [FlutterDartProject lookupKeyForAsset:assetName];
NSString *path = [[NSBundle mainBundle] pathForResource:key ofType:nil];
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/Util/ArgsRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef NSDictionary<NSString *, NSNumber *> ArgsDictionary;
+ (ArgsDictionary *)dismissTypes;
+ (ArgsDictionary *)actionTypes;
+ (ArgsDictionary *)extendedBugReportStates;
+ (ArgsDictionary *)reproStates;
+ (ArgsDictionary *)reproModes;
+ (ArgsDictionary *)locales;
+ (NSDictionary<NSString *, NSString *> *)placeholders;

Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/Util/ArgsRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ + (ArgsDictionary *)extendedBugReportStates {
};
}

+ (ArgsDictionary *)reproStates {
+ (ArgsDictionary *)reproModes {
return @{
@"ReproStepsMode.enabled" : @(IBGUserStepsModeEnable),
@"ReproStepsMode.disabled" : @(IBGUserStepsModeDisable),
Expand Down
42 changes: 42 additions & 0 deletions lib/src/modules/instabug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,52 @@ class Instabug {

/// Sets the repro steps mode
/// [mode] repro steps mode
@Deprecated('Use [setReproStepsConfig] instead.')
static Future<void> setReproStepsMode(ReproStepsMode reproStepsMode) async {
return _host.setReproStepsMode(reproStepsMode.toString());
}

/// Sets the repro steps mode for bugs and crashes.
///
/// [bug] repro steps mode for bug reports.
/// [crash] repro steps mode for crash reports.
/// [all] repro steps mode for both bug and crash reports, when present it
/// overrides [bug] and [crash].
///
/// Example:
/// ```dart
/// Instabug.setReproStepsConfig(
/// bug: ReproStepsMode.enabled,
/// crash: ReproStepsMode.disabled,
/// );
/// ```
static Future<void> setReproStepsConfig({
ReproStepsMode? bug,
ReproStepsMode? crash,
ReproStepsMode? all,
}) async {
var bugMode = bug;
var crashMode = crash;

if (all != null) {
bugMode = all;
crashMode = all;
}

// There's an issue with crashes repro steps with screenshots in the iOS SDK
// at the moment, so we'll map enabled with screenshots to enabled with no
// screenshots to avoid storing the images on disk if it's not needed until
// this issue is fixed in a future version.
if (IBGBuildInfo.I.isIOS && crashMode == ReproStepsMode.enabled) {
crashMode = ReproStepsMode.enabledWithNoScreenshots;
}

return _host.setReproStepsConfig(
bugMode.toString(),
crashMode.toString(),
);
}

/// Sets a custom branding image logo with [light] and [dark] images for different color modes.
///
/// If no [context] is passed, [asset variants](https://docs.flutter.dev/development/ui/assets-and-images#asset-variants) won't work as expected;
Expand Down
2 changes: 2 additions & 0 deletions pigeons/instabug.api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ abstract class InstabugHostApi {
void setDebugEnabled(bool enabled);
void setSdkDebugLogsLevel(String level);

@Deprecated('Use [setReproStepsConfig] instead')
void setReproStepsMode(String mode);
void setReproStepsConfig(String? bugMode, String? crashMode);
void reportScreenChange(String screenName);

void setCustomBrandingImage(String light, String dark);
Expand Down
29 changes: 29 additions & 0 deletions test/instabug_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,42 @@ void main() {
test('[setReproStepsMode] should call host method', () async {
const mode = ReproStepsMode.enabled;

// ignore: deprecated_member_use_from_same_package
await Instabug.setReproStepsMode(mode);

verify(
mHost.setReproStepsMode(mode.toString()),
).called(1);
});

test('[setReproStepsConfig] should call host method', () async {
const bug = ReproStepsMode.enabled;
const crash = ReproStepsMode.enabledWithNoScreenshots;

when(mBuildInfo.isIOS).thenReturn(false);

await Instabug.setReproStepsConfig(
bug: bug,
crash: crash,
);

verify(
mHost.setReproStepsConfig(bug.toString(), crash.toString()),
).called(1);
});

test(
'[setReproStepsConfig] should use [all] for [bug] and [crash] if present',
() async {
const all = ReproStepsMode.enabled;

await Instabug.setReproStepsConfig(all: all);

verify(
mHost.setReproStepsConfig(all.toString(), all.toString()),
).called(1);
});

test('[setCustomBrandingImage] should call host method', () async {
const lightImage = 'images/light_logo.jpeg';
const darkImage = 'images/dark_logo.jpeg';
Expand Down