Skip to content

Commit 190e364

Browse files
AndrewAminInstabugMoKamall
authored andcommitted
add screen render to sample app , add unit testing to android, ios and RN
1 parent f241b73 commit 190e364

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
@@ -26,7 +26,6 @@
2626
import com.facebook.react.bridge.WritableNativeMap;
2727
import com.facebook.react.uimanager.UIManagerModule;
2828
import com.instabug.apm.InternalAPM;
29-
import com.instabug.apm.configuration.cp.APMFeature;
3029
import com.instabug.library.Feature;
3130
import com.instabug.library.Instabug;
3231
import com.instabug.library.InstabugColorTheme;
@@ -35,24 +34,21 @@
3534
import com.instabug.library.LogLevel;
3635
import com.instabug.library.ReproConfigurations;
3736
import com.instabug.library.core.InstabugCore;
37+
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
3838
import com.instabug.library.internal.crossplatform.CoreFeature;
3939
import com.instabug.library.internal.crossplatform.CoreFeaturesState;
4040
import com.instabug.library.internal.crossplatform.FeaturesStateListener;
4141
import com.instabug.library.internal.crossplatform.InternalCore;
42-
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
43-
import com.instabug.library.internal.crossplatform.InternalCore;
4442
import com.instabug.library.internal.crossplatform.OnFeaturesUpdatedListener;
4543
import com.instabug.library.internal.module.InstabugLocale;
4644
import com.instabug.library.invocation.InstabugInvocationEvent;
4745
import com.instabug.library.logging.InstabugLog;
4846
import com.instabug.library.model.NetworkLog;
4947
import com.instabug.library.model.Report;
5048
import com.instabug.library.ui.onboarding.WelcomeMessage;
51-
import com.instabug.library.util.InstabugSDKLogger;
5249
import com.instabug.reactlibrary.utils.ArrayUtil;
5350
import com.instabug.reactlibrary.utils.EventEmitterModule;
5451
import com.instabug.reactlibrary.utils.MainThreadHandler;
55-
5652
import com.instabug.reactlibrary.utils.RNTouchedViewExtractor;
5753

5854
import org.json.JSONException;
@@ -115,6 +111,7 @@ public void removeListeners(Integer count) {
115111

116112
/**
117113
* Enables or disables Instabug functionality.
114+
*
118115
* @param isEnabled A boolean to enable/disable Instabug.
119116
*/
120117
@ReactMethod
@@ -1175,7 +1172,7 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11751172
params.putBoolean("isW3ExternalTraceIDEnabled", featuresState.isW3CExternalTraceIdEnabled());
11761173
params.putBoolean("isW3ExternalGeneratedHeaderEnabled", featuresState.isAttachingGeneratedHeaderEnabled());
11771174
params.putBoolean("isW3CaughtHeaderEnabled", featuresState.isAttachingCapturedHeaderEnabled());
1178-
params.putInt("networkBodyLimit",featuresState.getNetworkLogCharLimit());
1175+
params.putInt("networkBodyLimit", featuresState.getNetworkLogCharLimit());
11791176

11801177
sendEvent(Constants.IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
11811178
}
@@ -1259,7 +1256,7 @@ public void run() {
12591256
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
12601257
* The constant name and the arg key should match to be able to resolve the
12611258
* constant with its actual value from the {@link ArgsRegistry} maps.
1262-
*
1259+
* <p>
12631260
* This is a workaround, because RN cannot resolve enums in the constants map.
12641261
*/
12651262
@Override
@@ -1290,23 +1287,25 @@ public void invoke() {
12901287
}
12911288
});
12921289
}
1290+
12931291
/**
1294-
* Enables or disables capturing network body.
1295-
* @param isEnabled A boolean to enable/disable capturing network body.
1296-
*/
1297-
@ReactMethod
1298-
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
1299-
MainThreadHandler.runOnMainThread(new Runnable() {
1300-
@Override
1301-
public void run() {
1302-
try {
1303-
Instabug.setNetworkLogBodyEnabled(isEnabled);
1304-
} catch (Exception e) {
1305-
e.printStackTrace();
1306-
}
1307-
}
1308-
});
1309-
}
1292+
* Enables or disables capturing network body.
1293+
*
1294+
* @param isEnabled A boolean to enable/disable capturing network body.
1295+
*/
1296+
@ReactMethod
1297+
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
1298+
MainThreadHandler.runOnMainThread(new Runnable() {
1299+
@Override
1300+
public void run() {
1301+
try {
1302+
Instabug.setNetworkLogBodyEnabled(isEnabled);
1303+
} catch (Exception e) {
1304+
e.printStackTrace();
1305+
}
1306+
}
1307+
});
1308+
}
13101309

13111310
/**
13121311
* 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
@@ -205,5 +205,13 @@ public void testSetFlowAttribute() {
205205
APM.endUITrace();
206206
}
207207

208+
@Test
209+
public void given$setScreenRenderEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
210+
apmModule.setScreenRenderEnabled(true);
211+
// then
212+
verify(APM.class, times(1));
213+
APM.setScreenRenderingEnabled(true);
214+
}
215+
208216

209217
}

examples/default/ios/InstabugTests/InstabugAPMTests.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,32 @@ - (void) testEndUITrace {
176176
[self.instabugBridge endUITrace];
177177
OCMVerify([mock endUITrace]);
178178
}
179+
//
180+
//- (void) testSetScreenRenderEnabled {
181+
// id mock = OCMClassMock([IBGAPM class]);
182+
// BOOL isEnabled = YES;
183+
//
184+
// OCMStub([mock enabled:isEnabled]);
185+
// [self.instabugBridge setScreenRenderEnabled:isEnabled];
186+
// OCMVerify([mock setScreenRenderEnabled:isEnabled]);
187+
//}
188+
189+
- (void) testSetScreenRenderEnabled {
190+
id mock = OCMClassMock([IBGAPM class]);
191+
NSNumber *isEnabled = @1;
192+
193+
[self.instabugBridge setScreenRenderEnabled:isEnabled];
179194

195+
OCMVerify([mock setScreenRenderingEnabled:YES]);
196+
}
197+
198+
- (void) testSetScreenRenderDisabled {
199+
id mock = OCMClassMock([IBGAPM class]);
200+
NSNumber *isEnabled = @0;
180201

202+
[self.instabugBridge setScreenRenderEnabled:isEnabled];
203+
204+
OCMVerify([mock setScreenRenderingEnabled:NO]);
205+
}
181206

182207
@end

examples/default/src/navigation/HomeStack.tsx

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

3536
export type HomeStackParamList = {
3637
Home: undefined;
@@ -61,6 +62,7 @@ export type HomeStackParamList = {
6162
WebViews: undefined;
6263
FullWebViews: undefined;
6364
PartialWebViews: undefined;
65+
ScreenRender: undefined;
6466
};
6567

6668
const HomeStack = createNativeStackNavigator<HomeStackParamList>();
@@ -163,6 +165,12 @@ export const HomeStackNavigator: React.FC = () => {
163165
component={PartialWebViewsScreen}
164166
options={{ title: 'PartialWebViews' }}
165167
/>
168+
<HomeStack.Screen
169+
name="ScreenRender"
170+
component={ScreenRender}
171+
options={{ title: 'ScreenRender' }}
172+
/>
173+
166174
</HomeStack.Navigator>
167175
);
168176
};

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

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

0 commit comments

Comments
 (0)