Skip to content

Commit 25e35fe

Browse files
authored
Native tests + Separate enums (#323)
* ✨ Add BugReporting native Android tests * ✨ Adds android native tests for modules: crash reporting, surveys, feature requests, chats and replies
1 parent edbe243 commit 25e35fe

File tree

4 files changed

+916
-31
lines changed

4 files changed

+916
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@
5959
* Added new OnReportSubmitHandler API
6060
* Fixed linking script
6161
* Api Name Changes
62+
63+
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
package com.instabug.reactlibrary;
2+
3+
import java.util.HashMap;
4+
import java.util.Locale;
5+
import java.util.Map;
6+
7+
import com.instabug.bug.BugReporting;
8+
import com.instabug.bug.invocation.Option;
9+
import com.instabug.library.ActionType;
10+
import com.instabug.library.InstabugColorTheme;
11+
import com.instabug.library.InstabugCustomTextPlaceHolder;
12+
import com.instabug.library.extendedbugreport.ExtendedBugReport;
13+
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition;
14+
15+
import static com.instabug.library.internal.module.InstabugLocale.ARABIC;
16+
import static com.instabug.library.internal.module.InstabugLocale.CZECH;
17+
import static com.instabug.library.internal.module.InstabugLocale.DANISH;
18+
import static com.instabug.library.internal.module.InstabugLocale.ENGLISH;
19+
import static com.instabug.library.internal.module.InstabugLocale.FRENCH;
20+
import static com.instabug.library.internal.module.InstabugLocale.GERMAN;
21+
import static com.instabug.library.internal.module.InstabugLocale.INDONESIAN;
22+
import static com.instabug.library.internal.module.InstabugLocale.ITALIAN;
23+
import static com.instabug.library.internal.module.InstabugLocale.JAPANESE;
24+
import static com.instabug.library.internal.module.InstabugLocale.KOREAN;
25+
import static com.instabug.library.internal.module.InstabugLocale.NETHERLANDS;
26+
import static com.instabug.library.internal.module.InstabugLocale.NORWEGIAN;
27+
import static com.instabug.library.internal.module.InstabugLocale.POLISH;
28+
import static com.instabug.library.internal.module.InstabugLocale.PORTUGUESE_BRAZIL;
29+
import static com.instabug.library.internal.module.InstabugLocale.PORTUGUESE_PORTUGAL;
30+
import static com.instabug.library.internal.module.InstabugLocale.RUSSIAN;
31+
import static com.instabug.library.internal.module.InstabugLocale.SIMPLIFIED_CHINESE;
32+
import static com.instabug.library.internal.module.InstabugLocale.SLOVAK;
33+
import static com.instabug.library.internal.module.InstabugLocale.SPANISH;
34+
import static com.instabug.library.internal.module.InstabugLocale.SWEDISH;
35+
import static com.instabug.library.internal.module.InstabugLocale.TRADITIONAL_CHINESE;
36+
import static com.instabug.library.internal.module.InstabugLocale.TURKISH;
37+
import static com.instabug.library.invocation.InstabugInvocationEvent.FLOATING_BUTTON;
38+
import static com.instabug.library.invocation.InstabugInvocationEvent.NONE;
39+
import static com.instabug.library.invocation.InstabugInvocationEvent.SCREENSHOT;
40+
import static com.instabug.library.invocation.InstabugInvocationEvent.SHAKE;
41+
import static com.instabug.library.invocation.InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT;
42+
import static com.instabug.library.ui.onboarding.WelcomeMessage.State.BETA;
43+
import static com.instabug.library.ui.onboarding.WelcomeMessage.State.DISABLED;
44+
import static com.instabug.library.ui.onboarding.WelcomeMessage.State.LIVE;
45+
46+
@SuppressWarnings({"SameParameterValue", "unchecked"})
47+
final class ArgsRegistry {
48+
49+
static final Map<String, Object> ARGS = new HashMap<>();
50+
51+
static {
52+
registerInstabugInvocationEventsArgs(ARGS);
53+
registerWelcomeMessageArgs(ARGS);
54+
registerColorThemeArgs(ARGS);
55+
registerLocaleArgs(ARGS);
56+
registerInvocationModeArgs(ARGS);
57+
registerInvocationOptionsArgs(ARGS);
58+
registerCustomTextPlaceHolderKeysArgs(ARGS);
59+
registerInstabugReportTypesArgs(ARGS);
60+
registerInstabugExtendedBugReportModeArgs(ARGS);
61+
registerInstabugActionTypesArgs(ARGS);
62+
registerInstabugVideoRecordingFloatingButtonPositionArgs(ARGS);
63+
}
64+
65+
/**
66+
* This acts as a safe get() method.
67+
* It returns the queried value after deserialization if AND ONLY IF it passed the following assertions:
68+
* - {@code key} is not null
69+
* - {@code key} does exist in the registry
70+
* - The value assigned to the {@code key} is not null
71+
* - The value assigned to the {@code key} is assignable from and can be casted to {@code clazz}
72+
* (i.e. Foo value = getDeserializedValue("key", Foo.class))
73+
*
74+
* @param key the key whose associated value is to be returned
75+
* @param clazz the type in which the value should be deserialized to
76+
* @return the value deserialized if all the assertions were successful, null otherwise
77+
*/
78+
static <T> T getDeserializedValue(String key, Class<T> clazz) {
79+
if (key != null && ARGS.containsKey(key)) {
80+
Object constant = ARGS.get(key);
81+
if (constant != null && constant.getClass().isAssignableFrom(clazz)) {
82+
return (T) constant;
83+
}
84+
}
85+
return null;
86+
}
87+
88+
/**
89+
* This acts as a safe get() method.
90+
* It returns the queried raw value if AND ONLY IF it passed the following assertions:
91+
* - {@code key} is not null
92+
* - {@code key} does exist in the registry
93+
* (i.e. Object value = getRawValue("key")
94+
*
95+
* @param key the key whose associated value is to be returned
96+
* @return the value if all the assertions were successful, null otherwise
97+
*/
98+
static Object getRawValue(String key) {
99+
if (key != null) {
100+
return ARGS.get(key);
101+
}
102+
return null;
103+
}
104+
105+
static void registerInstabugInvocationEventsArgs(Map<String, Object> args) {
106+
args.put("invocationEventTwoFingersSwipe", TWO_FINGER_SWIPE_LEFT);
107+
args.put("invocationEventFloatingButton", FLOATING_BUTTON);
108+
args.put("invocationEventScreenshot", SCREENSHOT);
109+
args.put("invocationEventShake", SHAKE);
110+
args.put("invocationEventNone", NONE);
111+
}
112+
113+
static void registerWelcomeMessageArgs(Map<String, Object> args) {
114+
args.put("WelcomeMessageMode.disabled", DISABLED);
115+
args.put("WelcomeMessageMode.live", LIVE);
116+
args.put("WelcomeMessageMode.beta", BETA);
117+
}
118+
119+
static void registerColorThemeArgs(Map<String, Object> args) {
120+
args.put("colorThemeLight", InstabugColorTheme.InstabugColorThemeLight);
121+
args.put("colorThemeDark", InstabugColorTheme.InstabugColorThemeDark);
122+
}
123+
124+
static void registerInvocationModeArgs(Map<String, Object> args) {
125+
args.put("invocationModeNewBug", BugReporting.ReportType.BUG);
126+
args.put("invocationModeNewFeedback", BugReporting.ReportType.FEEDBACK);
127+
}
128+
129+
static void registerInvocationOptionsArgs(Map<String, Object> args) {
130+
args.put("commentFieldRequired", Option.COMMENT_FIELD_REQUIRED);
131+
args.put("disablePostSendingDialog", Option.DISABLE_POST_SENDING_DIALOG);
132+
args.put("emailFieldHidden", Option.EMAIL_FIELD_HIDDEN);
133+
args.put("emailFieldOptional", Option.EMAIL_FIELD_OPTIONAL);
134+
}
135+
136+
static void registerLocaleArgs(Map<String, Object> args) {
137+
args.put("IBGLocale.chineseTraditional", new Locale(TRADITIONAL_CHINESE.getCode(), TRADITIONAL_CHINESE.getCountry()));
138+
args.put("IBGLocale.portuguesePortugal", new Locale(PORTUGUESE_PORTUGAL.getCode(), PORTUGUESE_PORTUGAL.getCountry()));
139+
args.put("IBGLocale.chineseSimplified", new Locale(SIMPLIFIED_CHINESE.getCode(), SIMPLIFIED_CHINESE.getCountry()));
140+
args.put("IBGLocale.portugueseBrazil", new Locale(PORTUGUESE_BRAZIL.getCode(), PORTUGUESE_BRAZIL.getCountry()));
141+
args.put("IBGLocale.indonesian", new Locale(INDONESIAN.getCode(), INDONESIAN.getCountry()));
142+
args.put("IBGLocale.dutch", new Locale(NETHERLANDS.getCode(), NETHERLANDS.getCountry()));
143+
args.put("IBGLocale.norwegian", new Locale(NORWEGIAN.getCode(), NORWEGIAN.getCountry()));
144+
args.put("IBGLocale.japanese", new Locale(JAPANESE.getCode(), JAPANESE.getCountry()));
145+
args.put("IBGLocale.english", new Locale(ENGLISH.getCode(), ENGLISH.getCountry()));
146+
args.put("IBGLocale.italian", new Locale(ITALIAN.getCode(), ITALIAN.getCountry()));
147+
args.put("IBGLocale.russian", new Locale(RUSSIAN.getCode(), RUSSIAN.getCountry()));
148+
args.put("IBGLocale.spanish", new Locale(SPANISH.getCode(), SPANISH.getCountry()));
149+
args.put("IBGLocale.swedish", new Locale(SWEDISH.getCode(), SWEDISH.getCountry()));
150+
args.put("IBGLocale.turkish", new Locale(TURKISH.getCode(), TURKISH.getCountry()));
151+
args.put("IBGLocale.arabic", new Locale(ARABIC.getCode(), ARABIC.getCountry()));
152+
args.put("IBGLocale.danish", new Locale(DANISH.getCode(), DANISH.getCountry()));
153+
args.put("IBGLocale.french", new Locale(FRENCH.getCode(), FRENCH.getCountry()));
154+
args.put("IBGLocale.german", new Locale(GERMAN.getCode(), GERMAN.getCountry()));
155+
args.put("IBGLocale.korean", new Locale(KOREAN.getCode(), KOREAN.getCountry()));
156+
args.put("IBGLocale.polish", new Locale(POLISH.getCode(), POLISH.getCountry()));
157+
args.put("IBGLocale.slovak", new Locale(SLOVAK.getCode(), SLOVAK.getCountry()));
158+
args.put("IBGLocale.czech", new Locale(CZECH.getCode(), CZECH.getCountry()));
159+
}
160+
161+
static void registerCustomTextPlaceHolderKeysArgs(Map<String, Object> args) {
162+
args.put("CustomTextPlaceHolderKey.shakeHint", InstabugCustomTextPlaceHolder.Key.SHAKE_HINT);
163+
args.put("CustomTextPlaceHolderKey.swipeHint", InstabugCustomTextPlaceHolder.Key.SWIPE_HINT);
164+
args.put("CustomTextPlaceHolderKey.invalidEmailMessage", InstabugCustomTextPlaceHolder.Key.INVALID_EMAIL_MESSAGE);
165+
args.put("CustomTextPlaceHolderKey.invalidCommentMessage", InstabugCustomTextPlaceHolder.Key.INVALID_COMMENT_MESSAGE);
166+
args.put("CustomTextPlaceHolderKey.invocationHeader", InstabugCustomTextPlaceHolder.Key.INVOCATION_HEADER);
167+
args.put("CustomTextPlaceHolderKey.startChats", InstabugCustomTextPlaceHolder.Key.START_CHATS);
168+
args.put("CustomTextPlaceHolderKey.reportBug", InstabugCustomTextPlaceHolder.Key.REPORT_BUG);
169+
args.put("CustomTextPlaceHolderKey.reportFeedback", InstabugCustomTextPlaceHolder.Key.REPORT_FEEDBACK);
170+
args.put("CustomTextPlaceHolderKey.emailFieldHint", InstabugCustomTextPlaceHolder.Key.EMAIL_FIELD_HINT);
171+
args.put("CustomTextPlaceHolderKey.commentFieldHintForBugReport", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_BUG_REPORT);
172+
args.put("CustomTextPlaceHolderKey.commentFieldHintForFeedback", InstabugCustomTextPlaceHolder.Key.COMMENT_FIELD_HINT_FOR_FEEDBACK);
173+
args.put("CustomTextPlaceHolderKey.addVoiceMessage", InstabugCustomTextPlaceHolder.Key.ADD_VOICE_MESSAGE);
174+
args.put("CustomTextPlaceHolderKey.addImageFromGallery", InstabugCustomTextPlaceHolder.Key.ADD_IMAGE_FROM_GALLERY);
175+
args.put("CustomTextPlaceHolderKey.addExtraScreenshot", InstabugCustomTextPlaceHolder.Key.ADD_EXTRA_SCREENSHOT);
176+
args.put("CustomTextPlaceHolderKey.conversationsListTitle", InstabugCustomTextPlaceHolder.Key.CONVERSATIONS_LIST_TITLE);
177+
args.put("CustomTextPlaceHolderKey.audioRecordingPermissionDenied", InstabugCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED);
178+
args.put("CustomTextPlaceHolderKey.conversationTextFieldHint", InstabugCustomTextPlaceHolder.Key.CONVERSATION_TEXT_FIELD_HINT);
179+
args.put("CustomTextPlaceHolderKey.bugReportHeader", InstabugCustomTextPlaceHolder.Key.BUG_REPORT_HEADER);
180+
args.put("CustomTextPlaceHolderKey.feedbackReportHeader", InstabugCustomTextPlaceHolder.Key.FEEDBACK_REPORT_HEADER);
181+
args.put("CustomTextPlaceHolderKey.voiceMessagePressAndHoldToRecord", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD);
182+
args.put("CustomTextPlaceHolderKey.voiceMessageReleaseToAttach", InstabugCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH);
183+
args.put("CustomTextPlaceHolderKey.reportSuccessfullySent", InstabugCustomTextPlaceHolder.Key.REPORT_SUCCESSFULLY_SENT);
184+
args.put("CustomTextPlaceHolderKey.successDialogHeader", InstabugCustomTextPlaceHolder.Key.SUCCESS_DIALOG_HEADER);
185+
args.put("CustomTextPlaceHolderKey.addVideo", InstabugCustomTextPlaceHolder.Key.ADD_VIDEO);
186+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageWelcomeStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_TITLE);
187+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageWelcomeStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_WELCOME_STEP_CONTENT);
188+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageHowToReportStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_TITLE);
189+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageHowToReportStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_HOW_TO_REPORT_STEP_CONTENT);
190+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageFinishStepTitle", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_TITLE);
191+
args.put("CustomTextPlaceHolderKey.betaWelcomeMessageFinishStepContent", InstabugCustomTextPlaceHolder.Key.BETA_WELCOME_MESSAGE_FINISH_STEP_CONTENT);
192+
args.put("CustomTextPlaceHolderKey.liveWelcomeMessageTitle", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_TITLE);
193+
args.put("CustomTextPlaceHolderKey.liveWelcomeMessageContent", InstabugCustomTextPlaceHolder.Key.LIVE_WELCOME_MESSAGE_CONTENT);
194+
}
195+
196+
static void registerInstabugReportTypesArgs(Map<String, Object> args) {
197+
args.put("bugReportingReportTypeBug", BugReporting.ReportType.BUG);
198+
args.put("bugReportingReportTypeFeedback", BugReporting.ReportType.FEEDBACK);
199+
}
200+
201+
static void registerInstabugExtendedBugReportModeArgs(Map<String, Object> args) {
202+
args.put("enabledWithRequiredFields", ExtendedBugReport.State.ENABLED_WITH_REQUIRED_FIELDS);
203+
args.put("enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS);
204+
args.put("disabled", ExtendedBugReport.State.DISABLED);
205+
}
206+
207+
static void registerInstabugActionTypesArgs(Map<String, Object> args) {
208+
args.put("ActionType.allActions", ActionType.ALL_ACTIONS);
209+
args.put("ActionType.reportBug", ActionType.REPORT_BUG);
210+
args.put("ActionType.requestNewFeature", ActionType.REQUEST_NEW_FEATURE);
211+
args.put("ActionType.addCommentToFeature", ActionType.ADD_COMMENT_TO_FEATURE);
212+
}
213+
214+
static void registerInstabugVideoRecordingFloatingButtonPositionArgs(Map<String, Object> args) {
215+
args.put("topRight", InstabugVideoRecordingButtonPosition.TOP_RIGHT);
216+
args.put("topLeft", InstabugVideoRecordingButtonPosition.TOP_LEFT);
217+
args.put("bottomRight", InstabugVideoRecordingButtonPosition.BOTTOM_RIGHT);
218+
args.put("bottomLeft", InstabugVideoRecordingButtonPosition.BOTTOM_LEFT);
219+
}
220+
}

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.net.Uri;
66
import android.os.Handler;
77
import android.os.Looper;
8-
import android.util.Log;
98
import android.view.View;
109

1110
import com.facebook.react.bridge.Arguments;
@@ -15,7 +14,6 @@
1514
import com.facebook.react.bridge.ReactMethod;
1615
import com.facebook.react.bridge.ReadableArray;
1716
import com.facebook.react.bridge.ReadableMap;
18-
import com.facebook.react.bridge.ReadableType;
1917
import com.facebook.react.bridge.WritableArray;
2018
import com.facebook.react.bridge.WritableNativeArray;
2119
import com.facebook.react.bridge.WritableMap;
@@ -49,18 +47,14 @@
4947
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
5048
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition;
5149
import com.instabug.library.logging.InstabugLog;
52-
import com.instabug.library.bugreporting.model.ReportCategory;
5350
import com.instabug.library.ui.onboarding.WelcomeMessage;
5451
import com.instabug.library.InstabugCustomTextPlaceHolder;
5552
import com.instabug.library.model.Report;
5653
import com.instabug.library.model.NetworkLog;
57-
import com.instabug.library.user.UserEventParam;
5854
import com.instabug.library.visualusersteps.State;
5955

6056
import com.instabug.reactlibrary.utils.ArrayUtil;
6157
import com.instabug.reactlibrary.utils.ReportUtil;
62-
import com.instabug.reactlibrary.utils.InstabugUtil;
63-
import com.instabug.reactlibrary.utils.MapUtil;
6458
import com.instabug.survey.OnDismissCallback;
6559
import com.instabug.survey.OnShowCallback;
6660
import com.instabug.survey.Survey;
@@ -93,11 +87,11 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
9387
private static final String TAG = RNInstabugReactnativeModule.class.getSimpleName();
9488

9589
//InvocationEvents
96-
private final String INVOCATION_EVENT_NONE = "none";
97-
private final String INVOCATION_EVENT_SHAKE = "shake";
98-
private final String INVOCATION_EVENT_SCREENSHOT = "screenshot";
99-
private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "swipe";
100-
private final String INVOCATION_EVENT_FLOATING_BUTTON = "button";
90+
private final String INVOCATION_EVENT_NONE = "invocationEventNone";
91+
private final String INVOCATION_EVENT_SHAKE = "invocationEventShake";
92+
private final String INVOCATION_EVENT_SCREENSHOT = "invocationEventScreenshot";
93+
private final String INVOCATION_EVENT_TWO_FINGERS_SWIPE = "invocationEventTwoFingersSwipe";
94+
private final String INVOCATION_EVENT_FLOATING_BUTTON = "invocationEventFloatingButton";
10195
//InvocationModes
10296
private final String INVOCATION_MODE_NA = "na";
10397
private final String INVOCATION_MODE_NEW_BUG = "bug";
@@ -715,6 +709,7 @@ public void getUnreadMessagesCount(Callback messageCountCallback) {
715709
}
716710

717711
/**
712+
* @deprecated
718713
* Sets the event used to invoke Instabug SDK
719714
*
720715
* @param invocationEventValue the invocation event value
@@ -1098,6 +1093,7 @@ public void setColorTheme(String theme) {
10981093
}
10991094

11001095
/**
1096+
* @deprecated
11011097
* Sets whether users are required to enter a comment or not when sending reports.
11021098
* Defaults to NO.
11031099
*
@@ -1464,6 +1460,7 @@ public void onDismiss() {
14641460
}
14651461

14661462
/**
1463+
* @deprecated
14671464
* Enable/Disable prompt options when SDK invoked. When only a single option is enabled it
14681465
* becomes the default invocation option that SDK gets invoked with and prompt options screen
14691466
* will not show. When none is enabled, Bug reporting becomes the default invocation option.
@@ -1497,6 +1494,7 @@ public void setPromptOptionsEnabled(boolean chat, boolean bug, boolean feedback)
14971494
}
14981495

14991496
/**
1497+
* @deprecated
15001498
* Sets whether email field is required or not when submitting
15011499
* bug/feedback/new-feature-request/new-comment-on-feature
15021500
*
@@ -1875,7 +1873,7 @@ private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONEx
18751873
}
18761874

18771875
private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
1878-
WritableArray array = new WritableNativeArray();
1876+
WritableArray array = Arguments.createArray();
18791877

18801878
for (int i = 0; i < jsonArray.length(); i++) {
18811879
Object value = jsonArray.get(i);

0 commit comments

Comments
 (0)