Skip to content

Commit f7fe7b3

Browse files
authored
Merge pull request #1192 from Instabug/dev
2 parents 1b83638 + a277bb4 commit f7fe7b3

27 files changed

+433
-31
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type {import('eslint').ESLint.ConfigData} */
22
module.exports = {
33
extends: '@react-native-community',
4-
plugins: ['prettier', 'jest'],
4+
plugins: ['prettier', 'jest', 'jsdoc'],
55
overrides: [
66
{
77
// Jest Overrides
@@ -34,6 +34,7 @@ module.exports = {
3434
},
3535
],
3636
rules: {
37+
'jsdoc/no-undefined-types': 'warn',
3738
'prettier/prettier': 'error',
3839
'prefer-const': 'error',
3940
},

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
# Changelog
22

3+
## [13.0.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.9.0...dev) (April 19, 2024)
4+
5+
### Added
6+
7+
- Add `Instabug.willRedirectToStore` API for use in custom app rating prompts ([#1186](https://github.com/Instabug/Instabug-React-Native/pull/1186)).
8+
- Add support for App Flows APIs `APM.startFlow`, `APM.setFlowAttribute` and `APM.endFlow` ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).
9+
10+
### Changed
11+
12+
- Bump Instabug iOS SDK to v13.0.0 ([#1189](https://github.com/Instabug/Instabug-React-Native/pull/1189)). [See release notes](https://github.com/instabug/instabug-ios/releases/tag/13.0.0).
13+
- Bump Instabug Android SDK to v13.0.0 ([#1188](https://github.com/Instabug/Instabug-React-Native/pull/1188)). [See release notes](https://github.com/Instabug/android/releases/tag/v13.0.0).
14+
315
## [12.9.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.8.0...dev)(April 2, 2024)
416

517
### Added
618

719
- Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137))
820
- Support enabling NDK crash capturing on Android ([#1132](https://github.com/Instabug/Instabug-React-Native/pull/1132)).
921

22+
### Deprecated
23+
24+
- Deprecate Execution Traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setAttribute` in favor of the new App Flows APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).
25+
1026
### Changed
1127

1228
- Bump Instabug Android SDK to v12.9.0 ([#1168](https://github.com/Instabug/Instabug-React-Native/pull/1168)). [See release notes](https://github.com/Instabug/android/releases/tag/v12.9.0).

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ android {
5757
minSdkVersion getExtOrDefault('minSdkVersion').toInteger()
5858
targetSdkVersion getExtOrDefault('targetSdkVersion').toInteger()
5959
versionCode 1
60-
versionName "12.9.0"
60+
versionName "13.0.0"
6161
multiDexEnabled true
6262
ndk {
6363
abiFilters "armeabi-v7a", "x86"

android/native.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project.ext.instabug = [
2-
version: '12.9.0'
2+
version: '13.0.0'
33
]
44

55
dependencies {

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

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.os.SystemClock;
55
import android.util.Log;
66

7+
import androidx.annotation.NonNull;
78
import com.facebook.react.bridge.Promise;
89
import com.facebook.react.bridge.ReactApplicationContext;
910
import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -29,6 +30,8 @@ public class RNInstabugAPMModule extends ReactContextBaseJavaModule {
2930
public RNInstabugAPMModule(ReactApplicationContext reactApplicationContext) {
3031
super(reactApplicationContext);
3132
}
33+
34+
@Deprecated
3235
HashMap<String, ExecutionTrace> traces = new HashMap<String, ExecutionTrace>();
3336

3437
@Nonnull
@@ -121,10 +124,92 @@ public void run() {
121124
});
122125
}
123126

127+
/**
128+
* Starts an AppFlow with the specified name.
129+
* <br/>
130+
* On starting two flows with the same name the older flow will end with force abandon end reason.
131+
* AppFlow name cannot exceed 150 characters otherwise it's truncated,
132+
* leading and trailing whitespaces are also ignored.
133+
*
134+
* @param name AppFlow name. It can not be empty string or null.
135+
* Starts a new AppFlow, if APM is enabled, feature is enabled
136+
* and Instabug SDK is initialised.
137+
*/
138+
@ReactMethod
139+
public void startFlow(@NonNull final String name) {
140+
MainThreadHandler.runOnMainThread(new Runnable() {
141+
@Override
142+
public void run() {
143+
try {
144+
APM.startFlow(name);
145+
} catch (Exception e) {
146+
e.printStackTrace();
147+
}
148+
}
149+
});
150+
}
151+
152+
/**
153+
* Sets custom attributes for AppFlow with a given name.
154+
* <br/>
155+
* Setting an attribute value to null will remove its corresponding key if it already exists.
156+
* <br/>
157+
* Attribute key name cannot exceed 30 characters.
158+
* Leading and trailing whitespaces are also ignored.
159+
* Does not accept empty strings or null.
160+
* <br/>
161+
* Attribute value name cannot exceed 60 characters,
162+
* leading and trailing whitespaces are also ignored.
163+
* Does not accept empty strings.
164+
* <br/>
165+
* If a trace is ended, attributes will not be added and existing ones will not be updated.
166+
* <br/>
167+
*
168+
* @param name AppFlow name. It can not be empty string or null
169+
* @param key AppFlow attribute key. It can not be empty string or null
170+
* @param value AppFlow attribute value. It can not be empty string. Null to remove attribute
171+
*/
172+
@ReactMethod
173+
public void setFlowAttribute(@NonNull final String name, @NonNull final String key, final String value) {
174+
MainThreadHandler.runOnMainThread(new Runnable() {
175+
@Override
176+
public void run() {
177+
try {
178+
APM.setFlowAttribute(name, key, value);
179+
} catch (Exception e) {
180+
e.printStackTrace();
181+
}
182+
}
183+
});
184+
}
185+
186+
/**
187+
* Ends AppFlow with a given name.
188+
*
189+
* @param name AppFlow name to be ended. It can not be empty string or null
190+
*/
191+
@ReactMethod
192+
public void endFlow(@NonNull final String name) {
193+
MainThreadHandler.runOnMainThread(new Runnable() {
194+
@Override
195+
public void run() {
196+
try {
197+
APM.endFlow(name);
198+
} catch (Exception e) {
199+
e.printStackTrace();
200+
}
201+
}
202+
});
203+
}
204+
124205
/**
125206
* Starts an execution trace
207+
*
126208
* @param name string name of the trace.
209+
*
210+
* @deprecated see {@link #startFlow(String)}
127211
*/
212+
@Deprecated
128213
@ReactMethod
129214
public void startExecutionTrace(final String name, final String id, final Promise promise) {
130215
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -148,10 +233,14 @@ public void run() {
148233

149234
/**
150235
* Adds a new attribute to trace
151-
* @param id String id of the trace.
236+
*
237+
* @param id String id of the trace.
152238
* @param key attribute key
153239
* @param value attribute value. Null to remove attribute
240+
*
241+
* @deprecated see {@link #setFlowAttribute}
154242
*/
243+
@Deprecated
155244
@ReactMethod
156245
public void setExecutionTraceAttribute(final String id, final String key, final String value) {
157246
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -168,8 +257,12 @@ public void run() {
168257

169258
/**
170259
* Ends a trace
260+
*
171261
* @param id string id of the trace.
262+
*
263+
* @deprecated see {@link #endFlow}
172264
*/
265+
@Deprecated
173266
@ReactMethod
174267
public void endExecutionTrace(final String id) {
175268
MainThreadHandler.runOnMainThread(new Runnable() {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,20 @@ public void run() {
10561056
});
10571057
}
10581058

1059+
@ReactMethod
1060+
public void willRedirectToStore() {
1061+
MainThreadHandler.runOnMainThread(new Runnable() {
1062+
@Override
1063+
public void run() {
1064+
try {
1065+
Instabug.willRedirectToStore();
1066+
} catch (Exception e) {
1067+
e.printStackTrace();
1068+
}
1069+
}
1070+
});
1071+
}
1072+
10591073
/**
10601074
* Map between the exported JS constant and the arg key in {@link ArgsRegistry}.
10611075
* The constant name and the arg key should match to be able to resolve the

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,37 @@ public void givenTruesetEnabled_whenQuery_thenShouldCallNativeApiWithEnabled() {
125125
verify(promise).resolve(any());
126126
}
127127

128+
@Test
129+
public void testStartFlow() {
130+
String appFlowName = "appFlowName";
131+
132+
apmModule.startFlow(appFlowName);
133+
134+
mockAPM.verify(() -> APM.startFlow(appFlowName));
135+
mockAPM.verifyNoMoreInteractions();
136+
}
137+
138+
@Test
139+
public void testEndFlow() {
140+
String appFlowName = "appFlowName";
141+
142+
apmModule.endFlow(appFlowName);
143+
144+
mockAPM.verify(() -> APM.endFlow(appFlowName));
145+
mockAPM.verifyNoMoreInteractions();
146+
}
147+
148+
@Test
149+
public void testSetFlowAttribute() {
150+
String appFlowName = "appFlowName";
151+
String flowAttributeKey = "attributeKey";
152+
String flowAttributeValue = "attributeValue";
153+
apmModule.setFlowAttribute(appFlowName, flowAttributeKey, flowAttributeValue);
154+
155+
mockAPM.verify(() -> APM.setFlowAttribute(appFlowName, flowAttributeKey, flowAttributeValue));
156+
mockAPM.verifyNoMoreInteractions();
157+
}
158+
128159
// @Test
129160
// public void givenString$setExecutionTraceAttribute_whenQuery_thenShouldCallNativeApiWithIntArgs() {
130161
// // given

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,13 @@ public void testIdentifyUserWithId() {
576576
verify(Instabug.class,times(1));
577577
Instabug.clearAllExperiments();
578578
}
579+
580+
@Test
581+
public void testWillRedirectToStore() {
582+
// when
583+
rnModule.willRedirectToStore();
584+
585+
// then
586+
mockInstabug.verify(() -> Instabug.willRedirectToStore());
587+
}
579588
}

examples/default/ios/InstabugTests/InstabugAPMTests.m

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ - (void) testSetAPMEnabled {
6262
- (void) testSetAppLaunchEnabled {
6363
id mock = OCMClassMock([IBGAPM class]);
6464
BOOL isEnabled = YES;
65-
65+
6666
OCMStub([mock setColdAppLaunchEnabled:isEnabled]);
6767
[self.instabugBridge setAppLaunchEnabled:isEnabled];
6868
OCMVerify([mock setColdAppLaunchEnabled:isEnabled]);
6969
}
7070

7171
- (void) testEndAppLaunch {
7272
id mock = OCMClassMock([IBGAPM class]);
73-
73+
7474
OCMStub([mock endAppLaunch]);
7575
[self.instabugBridge endAppLaunch];
7676
OCMVerify([mock endAppLaunch]);
@@ -79,7 +79,7 @@ - (void) testEndAppLaunch {
7979
- (void) testSetAutoUITraceEnabled {
8080
id mock = OCMClassMock([IBGAPM class]);
8181
BOOL isEnabled = YES;
82-
82+
8383
OCMStub([mock setAutoUITraceEnabled:isEnabled]);
8484
[self.instabugBridge setAutoUITraceEnabled:isEnabled];
8585
OCMVerify([mock setAutoUITraceEnabled:isEnabled]);
@@ -91,7 +91,7 @@ - (void) testStartExecutionTrace {
9191
NSString* traceKey = @"1";
9292
RCTPromiseResolveBlock resolve = ^(id result) {};
9393
RCTPromiseRejectBlock reject = ^(NSString *code, NSString *message, NSError *error) {};
94-
94+
9595
OCMStub([mock startExecutionTraceWithName:traceName]);
9696
[self.instabugBridge startExecutionTrace:traceName :traceKey :resolve :reject];
9797
OCMVerify([mock startExecutionTraceWithName:traceName]);
@@ -107,10 +107,10 @@ - (void) testSetExecutionTraceAttribute {
107107
IBGExecutionTrace * trace = [IBGExecutionTrace alloc];
108108
id mock = OCMClassMock([IBGAPM class]);
109109
id traceMock = OCMPartialMock(trace);
110-
110+
111111
OCMStub([mock startExecutionTraceWithName:traceName]).andReturn(trace);
112112
[self.instabugBridge startExecutionTrace:traceName :traceId :resolve :reject];
113-
113+
114114
OCMStub([traceMock setAttributeWithKey:traceKey value:traceValue]);
115115
[self.instabugBridge setExecutionTraceAttribute:traceId :traceKey :traceValue];
116116
OCMVerify([traceMock setAttributeWithKey:traceKey value:traceValue]);
@@ -127,24 +127,50 @@ - (void) testEndExecutionTrace {
127127

128128
OCMStub([apmMock startExecutionTraceWithName:traceName]).andReturn(trace);
129129
[self.instabugBridge startExecutionTrace:traceName :traceId :resolve :reject];
130-
130+
131131
OCMStub([traceMock end]);
132132
[self.instabugBridge endExecutionTrace:traceId];
133133
OCMVerify([traceMock end]);
134134
}
135135

136+
- (void) testStartFlow {
137+
id mock = OCMClassMock([IBGAPM class]);
138+
NSString* appFlowName = @"APP_Flow_1";
139+
140+
[self.instabugBridge startFlow:appFlowName];
141+
OCMVerify([mock startFlowWithName:appFlowName]);
142+
}
143+
144+
- (void) testEndFlow {
145+
id mock = OCMClassMock([IBGAPM class]);
146+
NSString* appFlowName = @"APP_Flow_1";
147+
148+
[self.instabugBridge endFlow:appFlowName];
149+
OCMVerify([mock endFlowWithName:appFlowName]);
150+
}
151+
152+
- (void) testSetFlowAttribute {
153+
id mock = OCMClassMock([IBGAPM class]);
154+
NSString* appFlowName = @"APP_Flow_1";
155+
NSString* attributeKey = @"Attribute_Key_1";
156+
NSString* attributeValue = @"Attribute_Value_1";
157+
158+
[self.instabugBridge setFlowAttribute:appFlowName :attributeKey :attributeValue];
159+
OCMVerify([mock setAttributeForFlowWithName:appFlowName key:attributeKey value:attributeValue]);
160+
}
161+
136162
- (void) testStartUITrace {
137163
id mock = OCMClassMock([IBGAPM class]);
138164
NSString* traceName = @"UITrace_1";
139-
165+
140166
OCMStub([mock startUITraceWithName:traceName]);
141167
[self.instabugBridge startUITrace:traceName];
142168
OCMVerify([mock startUITraceWithName:traceName]);
143169
}
144170

145171
- (void) testEndUITrace {
146172
id mock = OCMClassMock([IBGAPM class]);
147-
173+
148174
OCMStub([mock endUITrace]);
149175
[self.instabugBridge endUITrace];
150176
OCMVerify([mock endUITrace]);

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ - (void)testShow {
340340
}
341341

342342

343+
- (void)testWillRedirectToStore {
344+
345+
id mock = OCMClassMock([Instabug class]);
346+
347+
[self.instabugBridge willRedirectToStore];
348+
349+
OCMVerify([mock willRedirectToAppStore]);
350+
351+
[mock stopMocking];
352+
}
353+
354+
355+
343356
/*
344357
+------------------------------------------------------------------------+
345358
| Log Module |

0 commit comments

Comments
 (0)