Skip to content
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

release: dream11 #1123

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ workflows:
branches:
only: master
- hold_release_d11:
requires: *release_dependencies
# edit to publish 13.0.6 version,,since 13.0.6 version is for dream11 only and we don't have public version for it
requires:
- lint
- test_module
- validate_shell_files
- sync_generated_files
type: approval
filters:
branches:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [13.0.6](https://github.com/Instabug/Instabug-React-Native/compare/v13.0.5...v13.0.6) (JUN 17, 2024)

### Changed

- Support controlling repro steps for ANRs, app hangs, fatal crashes, non-fatal crashes, force restarts, and out-of-memory crash types separately using the `Instabug.setReproStepsConfig` API.
- Bump Instabug Android SDK to v13.0.6 . [See release notes](https://github.com/Instabug/android/releases/tag/v13.0.6).
- Bump Instabug iOS SDK to v13.0.6 . [See release notes](https://github.com/instabug/instabug-ios/releases/tag/13.0.6).

## [13.0.5](https://github.com/Instabug/Instabug-React-Native/compare/v13.0.4...v13.0.5) (May 18, 2024)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion android/native.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project.ext.instabug = [
version: '13.0.3'
version: '13.0.7'
]

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
final class Constants {
final static String IBG_PRE_INVOCATION_HANDLER = "IBGpreInvocationHandler";
final static String IBG_POST_INVOCATION_HANDLER = "IBGpostInvocationHandler";
final static String IBG_NETWORK_DIAGNOSTICS_HANDLER = "IBGNetworkDiagnosticsHandler";

final static String IBG_ON_SHOW_SURVEY_HANDLER = "IBGWillShowSurvey";
final static String IBG_ON_DISMISS_SURVEY_HANDLER = "IBGDidDismissSurvey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.View;

import androidx.annotation.UiThread;
import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
Expand All @@ -33,17 +34,20 @@
import com.instabug.library.logging.InstabugLog;
import com.instabug.library.model.NetworkLog;
import com.instabug.library.model.Report;
import com.instabug.library.networkDiagnostics.model.NetworkDiagnosticsCallback;
import com.instabug.library.ui.onboarding.WelcomeMessage;
import com.instabug.reactlibrary.utils.ArrayUtil;
import com.instabug.reactlibrary.utils.EventEmitterModule;
import com.instabug.reactlibrary.utils.MainThreadHandler;

import com.instabug.reactlibrary.utils.RNTouchedViewExtractor;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -795,22 +799,34 @@ public void run() {
}

@ReactMethod
public void setReproStepsConfig(final String bugMode, final String crashMode, final String sessionReplayMode) {
public void setReproStepsConfig(final String bugMode, final String sessionReplayMode,
final String anr, final String appHang, final String fatal, final String nonFatal, final String forceRestart,String oom

) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
final Integer resolvedBugMode = ArgsRegistry.reproModes.get(bugMode);
final Integer resolvedCrashMode = ArgsRegistry.reproModes.get(crashMode);
final Integer resolvedSessionReplayMode = ArgsRegistry.reproModes.get(sessionReplayMode);
final Integer resolvedAnrMode = ArgsRegistry.reproModes.get(anr);
final Integer resolvedAppHangsMode = ArgsRegistry.reproModes.get(appHang);
final Integer resolvedFatalCrashesMode = ArgsRegistry.reproModes.get(fatal);
final Integer resolvedNonFatalCrashesMode = ArgsRegistry.reproModes.get(nonFatal);
final Integer resolvedForceRestartStartMode = ArgsRegistry.reproModes.get(forceRestart);

final ReproConfigurations config = new ReproConfigurations.Builder()
final ReproConfigurations.Builder config = new ReproConfigurations.Builder()
.setIssueMode(IssueType.Bug, resolvedBugMode)
.setIssueMode(IssueType.Crash, resolvedCrashMode)
.setIssueMode(IssueType.SessionReplay, resolvedSessionReplayMode)
.build();
.setIssueMode(IssueType.ANR, resolvedAnrMode)
.setIssueMode(IssueType.AppHang, resolvedAppHangsMode)
.setIssueMode(IssueType.Fatal, resolvedFatalCrashesMode)
.setIssueMode(IssueType.NonFatal, resolvedNonFatalCrashesMode)
.setIssueMode(IssueType.ForceRestart, resolvedForceRestartStartMode)
.setIssueMode(IssueType.SessionReplay, resolvedSessionReplayMode);



Instabug.setReproConfigurations(config);
Instabug.setReproConfigurations(config.build());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -1070,6 +1086,39 @@ public void run() {
});
}

@ReactMethod
public void setOnNetworkDiagnosticsHandler() {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "setNetworkDiagnosticsCallback", NetworkDiagnosticsCallback.class);

if (method != null) {
method.invoke(null, new NetworkDiagnosticsCallback() {
@Override
public void onReady(@NonNull String date, int totalRequestCount, int failureCount) {
try {
WritableMap params = Arguments.createMap();
params.putString("date", date);
params.putInt("totalRequestCount", totalRequestCount);
params.putInt("failureCount", failureCount);

sendEvent(Constants.IBG_NETWORK_DIAGNOSTICS_HANDLER, params);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
} catch (ClassNotFoundException | IllegalAccessException |
InvocationTargetException e) {
e.printStackTrace();
}
}
});
}

/**
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
* The constant name and the arg key should match to be able to resolve the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.instabug.library.Feature;
Expand All @@ -19,7 +20,10 @@
import com.instabug.library.ReproConfigurations;
import com.instabug.library.ReproMode;
import com.instabug.library.internal.module.InstabugLocale;
import com.instabug.library.networkDiagnostics.model.NetworkDiagnosticsCallback;
import com.instabug.library.ui.onboarding.WelcomeMessage;
import com.instabug.reactlibrary.util.GlobalMocks;
import com.instabug.reactlibrary.util.MockReflected;
import com.instabug.reactlibrary.utils.MainThreadHandler;

import org.junit.After;
Expand All @@ -37,6 +41,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -45,18 +50,21 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import static com.instabug.reactlibrary.util.GlobalMocks.reflected;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


public class RNInstabugReactnativeModuleTest {
private RNInstabugReactnativeModule rnModule = new RNInstabugReactnativeModule(null);
private RNInstabugReactnativeModule rnModule;
private ReactApplicationContext mReactContext = mock(ReactApplicationContext.class);

private final static ScheduledExecutorService mainThread = Executors.newSingleThreadScheduledExecutor();

Expand All @@ -66,7 +74,9 @@ public class RNInstabugReactnativeModuleTest {
private MockedStatic <Instabug> mockInstabug;

@Before
public void mockMainThreadHandler() throws Exception {
public void setUp() throws Exception {
rnModule = spy(new RNInstabugReactnativeModule(mReactContext));

// Mock static functions
mockInstabug = mockStatic(Instabug.class);
mockLooper = mockStatic(Looper.class);
Expand All @@ -86,13 +96,19 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
};
Mockito.doAnswer(handlerPostAnswer).when(MainThreadHandler.class);
MainThreadHandler.runOnMainThread(any(Runnable.class));

// Set up global mocks
GlobalMocks.setUp();
}
@After
public void tearDown() {
// Remove static mocks
mockLooper.close();
mockMainThreadHandler.close();
mockInstabug.close();

// Remove global mocks
GlobalMocks.close();
}

/********Instabug*********/
Expand Down Expand Up @@ -282,22 +298,33 @@ public void testIdentifyUserWithId() {
@Test
public void givenArg$setReproStepsConfig_whenQuery_thenShouldCallNativeApiWithArg() {
String bug = "reproStepsEnabled";
String crash = "reproStepsDisabled";
String anr = "reproStepsEnabled";
String apphangs = "reproStepsEnabled";
String crashNonFatal = "reproStepsDisabled";
String crashFatal = "reproStepsEnabled";
String forceRestart = "reproStepsDisabled";

String sessionReplay = "reproStepsEnabled";


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);
});

rnModule.setReproStepsConfig(bug, crash, sessionReplay);
rnModule.setReproStepsConfig(bug, sessionReplay,anr,apphangs,crashFatal,crashNonFatal,forceRestart,null);

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

verify(builder).setIssueMode(IssueType.Bug, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.Crash, ReproMode.Disable);
verify(builder).setIssueMode(IssueType.SessionReplay, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.ANR, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.AppHang, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.Fatal, ReproMode.EnableWithScreenshots);
verify(builder).setIssueMode(IssueType.NonFatal, ReproMode.Disable);
verify(builder).setIssueMode(IssueType.ForceRestart, ReproMode.Disable);

verify(builder).build();

mockInstabug.verify(() -> Instabug.setReproConfigurations(config));
Expand Down Expand Up @@ -505,28 +532,17 @@ public void testIdentifyUserWithId() {
}

@Test
public void givenString$reportCurrentViewChange_whenQuery_thenShouldCallNativeApiWithString() throws Exception {
// when
public void testReportCurrentViewChange() {
rnModule.reportCurrentViewChange("screen");
Method privateStringMethod = getMethod(Class.forName("com.instabug.library.Instabug"), "reportCurrentViewChange", String.class);
privateStringMethod.setAccessible(true);

// then
verify(Instabug.class, VerificationModeFactory.times(1));
privateStringMethod.invoke("reportCurrentViewChange","screen");
reflected.verify(() -> MockReflected.reportCurrentViewChange("screen"), times(1));
}

@Test
public void givenString$reportScreenChange_whenQuery_thenShouldCallNativeApiWithString() throws Exception {
// when
public void testReportScreenChange() {
rnModule.reportScreenChange("screen");
Method privateStringMethod = getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange", Bitmap.class, String.class);
privateStringMethod.setAccessible(true);

// then
verify(Instabug.class, VerificationModeFactory.times(1));
privateStringMethod.invoke("reportScreenChange", null,"screen");

reflected.verify(() -> MockReflected.reportScreenChange(null, "screen"), times(1));
}

@Test
Expand Down Expand Up @@ -585,4 +601,33 @@ public void testWillRedirectToStore() {
// then
mockInstabug.verify(() -> Instabug.willRedirectToStore());
}

@Test
public void testSetOnNetworkDiagnosticsHandler() {
String date = new Date().toString();
int successOrderCount = 2;
int failureCount = 1;

MockedStatic<Arguments> mockArgument = mockStatic(Arguments.class);
mockArgument.when(Arguments::createMap).thenReturn(new JavaOnlyMap());

reflected
.when(() -> MockReflected.setNetworkDiagnosticsCallback(any(NetworkDiagnosticsCallback.class)))
.thenAnswer((InvocationOnMock invocation) -> {
NetworkDiagnosticsCallback callback = invocation.getArgument(0);
callback.onReady(date, successOrderCount, failureCount);
return null;
});

rnModule.setOnNetworkDiagnosticsHandler();

WritableMap params = new JavaOnlyMap();
params.putString("date", date);
params.putInt("totalRequestCount", successOrderCount);
params.putInt("failureCount", failureCount);

verify(rnModule).sendEvent(Constants.IBG_NETWORK_DIAGNOSTICS_HANDLER, params);

mockArgument.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.instabug.reactlibrary.util;

import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod;
import static org.mockito.Mockito.mockStatic;

import android.graphics.Bitmap;
import android.util.Log;

import com.instabug.library.networkDiagnostics.model.NetworkDiagnosticsCallback;
import com.instabug.reactlibrary.utils.InstabugUtil;

import org.mockito.MockedStatic;
Expand Down Expand Up @@ -37,6 +40,29 @@ public static void setUp() throws NoSuchMethodException {
reflection
.when(() -> InstabugUtil.getMethod(Class.forName("com.instabug.library.util.InstabugDeprecationLogger"), "setBaseUrl", String.class))
.thenReturn(mSetBaseUrl);

// setNetworkDiagnosticsCallback mock
Method mSetNetworkDiagnosticsCallback = MockReflected.class.getDeclaredMethod("setNetworkDiagnosticsCallback", NetworkDiagnosticsCallback.class);
mSetNetworkDiagnosticsCallback.setAccessible(true);
reflection
.when(() -> InstabugUtil.getMethod(Class.forName("com.instabug.library.Instabug"), "setNetworkDiagnosticsCallback", NetworkDiagnosticsCallback.class))
.thenReturn(mSetNetworkDiagnosticsCallback);

// reportCurrentViewChange mock
Method mReportCurrentViewChange = MockReflected.class.getDeclaredMethod("reportCurrentViewChange", String.class);
mReportCurrentViewChange.setAccessible(true);

reflection
.when(() -> InstabugUtil.getMethod(Class.forName("com.instabug.library.Instabug"), "reportCurrentViewChange", String.class))
.thenReturn(mReportCurrentViewChange);

// reportScreenChange mock
Method mReportScreenChange = MockReflected.class.getDeclaredMethod("reportScreenChange", Bitmap.class, String.class);
mReportScreenChange.setAccessible(true);

reflection
.when(() -> InstabugUtil.getMethod(Class.forName("com.instabug.library.Instabug"), "reportScreenChange", Bitmap.class, String.class))
.thenReturn(mReportScreenChange);
}

public static void close() {
Expand Down
Loading