Skip to content

Commit ce90c4f

Browse files
add screen render to sample app , add unit testing to android, ios and RN
1 parent 2944c2a commit ce90c4f

File tree

8 files changed

+389
-48
lines changed

8 files changed

+389
-48
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.facebook.react.bridge.WritableNativeMap;
3131
import com.facebook.react.uimanager.UIManagerModule;
3232
import com.instabug.apm.InternalAPM;
33-
import com.instabug.apm.configuration.cp.APMFeature;
3433
import com.instabug.library.Feature;
3534
import com.instabug.library.Instabug;
3635
import com.instabug.library.InstabugColorTheme;
@@ -39,12 +38,11 @@
3938
import com.instabug.library.LogLevel;
4039
import com.instabug.library.ReproConfigurations;
4140
import com.instabug.library.core.InstabugCore;
41+
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
4242
import com.instabug.library.internal.crossplatform.CoreFeature;
4343
import com.instabug.library.internal.crossplatform.CoreFeaturesState;
4444
import com.instabug.library.internal.crossplatform.FeaturesStateListener;
4545
import com.instabug.library.internal.crossplatform.InternalCore;
46-
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
47-
import com.instabug.library.internal.crossplatform.InternalCore;
4846
import com.instabug.library.internal.crossplatform.OnFeaturesUpdatedListener;
4947
import com.instabug.library.internal.module.InstabugLocale;
5048
import com.instabug.library.invocation.InstabugInvocationEvent;
@@ -53,11 +51,9 @@
5351
import com.instabug.library.model.NetworkLog;
5452
import com.instabug.library.model.Report;
5553
import com.instabug.library.ui.onboarding.WelcomeMessage;
56-
import com.instabug.library.util.InstabugSDKLogger;
5754
import com.instabug.reactlibrary.utils.ArrayUtil;
5855
import com.instabug.reactlibrary.utils.EventEmitterModule;
5956
import com.instabug.reactlibrary.utils.MainThreadHandler;
60-
6157
import com.instabug.reactlibrary.utils.RNTouchedViewExtractor;
6258

6359
import org.json.JSONException;
@@ -120,6 +116,7 @@ public void removeListeners(Integer count) {
120116

121117
/**
122118
* Enables or disables Instabug functionality.
119+
*
123120
* @param isEnabled A boolean to enable/disable Instabug.
124121
*/
125122
@ReactMethod
@@ -1107,7 +1104,7 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11071104
params.putBoolean("isW3ExternalTraceIDEnabled", featuresState.isW3CExternalTraceIdEnabled());
11081105
params.putBoolean("isW3ExternalGeneratedHeaderEnabled", featuresState.isAttachingGeneratedHeaderEnabled());
11091106
params.putBoolean("isW3CaughtHeaderEnabled", featuresState.isAttachingCapturedHeaderEnabled());
1110-
params.putInt("networkBodyLimit",featuresState.getNetworkLogCharLimit());
1107+
params.putInt("networkBodyLimit", featuresState.getNetworkLogCharLimit());
11111108

11121109
sendEvent(Constants.IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
11131110
}
@@ -1191,7 +1188,7 @@ public void run() {
11911188
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
11921189
* The constant name and the arg key should match to be able to resolve the
11931190
* constant with its actual value from the {@link ArgsRegistry} maps.
1194-
*
1191+
* <p>
11951192
* This is a workaround, because RN cannot resolve enums in the constants map.
11961193
*/
11971194
@Override
@@ -1222,23 +1219,25 @@ public void invoke() {
12221219
}
12231220
});
12241221
}
1222+
12251223
/**
1226-
* Enables or disables capturing network body.
1227-
* @param isEnabled A boolean to enable/disable capturing network body.
1228-
*/
1229-
@ReactMethod
1230-
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
1231-
MainThreadHandler.runOnMainThread(new Runnable() {
1232-
@Override
1233-
public void run() {
1234-
try {
1235-
Instabug.setNetworkLogBodyEnabled(isEnabled);
1236-
} catch (Exception e) {
1237-
e.printStackTrace();
1238-
}
1239-
}
1240-
});
1241-
}
1224+
* Enables or disables capturing network body.
1225+
*
1226+
* @param isEnabled A boolean to enable/disable capturing network body.
1227+
*/
1228+
@ReactMethod
1229+
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
1230+
MainThreadHandler.runOnMainThread(new Runnable() {
1231+
@Override
1232+
public void run() {
1233+
try {
1234+
Instabug.setNetworkLogBodyEnabled(isEnabled);
1235+
} catch (Exception e) {
1236+
e.printStackTrace();
1237+
}
1238+
}
1239+
});
1240+
}
12421241

12431242
/**
12441243
* Sets the auto mask screenshots types.

android/src/test/java/com/instabug/reactlibrary/RNInstabugAPMModuleTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,13 @@ public void testSetFlowAttribute() {
166166
APM.endUITrace();
167167
}
168168

169+
@Test
170+
public void given$setScreenRenderEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
171+
apmModule.setScreenRenderEnabled(true);
172+
// then
173+
verify(APM.class, times(1));
174+
APM.setScreenRenderingEnabled(true);
175+
}
176+
169177

170178
}

examples/default/ios/InstabugTests/InstabugAPMTests.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,32 @@ - (void) testEndUITrace {
129129
[self.instabugBridge endUITrace];
130130
OCMVerify([mock endUITrace]);
131131
}
132+
//
133+
//- (void) testSetScreenRenderEnabled {
134+
// id mock = OCMClassMock([IBGAPM class]);
135+
// BOOL isEnabled = YES;
136+
//
137+
// OCMStub([mock enabled:isEnabled]);
138+
// [self.instabugBridge setScreenRenderEnabled:isEnabled];
139+
// OCMVerify([mock setScreenRenderEnabled:isEnabled]);
140+
//}
141+
142+
- (void) testSetScreenRenderEnabled {
143+
id mock = OCMClassMock([IBGAPM class]);
144+
NSNumber *isEnabled = @1;
145+
146+
[self.instabugBridge setScreenRenderEnabled:isEnabled];
132147

148+
OCMVerify([mock setScreenRenderingEnabled:YES]);
149+
}
150+
151+
- (void) testSetScreenRenderDisabled {
152+
id mock = OCMClassMock([IBGAPM class]);
153+
NSNumber *isEnabled = @0;
133154

155+
[self.instabugBridge setScreenRenderEnabled:isEnabled];
156+
157+
OCMVerify([mock setScreenRenderingEnabled:NO]);
158+
}
134159

135160
@end

examples/default/src/navigation/HomeStack.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { HttpScreen } from '../screens/apm/HttpScreen';
3030
import { WebViewsScreen } from '../screens/apm/webViews/WebViewsScreen';
3131
import { FullWebViewsScreen } from '../screens/apm/webViews/FullWebViewsScreen';
3232
import { PartialWebViewsScreen } from '../screens/apm/webViews/PartialWebViewsScreen';
33+
import ScreenRender from '../screens/apm/ScreenRender';
3334

3435
export type HomeStackParamList = {
3536
Home: undefined;
@@ -60,6 +61,7 @@ export type HomeStackParamList = {
6061
WebViews: undefined;
6162
FullWebViews: undefined;
6263
PartialWebViews: undefined;
64+
ScreenRender: undefined;
6365
};
6466

6567
const HomeStack = createNativeStackNavigator<HomeStackParamList>();
@@ -161,6 +163,12 @@ export const HomeStackNavigator: React.FC = () => {
161163
component={PartialWebViewsScreen}
162164
options={{ title: 'PartialWebViews' }}
163165
/>
166+
<HomeStack.Screen
167+
name="ScreenRender"
168+
component={ScreenRender}
169+
options={{ title: 'ScreenRender' }}
170+
/>
171+
164172
</HomeStack.Navigator>
165173
);
166174
};

examples/default/src/screens/apm/APMScreen.tsx

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,7 @@ export const APMScreen: React.FC<NativeStackScreenProps<HomeStackParamList, 'APM
3737
<ListTile title="Flows" onPress={() => navigation.navigate('AppFlows')} />
3838
<ListTile title="WebViews" onPress={() => navigation.navigate('WebViews')} />
3939
<ListTile title="Complex Views" onPress={() => navigation.navigate('ComplexViews')} />
40-
41-
<ListTile
42-
title="Simulate Slow Frames"
43-
onPress={() => {
44-
// Simulate slow rendering
45-
const heavyComputation = () => {
46-
for (let i = 0; i < 1000000; i++) {
47-
Math.random() * Math.random();
48-
}
49-
};
50-
heavyComputation();
51-
showNotification('Slow Frames', 'Heavy computation executed to simulate slow frames');
52-
}}
53-
/>
54-
<ListTile
55-
title="Simulate Frozen Frames"
56-
onPress={() => {
57-
const freezeDuration = 3000; // 3 seconds
58-
const start = Date.now();
59-
while (Date.now() - start < freezeDuration) {
60-
// Busy wait to block JS thread
61-
}
62-
showNotification('Frozen Frames', `UI frozen for ${freezeDuration / 1000} seconds`);
63-
}}
64-
/>
40+
<ListTile title="Screen Rendering" onPress={() => navigation.navigate('ScreenRender')} />
6541
</Screen>
6642
);
6743
};

0 commit comments

Comments
 (0)