diff --git a/src/modules/CrashReporting.ts b/src/modules/CrashReporting.ts index 0eff9140a8..c9b827eeac 100644 --- a/src/modules/CrashReporting.ts +++ b/src/modules/CrashReporting.ts @@ -2,6 +2,7 @@ import { Platform } from 'react-native'; import type { ExtendedError } from 'react-native/Libraries/Core/Devtools/parseErrorStack'; import { NativeCrashReporting } from '../native'; +import type { CrashData } from '../native/CrashReportingNativeModule'; import InstabugUtils from '../utils/InstabugUtils'; /** @@ -31,7 +32,7 @@ export const reportJSException = (error: any) => { export const reportError = (error: ExtendedError) => { const jsStackTrace = InstabugUtils.getStackTrace(error); - const jsonObject = { + const jsonObject: CrashData = { message: error.name + ' - ' + error.message, e_message: error.message, e_name: error.name, diff --git a/src/modules/FeatureRequests.ts b/src/modules/FeatureRequests.ts index 2ac2821a2e..08453a7eec 100644 --- a/src/modules/FeatureRequests.ts +++ b/src/modules/FeatureRequests.ts @@ -23,9 +23,11 @@ export const setEnabled = (isEnabled: boolean) => { */ export const setEmailFieldRequired = ( isEmailFieldRequired: boolean, - types: actionTypes | ActionType, + type: actionTypes | ActionType, ) => { - NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, types); + NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, [ + type, + ] as ActionType[]); }; /** diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index cb7b399563..dd569ebb91 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -564,7 +564,7 @@ export const onNavigationStateChange = ( } _currentScreen = currentScreen; setTimeout(() => { - if (_currentScreen === currentScreen) { + if (currentScreen && _currentScreen === currentScreen) { NativeInstabug.reportScreenChange(currentScreen); _currentScreen = null; } diff --git a/src/modules/Surveys.ts b/src/modules/Surveys.ts index ec6b2a5e68..b66fdbff0b 100644 --- a/src/modules/Surveys.ts +++ b/src/modules/Surveys.ts @@ -1,12 +1,11 @@ import { Platform } from 'react-native'; import { NativeSurveys } from '../native'; +import type { Survey } from '../native/SurveysNativeModule'; import IBGEventEmitter from '../utils/IBGEventEmitter'; import InstabugConstants from '../utils/InstabugConstants'; -export interface Survey { - title: string; -} +export type { Survey }; /** * Sets whether surveys are enabled or not. diff --git a/src/native.ts b/src/native.ts deleted file mode 100644 index d06fff4647..0000000000 --- a/src/native.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { - NativeModule as ReactNativeModule, - NativeModules as ReactNativeModules, -} from 'react-native'; - -export interface NativeModule extends ReactNativeModule, Record { - getConstants: () => Record; -} - -interface InstabugNativeModules { - IBGAPM: NativeModule; - IBGBugReporting: NativeModule; - IBGCrashReporting: NativeModule; - IBGFeatureRequests: NativeModule; - Instabug: NativeModule; - IBGReplies: NativeModule; - IBGSurveys: NativeModule; -} - -export const NativeModules = ReactNativeModules as InstabugNativeModules; - -export const NativeAPM = NativeModules.IBGAPM; -export const NativeBugReporting = NativeModules.IBGBugReporting; -export const NativeCrashReporting = NativeModules.IBGCrashReporting; -export const NativeFeatureRequests = NativeModules.IBGFeatureRequests; -export const NativeInstabug = NativeModules.Instabug; -export const NativeReplies = NativeModules.IBGReplies; -export const NativeSurveys = NativeModules.IBGSurveys; diff --git a/src/native/ApmNativeModule.ts b/src/native/ApmNativeModule.ts new file mode 100644 index 0000000000..f398509ea9 --- /dev/null +++ b/src/native/ApmNativeModule.ts @@ -0,0 +1,30 @@ +import type { NativeModule } from 'react-native'; + +import type { logLevel } from '../utils/ArgsRegistry'; + +export interface ApmNativeModule extends NativeModule { + // Essential APIs // + setEnabled(isEnabled: boolean): void; + + // Network APIs // + networkLog(data: string): void; + + // App Launches APIs // + setAppLaunchEnabled(isEnabled: boolean): void; + endAppLaunch(): void; + + // Execution Traces APIs // + startExecutionTrace(name: string, timestamp: string, callback: (id: string | null) => void): void; + setExecutionTraceAttribute(id: string, key: string, value: string): void; + endExecutionTrace(id: string): void; + + // UI Traces APIs // + setAutoUITraceEnabled(isEnabled: boolean): void; + startUITrace(name: string): void; + endUITrace(): void; + ibgSleep(): void; + + // Deprecated APIs // + /** @deprecated */ + setLogLevel(level: logLevel): void; +} diff --git a/src/native/BugReportingNativeModule.ts b/src/native/BugReportingNativeModule.ts new file mode 100644 index 0000000000..cc4dbe59d1 --- /dev/null +++ b/src/native/BugReportingNativeModule.ts @@ -0,0 +1,59 @@ +import type { NativeModule } from 'react-native'; + +import type { + dismissType, + extendedBugReportMode, + floatingButtonEdge, + invocationEvent, + option, + position, + reportType, +} from '../utils/ArgsRegistry'; +import type { + DismissType, + ExtendedBugReportMode, + FloatingButtonPosition, + InvocationEvent, + InvocationOption, + RecordingButtonPosition, + ReportType, +} from '../utils/Enums'; + +export interface BugReportingNativeModule extends NativeModule { + // Essential APIs // + setEnabled(isEnabled: boolean): void; + show(type: reportType | ReportType, options: option[] | InvocationOption[]): void; + + // Customization APIs // + setInvocationEvents(events: invocationEvent[] | InvocationEvent[]): void; + setOptions(options: option[] | InvocationOption[]): void; + setExtendedBugReportMode(mode: extendedBugReportMode | ExtendedBugReportMode): void; + setReportTypes(types: reportType[] | ReportType[]): void; + setDisclaimerText(text: string): void; + setCommentMinimumCharacterCount(limit: number, reportTypes: reportType[] | ReportType[]): void; + setFloatingButtonEdge(edge: floatingButtonEdge | FloatingButtonPosition, offset: number): void; + setVideoRecordingFloatingButtonPosition(buttonPosition: position | RecordingButtonPosition): void; + setEnabledAttachmentTypes( + screenshot: boolean, + extraScreenshot: boolean, + galleryImage: boolean, + screenRecording: boolean, + ): void; + + // Screen Recording APIs // + setAutoScreenRecordingEnabled(isEnabled: boolean): void; + setAutoScreenRecordingDuration(maxDuration: number): void; + setViewHierarchyEnabled(isEnabled: boolean): void; + + // Shaking Threshold APIs // + setShakingThresholdForiPhone(threshold: number): void; + setShakingThresholdForiPad(threshold: number): void; + setShakingThresholdForAndroid(threshold: number): void; + + // Callbacks // + setOnInvokeHandler(handler: () => void): void; + setDidSelectPromptOptionHandler(handler: (promptOption: string) => void): void; + setOnSDKDismissedHandler( + handler: (dismissType: dismissType | DismissType, reportType: reportType | ReportType) => void, + ): void; +} diff --git a/src/native/CrashReportingNativeModule.ts b/src/native/CrashReportingNativeModule.ts new file mode 100644 index 0000000000..8124c2a0f2 --- /dev/null +++ b/src/native/CrashReportingNativeModule.ts @@ -0,0 +1,17 @@ +import type { NativeModule, Platform } from 'react-native'; +import type { StackFrame } from 'react-native/Libraries/Core/Devtools/parseErrorStack'; + +export interface CrashData { + message: string; + e_message: string; + e_name: string; + os: typeof Platform['OS']; + platform: 'react_native'; + exception: StackFrame[]; +} + +export interface CrashReportingNativeModule extends NativeModule { + setEnabled(isEnabled: boolean): void; + sendJSCrash(data: CrashData | string): void; + sendHandledJSCrash(data: CrashData | string): void; +} diff --git a/src/native/FeatureRequestsNativeModule.ts b/src/native/FeatureRequestsNativeModule.ts new file mode 100644 index 0000000000..6fc8d65291 --- /dev/null +++ b/src/native/FeatureRequestsNativeModule.ts @@ -0,0 +1,13 @@ +import type { NativeModule } from 'react-native'; + +import type { actionTypes } from '../utils/ArgsRegistry'; +import type { ActionType } from '../utils/Enums'; + +export interface FeatureRequestsNativeModule extends NativeModule { + setEnabled(isEnabled: boolean): void; + show(): void; + setEmailFieldRequiredForFeatureRequests( + isEmailFieldRequired: boolean, + types: actionTypes[] | ActionType[], + ): void; +} diff --git a/src/native/InstabugNativeModule.ts b/src/native/InstabugNativeModule.ts new file mode 100644 index 0000000000..ab37e9c6bc --- /dev/null +++ b/src/native/InstabugNativeModule.ts @@ -0,0 +1,122 @@ +import type { NativeModule, ProcessedColorValue } from 'react-native'; + +import type Report from '../models/Report'; +import type { + colorTheme, + invocationEvent, + locale, + reproStepsMode, + sdkDebugLogsLevel, + strings, + welcomeMessageMode, +} from '../utils/ArgsRegistry'; +import type { + ColorTheme, + InvocationEvent, + Locale, + LogLevel, + ReproStepsMode, + StringKey, + WelcomeMessageMode, +} from '../utils/Enums'; +import type { NetworkData } from '../utils/XhrNetworkInterceptor'; +import type { NativeConstants } from './NativeConstants'; + +export interface InstabugNativeModule extends NativeModule { + getConstants(): NativeConstants; + + // Essential APIs // + setEnabled(isEnabled: boolean): void; + init( + token: string, + invocationEvents: InvocationEvent[] | invocationEvent[], + debugLogsLevel: LogLevel, + ): void; + show(): void; + + // Misc APIs // + setIBGLogPrintsToConsole(printsToConsole: boolean): void; + setSessionProfilerEnabled(isEnabled: boolean): void; + + // Customization APIs // + setLocale(sdkLocale: Locale | locale): void; + setColorTheme(sdkTheme: ColorTheme | colorTheme): void; + setPrimaryColor(color: ProcessedColorValue | null | undefined): void; + setString(string: string, key: StringKey | strings): void; + + // Network APIs // + networkLog(network: NetworkData | string): void; + setNetworkLoggingEnabled(isEnabled: boolean): void; + + // Repro Steps APIs // + setReproStepsMode(mode: ReproStepsMode | reproStepsMode): void; + setTrackUserSteps(isEnabled: boolean): void; + reportScreenChange(firstScreen: string): void; + addPrivateView(nativeTag: number | null): void; + removePrivateView(nativeTag: number | null): void; + + // Logging APIs // + logVerbose(message: string): void; + logInfo(message: string): void; + logDebug(message: string): void; + logError(message: string): void; + logWarn(message: string): void; + clearLogs(): void; + + // User APIs // + identifyUser(email: string, name: string): void; + logOut(): void; + logUserEvent(name: string): void; + setUserData(data: string): void; + + // User Attributes APIs // + setUserAttribute(key: string, value: string): void; + getUserAttribute(key: string, callback: (attribute: string) => void): void; + removeUserAttribute(key: string): void; + getAllUserAttributes(callback: (attributes: Record) => void): void; + clearAllUserAttributes(): void; + + // Welcome Message APIs // + showWelcomeMessageWithMode(mode: WelcomeMessageMode | welcomeMessageMode): void; + setWelcomeMessageMode(mode: WelcomeMessageMode | welcomeMessageMode): void; + + // Tags APIs // + appendTags(tags: string[]): void; + resetTags(): void; + getTags(callback: (tags: string[]) => void): void; + + // Experiments APIs // + addExperiments(experiments: string[]): void; + removeExperiments(experiments: string[]): void; + clearAllExperiments(): void; + + // Files APIs // + setFileAttachment(filePath: string, fileName?: string): void; + + // Report APIs // + setPreSendingHandler(handler?: (report: Report) => void): void; + appendTagToReport(tag: string): void; + appendConsoleLogToReport(consoleLog: string): void; + setUserAttributeToReport(key: string, value: string): void; + logDebugToReport(log: string): void; + logVerboseToReport(log: string): void; + logWarnToReport(log: string): void; + logErrorToReport(log: string): void; + logInfoToReport(log: string): void; + addFileAttachmentWithURLToReport(url: string, filename?: string): void; + addFileAttachmentWithDataToReport(data: string, filename?: string): void; + + // Deprecated APIs // + /** @deprecated */ + setSdkDebugLogsLevel(level: sdkDebugLogsLevel): void; + /** @deprecated */ + setDebugEnabled(isEnabled: boolean): void; + /** @deprecated */ + enable(): void; + /** @deprecated */ + disable(): void; + /** @deprecated */ + isRunningLive(callback: (isLive: boolean) => void): void; + /** @deprecated */ + callPrivateApi(apiName: string, param: any[]): void; +} diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts new file mode 100644 index 0000000000..2d754bdbf6 --- /dev/null +++ b/src/native/NativeConstants.ts @@ -0,0 +1,198 @@ +export type NativeConstants = NativeLogLevel & + NativeSdkDebugLogsLevel & + NativeInvocationEvent & + NativeInvocationOption & + NativeColorTheme & + NativeFloatingButtonPosition & + NativeRecordingButtonPosition & + NativeWelcomeMessageMode & + NativeReportType & + NativeDismissType & + NativeDismissType & + NativeActionType & + NativeExtendedBugReportMode & + NativeReproStepsMode & + NativeLocale & + NativeStringKey; + +/** @deprecated */ +interface NativeSdkDebugLogsLevel { + sdkDebugLogsLevelVerbose: any; + sdkDebugLogsLevelDebug: any; + sdkDebugLogsLevelError: any; + sdkDebugLogsLevelNone: any; +} + +interface NativeLogLevel { + logLevelNone: any; + logLevelError: any; + /** @deprecated */ + logLevelWarning: any; + /** @deprecated */ + logLevelInfo: any; + logLevelDebug: any; + logLevelVerbose: any; +} + +interface NativeInvocationEvent { + invocationEventNone: any; + invocationEventShake: any; + invocationEventScreenshot: any; + invocationEventTwoFingersSwipeLeft: any; + invocationEventFloatingButton: any; +} + +interface NativeInvocationOption { + optionEmailFieldHidden: any; + optionEmailFieldOptional: any; + optionCommentFieldRequired: any; + optionDisablePostSendingDialog: any; +} + +interface NativeColorTheme { + colorThemeLight: any; + colorThemeDark: any; +} + +interface NativeFloatingButtonPosition { + rectMinXEdge: any; + rectMaxXEdge: any; +} + +interface NativeRecordingButtonPosition { + bottomRight: any; + topRight: any; + bottomLeft: any; + topLeft: any; +} + +interface NativeWelcomeMessageMode { + welcomeMessageModeLive: any; + welcomeMessageModeBeta: any; + welcomeMessageModeDisabled: any; +} + +interface NativeReportType { + bugReportingReportTypeBug: any; + bugReportingReportTypeFeedback: any; + bugReportingReportTypeQuestion: any; +} + +interface NativeDismissType { + dismissTypeSubmit: any; + dismissTypeCancel: any; + dismissTypeAddAttachment: any; +} + +interface NativeActionType { + allActions: any; + reportBugAction: any; + requestNewFeature: any; + addCommentToFeature: any; +} + +interface NativeExtendedBugReportMode { + enabledWithRequiredFields: any; + enabledWithOptionalFields: any; + disabled: any; +} + +interface NativeReproStepsMode { + reproStepsEnabledWithNoScreenshots: any; + reproStepsEnabled: any; + reproStepsDisabled: any; +} + +interface NativeLocale { + localeArabic: any; + localeAzerbaijani: any; + localeChineseSimplified: any; + localeChineseTraditional: any; + localeCzech: any; + localeDanish: any; + localeDutch: any; + localeEnglish: any; + localeFrench: any; + localeGerman: any; + localeItalian: any; + localeJapanese: any; + localeKorean: any; + localePolish: any; + localePortugueseBrazil: any; + localeRomanian: any; + localeRussian: any; + localeSpanish: any; + localeSwedish: any; + localeTurkish: any; +} + +interface NativeStringKey { + addAttachmentButtonTitleStringName: any; + addExtraScreenshot: any; + addImageFromGallery: any; + addVideoMessage: any; + addVoiceMessage: any; + audio: any; + audioRecordingPermissionDeniedMessage: any; + audioRecordingPermissionDeniedTitle: any; + cancelButtonTitle: any; + collectingDataText: any; + commentFieldHintForBugReport: any; + commentFieldHintForFeedback: any; + commentFieldHintForQuestion: any; + conversationsHeaderTitle: any; + conversationTextFieldHint: any; + discardAlertAction: any; + discardAlertCancel: any; + discardAlertMessage: any; + discardAlertTitle: any; + edgeSwipeStartHint: any; + emailFieldHint: any; + image: any; + insufficientContentMessage: any; + insufficientContentTitle: any; + invalidCommentMessage: any; + invalidCommentTitle: any; + invalidEmailMessage: any; + invalidEmailTitle: any; + invocationHeader: any; + messagesNotification: any; + messagesNotificationAndOthers: any; + microphonePermissionAlertSettingsButtonTitle: any; + okButtonTitle: any; + recordingMessageToHoldText: any; + recordingMessageToReleaseText: any; + reportBug: any; + reportBugDescription: any; + reportFeedback: any; + reportFeedbackDescription: any; + reportQuestion: any; + reportQuestionDescription: any; + reportReproStepsDisclaimerBody: any; + reportReproStepsDisclaimerLink: any; + reproStepsListDescription: any; + reproStepsListEmptyStateDescription: any; + reproStepsListHeader: any; + reproStepsListItemTitle: any; + reproStepsProgressDialogBody: any; + requestFeatureDescription: any; + screenRecording: any; + screenshotHeaderTitle: any; + shakeHint: any; + startAlertText: any; + surveysStoreRatingThanksSubtitle: any; + surveysStoreRatingThanksTitle: any; + swipeHint: any; + team: any; + thankYouAlertText: any; + thankYouText: any; + videoPressRecord: any; + welcomeMessageBetaFinishStepContent: any; + welcomeMessageBetaFinishStepTitle: any; + welcomeMessageBetaHowToReportStepContent: any; + welcomeMessageBetaHowToReportStepTitle: any; + welcomeMessageBetaWelcomeStepContent: any; + welcomeMessageBetaWelcomeStepTitle: any; + welcomeMessageLiveWelcomeStepContent: any; + welcomeMessageLiveWelcomeStepTitle: any; +} diff --git a/src/native/RepliesNativeModule.ts b/src/native/RepliesNativeModule.ts new file mode 100644 index 0000000000..b3db292da8 --- /dev/null +++ b/src/native/RepliesNativeModule.ts @@ -0,0 +1,24 @@ +import type { NativeModule } from 'react-native'; + +export interface RepliesNativeModule extends NativeModule { + // Essential APIs // + setEnabled(isEnabled: boolean): void; + show(): void; + hasChats(callback: (hasChats: boolean) => void): void; + getUnreadRepliesCount(callback: (count: number) => void): void; + + // Callbacks // + setOnNewReplyReceivedHandler(handler: () => void): void; + + // Notifications APIs // + setPushNotificationsEnabled(isEnabled: boolean): void; + setInAppNotificationEnabled(isEnabled: boolean): void; + + // Android Notifications APIs // + setInAppNotificationSound(isEnabled: boolean): void; + setPushNotificationRegistrationToken(token: string): void; + showNotification(data: Record): void; + setNotificationIcon(resourceId: number): void; + setPushNotificationChannelId(id: string): void; + setSystemReplyNotificationSoundEnabled(isEnabled: boolean): void; +} diff --git a/src/native/SurveysNativeModule.ts b/src/native/SurveysNativeModule.ts new file mode 100644 index 0000000000..575a26d3ed --- /dev/null +++ b/src/native/SurveysNativeModule.ts @@ -0,0 +1,26 @@ +import type { NativeModule } from 'react-native'; + +export interface Survey { + title: string; +} + +export interface SurveysNativeModule extends NativeModule { + // Essential APIs // + setEnabled(isEnabled: boolean): void; + setAutoShowingEnabled(autoShowingSurveysEnabled: boolean): void; + showSurvey(surveyToken: string): void; + showSurveysIfAvailable(): void; + getAvailableSurveys(availableSurveysCallback: (surveys: Survey[]) => void): void; + hasRespondedToSurvey( + surveyToken: string, + surveyTokenCallback: (hasResponded: boolean) => void, + ): void; + + // Misc APIs // + setShouldShowWelcomeScreen(shouldShowWelcomeScreen: boolean): void; + setAppStoreURL(appStoreURL: string): void; + + // Callbacks // + setOnShowHandler(onShowHandler: () => void): void; + setOnDismissHandler(onDismissHandler: () => void): void; +} diff --git a/src/native/index.ts b/src/native/index.ts new file mode 100644 index 0000000000..ba89401774 --- /dev/null +++ b/src/native/index.ts @@ -0,0 +1,29 @@ +import { NativeModules as ReactNativeModules } from 'react-native'; + +import type { ApmNativeModule } from './ApmNativeModule'; +import type { BugReportingNativeModule } from './BugReportingNativeModule'; +import type { CrashReportingNativeModule } from './CrashReportingNativeModule'; +import type { FeatureRequestsNativeModule } from './FeatureRequestsNativeModule'; +import type { InstabugNativeModule } from './InstabugNativeModule'; +import type { RepliesNativeModule } from './RepliesNativeModule'; +import type { SurveysNativeModule } from './SurveysNativeModule'; + +export interface InstabugNativePackage { + IBGAPM: ApmNativeModule; + IBGBugReporting: BugReportingNativeModule; + IBGCrashReporting: CrashReportingNativeModule; + IBGFeatureRequests: FeatureRequestsNativeModule; + Instabug: InstabugNativeModule; + IBGReplies: RepliesNativeModule; + IBGSurveys: SurveysNativeModule; +} + +export const NativeModules = ReactNativeModules as InstabugNativePackage; + +export const NativeAPM = NativeModules.IBGAPM; +export const NativeBugReporting = NativeModules.IBGBugReporting; +export const NativeCrashReporting = NativeModules.IBGCrashReporting; +export const NativeFeatureRequests = NativeModules.IBGFeatureRequests; +export const NativeInstabug = NativeModules.Instabug; +export const NativeReplies = NativeModules.IBGReplies; +export const NativeSurveys = NativeModules.IBGSurveys; diff --git a/src/utils/ArgsRegistry.ts b/src/utils/ArgsRegistry.ts index 479d6370f1..028d57039d 100644 --- a/src/utils/ArgsRegistry.ts +++ b/src/utils/ArgsRegistry.ts @@ -1,5 +1,7 @@ import { NativeInstabug } from '../native'; +const constants = NativeInstabug.getConstants(); + /** * @deprecated Pass a `LogLevel` to `debugLogsLevel` in `Instabug.init` instead. * @@ -7,10 +9,10 @@ import { NativeInstabug } from '../native'; * and only affect the logs used to debug the SDK itself. */ export enum sdkDebugLogsLevel { - sdkDebugLogsLevelVerbose = NativeInstabug.sdkDebugLogsLevelVerbose, - sdkDebugLogsLevelDebug = NativeInstabug.sdkDebugLogsLevelDebug, - sdkDebugLogsLevelError = NativeInstabug.sdkDebugLogsLevelError, - sdkDebugLogsLevelNone = NativeInstabug.sdkDebugLogsLevelNone, + sdkDebugLogsLevelVerbose = constants.sdkDebugLogsLevelVerbose, + sdkDebugLogsLevelDebug = constants.sdkDebugLogsLevelDebug, + sdkDebugLogsLevelError = constants.sdkDebugLogsLevelError, + sdkDebugLogsLevelNone = constants.sdkDebugLogsLevelNone, } /** @@ -19,12 +21,12 @@ export enum sdkDebugLogsLevel { * APM Log Level. */ export enum logLevel { - none = NativeInstabug.logLevelNone, - error = NativeInstabug.logLevelError, - warning = NativeInstabug.logLevelWarning, - info = NativeInstabug.logLevelInfo, - debug = NativeInstabug.logLevelDebug, - verbose = NativeInstabug.logLevelVerbose, + none = constants.logLevelNone, + error = constants.logLevelError, + warning = constants.logLevelWarning, + info = constants.logLevelInfo, + debug = constants.logLevelDebug, + verbose = constants.logLevelVerbose, } /** @@ -33,11 +35,11 @@ export enum logLevel { * The event used to invoke the feedback form */ export enum invocationEvent { - none = NativeInstabug.invocationEventNone, - shake = NativeInstabug.invocationEventShake, - screenshot = NativeInstabug.invocationEventScreenshot, - twoFingersSwipe = NativeInstabug.invocationEventTwoFingersSwipeLeft, - floatingButton = NativeInstabug.invocationEventFloatingButton, + none = constants.invocationEventNone, + shake = constants.invocationEventShake, + screenshot = constants.invocationEventScreenshot, + twoFingersSwipe = constants.invocationEventTwoFingersSwipeLeft, + floatingButton = constants.invocationEventFloatingButton, } /** @@ -46,10 +48,10 @@ export enum invocationEvent { * Options added while invoking bug reporting. */ export enum option { - emailFieldHidden = NativeInstabug.optionEmailFieldHidden, - emailFieldOptional = NativeInstabug.optionEmailFieldOptional, - commentFieldRequired = NativeInstabug.optionCommentFieldRequired, - disablePostSendingDialog = NativeInstabug.optionDisablePostSendingDialog, + emailFieldHidden = constants.optionEmailFieldHidden, + emailFieldOptional = constants.optionEmailFieldOptional, + commentFieldRequired = constants.optionCommentFieldRequired, + disablePostSendingDialog = constants.optionDisablePostSendingDialog, } /** @@ -58,8 +60,8 @@ export enum option { * The color theme of the different UI elements */ export enum colorTheme { - light = NativeInstabug.colorThemeLight, - dark = NativeInstabug.colorThemeDark, + light = constants.colorThemeLight, + dark = constants.colorThemeDark, } /** @@ -68,32 +70,32 @@ export enum colorTheme { * Floating Button edges */ export enum floatingButtonEdge { - left = NativeInstabug.rectMinXEdge, - right = NativeInstabug.rectMaxXEdge, + left = constants.rectMinXEdge, + right = constants.rectMaxXEdge, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeInstabug floating buttons positions. + * constants floating buttons positions. */ export enum position { - bottomRight = NativeInstabug.bottomRight, - topRight = NativeInstabug.topRight, - bottomLeft = NativeInstabug.bottomLeft, - topLeft = NativeInstabug.topLeft, + bottomRight = constants.bottomRight, + topRight = constants.topRight, + bottomLeft = constants.bottomLeft, + topLeft = constants.topLeft, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeInstabug floating buttons positions. + * constants floating buttons positions. */ export enum IBGPosition { - bottomRight = NativeInstabug.bottomRight, - topRight = NativeInstabug.topRight, - bottomLeft = NativeInstabug.bottomLeft, - topLeft = NativeInstabug.topLeft, + bottomRight = constants.bottomRight, + topRight = constants.topRight, + bottomLeft = constants.bottomLeft, + topLeft = constants.topLeft, } /** @@ -102,9 +104,9 @@ export enum IBGPosition { * The welcome message mode. */ export enum welcomeMessageMode { - live = NativeInstabug.welcomeMessageModeLive, - beta = NativeInstabug.welcomeMessageModeBeta, - disabled = NativeInstabug.welcomeMessageModeDisabled, + live = constants.welcomeMessageModeLive, + beta = constants.welcomeMessageModeBeta, + disabled = constants.welcomeMessageModeDisabled, } /** @@ -113,9 +115,9 @@ export enum welcomeMessageMode { * Type of the report either feedback or bug. */ export enum reportType { - bug = NativeInstabug.bugReportingReportTypeBug, - feedback = NativeInstabug.bugReportingReportTypeFeedback, - question = NativeInstabug.bugReportingReportTypeQuestion, + bug = constants.bugReportingReportTypeBug, + feedback = constants.bugReportingReportTypeFeedback, + question = constants.bugReportingReportTypeQuestion, } /** @@ -124,21 +126,21 @@ export enum reportType { * Type of SDK dismiss */ export enum dismissType { - submit = NativeInstabug.dismissTypeSubmit, - cancel = NativeInstabug.dismissTypeCancel, - addAttachment = NativeInstabug.dismissTypeAddAttachment, + submit = constants.dismissTypeSubmit, + cancel = constants.dismissTypeCancel, + addAttachment = constants.dismissTypeAddAttachment, } /** * @deprecated Use `ActionType` instead. * - * NativeInstabug action types. + * constants action types. */ export enum actionTypes { - allActions = NativeInstabug.allActions, - reportBug = NativeInstabug.reportBugAction, - requestNewFeature = NativeInstabug.requestNewFeature, - addCommentToFeature = NativeInstabug.addCommentToFeature, + allActions = constants.allActions, + reportBug = constants.reportBugAction, + requestNewFeature = constants.requestNewFeature, + addCommentToFeature = constants.addCommentToFeature, } /** @@ -147,9 +149,9 @@ export enum actionTypes { * The extended bug report mode */ export enum extendedBugReportMode { - enabledWithRequiredFields = NativeInstabug.enabledWithRequiredFields, - enabledWithOptionalFields = NativeInstabug.enabledWithOptionalFields, - disabled = NativeInstabug.disabled, + enabledWithRequiredFields = constants.enabledWithRequiredFields, + enabledWithOptionalFields = constants.enabledWithOptionalFields, + disabled = constants.disabled, } /** @@ -158,9 +160,9 @@ export enum extendedBugReportMode { * The user steps option. */ export enum reproStepsMode { - enabled = NativeInstabug.reproStepsEnabled, - disabled = NativeInstabug.reproStepsDisabled, - enabledWithNoScreenshots = NativeInstabug.reproStepsEnabledWithNoScreenshots, + enabled = constants.reproStepsEnabled, + disabled = constants.reproStepsDisabled, + enabledWithNoScreenshots = constants.reproStepsEnabledWithNoScreenshots, } /** @@ -169,100 +171,100 @@ export enum reproStepsMode { * The supported locales */ export enum locale { - arabic = NativeInstabug.localeArabic, - azerbaijani = NativeInstabug.localeAzerbaijani, - chineseSimplified = NativeInstabug.localeChineseSimplified, - chineseTraditional = NativeInstabug.localeChineseTraditional, - czech = NativeInstabug.localeCzech, - danish = NativeInstabug.localeDanish, - dutch = NativeInstabug.localeDutch, - english = NativeInstabug.localeEnglish, - french = NativeInstabug.localeFrench, - german = NativeInstabug.localeGerman, - italian = NativeInstabug.localeItalian, - japanese = NativeInstabug.localeJapanese, - korean = NativeInstabug.localeKorean, - polish = NativeInstabug.localePolish, - portugueseBrazil = NativeInstabug.localePortugueseBrazil, - romanian = NativeInstabug.localeRomanian, - russian = NativeInstabug.localeRussian, - spanish = NativeInstabug.localeSpanish, - swedish = NativeInstabug.localeSwedish, - turkish = NativeInstabug.localeTurkish, + arabic = constants.localeArabic, + azerbaijani = constants.localeAzerbaijani, + chineseSimplified = constants.localeChineseSimplified, + chineseTraditional = constants.localeChineseTraditional, + czech = constants.localeCzech, + danish = constants.localeDanish, + dutch = constants.localeDutch, + english = constants.localeEnglish, + french = constants.localeFrench, + german = constants.localeGerman, + italian = constants.localeItalian, + japanese = constants.localeJapanese, + korean = constants.localeKorean, + polish = constants.localePolish, + portugueseBrazil = constants.localePortugueseBrazil, + romanian = constants.localeRomanian, + russian = constants.localeRussian, + spanish = constants.localeSpanish, + swedish = constants.localeSwedish, + turkish = constants.localeTurkish, } /** * @deprecated Use `StringKey` instead. * - * NativeInstabug strings + * constants strings */ export enum strings { - shakeHint = NativeInstabug.shakeHint, - swipeHint = NativeInstabug.swipeHint, - edgeSwipeStartHint = NativeInstabug.edgeSwipeStartHint, - startAlertText = NativeInstabug.startAlertText, - invalidEmailMessage = NativeInstabug.invalidEmailMessage, - invalidEmailTitle = NativeInstabug.invalidEmailTitle, - invalidCommentMessage = NativeInstabug.invalidCommentMessage, - invalidCommentTitle = NativeInstabug.invalidCommentTitle, - invocationHeader = NativeInstabug.invocationHeader, - reportQuestion = NativeInstabug.reportQuestion, - reportBug = NativeInstabug.reportBug, - reportFeedback = NativeInstabug.reportFeedback, - emailFieldHint = NativeInstabug.emailFieldHint, - commentFieldHintForBugReport = NativeInstabug.commentFieldHintForBugReport, - commentFieldHintForFeedback = NativeInstabug.commentFieldHintForFeedback, - commentFieldHintForQuestion = NativeInstabug.commentFieldHintForQuestion, - videoPressRecord = NativeInstabug.videoPressRecord, - addVideoMessage = NativeInstabug.addVideoMessage, - addVoiceMessage = NativeInstabug.addVoiceMessage, - addImageFromGallery = NativeInstabug.addImageFromGallery, - addExtraScreenshot = NativeInstabug.addExtraScreenshot, - audioRecordingPermissionDeniedTitle = NativeInstabug.audioRecordingPermissionDeniedTitle, - audioRecordingPermissionDeniedMessage = NativeInstabug.audioRecordingPermissionDeniedMessage, - microphonePermissionAlertSettingsButtonText = NativeInstabug.microphonePermissionAlertSettingsButtonTitle, - recordingMessageToHoldText = NativeInstabug.recordingMessageToHoldText, - recordingMessageToReleaseText = NativeInstabug.recordingMessageToReleaseText, - conversationsHeaderTitle = NativeInstabug.conversationsHeaderTitle, - screenshotHeaderTitle = NativeInstabug.screenshotHeaderTitle, - okButtonText = NativeInstabug.okButtonTitle, - cancelButtonText = NativeInstabug.cancelButtonTitle, - thankYouText = NativeInstabug.thankYouText, - audio = NativeInstabug.audio, - image = NativeInstabug.image, - team = NativeInstabug.team, - messagesNotification = NativeInstabug.messagesNotification, - messagesNotificationAndOthers = NativeInstabug.messagesNotificationAndOthers, - conversationTextFieldHint = NativeInstabug.conversationTextFieldHint, - collectingDataText = NativeInstabug.collectingDataText, - thankYouAlertText = NativeInstabug.thankYouAlertText, - welcomeMessageBetaWelcomeStepTitle = NativeInstabug.welcomeMessageBetaWelcomeStepTitle, - welcomeMessageBetaWelcomeStepContent = NativeInstabug.welcomeMessageBetaWelcomeStepContent, - welcomeMessageBetaHowToReportStepTitle = NativeInstabug.welcomeMessageBetaHowToReportStepTitle, - welcomeMessageBetaHowToReportStepContent = NativeInstabug.welcomeMessageBetaHowToReportStepContent, - welcomeMessageBetaFinishStepTitle = NativeInstabug.welcomeMessageBetaFinishStepTitle, - welcomeMessageBetaFinishStepContent = NativeInstabug.welcomeMessageBetaFinishStepContent, - welcomeMessageLiveWelcomeStepTitle = NativeInstabug.welcomeMessageLiveWelcomeStepTitle, - welcomeMessageLiveWelcomeStepContent = NativeInstabug.welcomeMessageLiveWelcomeStepContent, - surveysStoreRatingThanksTitle = NativeInstabug.surveysStoreRatingThanksTitle, - surveysStoreRatingThanksSubtitle = NativeInstabug.surveysStoreRatingThanksSubtitle, - reportBugDescription = NativeInstabug.reportBugDescription, - reportFeedbackDescription = NativeInstabug.reportFeedbackDescription, - reportQuestionDescription = NativeInstabug.reportQuestionDescription, - requestFeatureDescription = NativeInstabug.requestFeatureDescription, - discardAlertTitle = NativeInstabug.discardAlertTitle, - discardAlertMessage = NativeInstabug.discardAlertMessage, - discardAlertCancel = NativeInstabug.discardAlertCancel, - discardAlertAction = NativeInstabug.discardAlertAction, - addAttachmentButtonTitleStringName = NativeInstabug.addAttachmentButtonTitleStringName, - reportReproStepsDisclaimerBody = NativeInstabug.reportReproStepsDisclaimerBody, - reportReproStepsDisclaimerLink = NativeInstabug.reportReproStepsDisclaimerLink, - reproStepsProgressDialogBody = NativeInstabug.reproStepsProgressDialogBody, - reproStepsListHeader = NativeInstabug.reproStepsListHeader, - reproStepsListDescription = NativeInstabug.reproStepsListDescription, - reproStepsListEmptyStateDescription = NativeInstabug.reproStepsListEmptyStateDescription, - reproStepsListItemTitle = NativeInstabug.reproStepsListItemTitle, - screenRecording = NativeInstabug.screenRecording, - insufficientContentMessage = NativeInstabug.insufficientContentMessage, - insufficientContentTitle = NativeInstabug.insufficientContentTitle, + shakeHint = constants.shakeHint, + swipeHint = constants.swipeHint, + edgeSwipeStartHint = constants.edgeSwipeStartHint, + startAlertText = constants.startAlertText, + invalidEmailMessage = constants.invalidEmailMessage, + invalidEmailTitle = constants.invalidEmailTitle, + invalidCommentMessage = constants.invalidCommentMessage, + invalidCommentTitle = constants.invalidCommentTitle, + invocationHeader = constants.invocationHeader, + reportQuestion = constants.reportQuestion, + reportBug = constants.reportBug, + reportFeedback = constants.reportFeedback, + emailFieldHint = constants.emailFieldHint, + commentFieldHintForBugReport = constants.commentFieldHintForBugReport, + commentFieldHintForFeedback = constants.commentFieldHintForFeedback, + commentFieldHintForQuestion = constants.commentFieldHintForQuestion, + videoPressRecord = constants.videoPressRecord, + addVideoMessage = constants.addVideoMessage, + addVoiceMessage = constants.addVoiceMessage, + addImageFromGallery = constants.addImageFromGallery, + addExtraScreenshot = constants.addExtraScreenshot, + audioRecordingPermissionDeniedTitle = constants.audioRecordingPermissionDeniedTitle, + audioRecordingPermissionDeniedMessage = constants.audioRecordingPermissionDeniedMessage, + microphonePermissionAlertSettingsButtonText = constants.microphonePermissionAlertSettingsButtonTitle, + recordingMessageToHoldText = constants.recordingMessageToHoldText, + recordingMessageToReleaseText = constants.recordingMessageToReleaseText, + conversationsHeaderTitle = constants.conversationsHeaderTitle, + screenshotHeaderTitle = constants.screenshotHeaderTitle, + okButtonText = constants.okButtonTitle, + cancelButtonText = constants.cancelButtonTitle, + thankYouText = constants.thankYouText, + audio = constants.audio, + image = constants.image, + team = constants.team, + messagesNotification = constants.messagesNotification, + messagesNotificationAndOthers = constants.messagesNotificationAndOthers, + conversationTextFieldHint = constants.conversationTextFieldHint, + collectingDataText = constants.collectingDataText, + thankYouAlertText = constants.thankYouAlertText, + welcomeMessageBetaWelcomeStepTitle = constants.welcomeMessageBetaWelcomeStepTitle, + welcomeMessageBetaWelcomeStepContent = constants.welcomeMessageBetaWelcomeStepContent, + welcomeMessageBetaHowToReportStepTitle = constants.welcomeMessageBetaHowToReportStepTitle, + welcomeMessageBetaHowToReportStepContent = constants.welcomeMessageBetaHowToReportStepContent, + welcomeMessageBetaFinishStepTitle = constants.welcomeMessageBetaFinishStepTitle, + welcomeMessageBetaFinishStepContent = constants.welcomeMessageBetaFinishStepContent, + welcomeMessageLiveWelcomeStepTitle = constants.welcomeMessageLiveWelcomeStepTitle, + welcomeMessageLiveWelcomeStepContent = constants.welcomeMessageLiveWelcomeStepContent, + surveysStoreRatingThanksTitle = constants.surveysStoreRatingThanksTitle, + surveysStoreRatingThanksSubtitle = constants.surveysStoreRatingThanksSubtitle, + reportBugDescription = constants.reportBugDescription, + reportFeedbackDescription = constants.reportFeedbackDescription, + reportQuestionDescription = constants.reportQuestionDescription, + requestFeatureDescription = constants.requestFeatureDescription, + discardAlertTitle = constants.discardAlertTitle, + discardAlertMessage = constants.discardAlertMessage, + discardAlertCancel = constants.discardAlertCancel, + discardAlertAction = constants.discardAlertAction, + addAttachmentButtonTitleStringName = constants.addAttachmentButtonTitleStringName, + reportReproStepsDisclaimerBody = constants.reportReproStepsDisclaimerBody, + reportReproStepsDisclaimerLink = constants.reportReproStepsDisclaimerLink, + reproStepsProgressDialogBody = constants.reproStepsProgressDialogBody, + reproStepsListHeader = constants.reproStepsListHeader, + reproStepsListDescription = constants.reproStepsListDescription, + reproStepsListEmptyStateDescription = constants.reproStepsListEmptyStateDescription, + reproStepsListItemTitle = constants.reproStepsListItemTitle, + screenRecording = constants.screenRecording, + insufficientContentMessage = constants.insufficientContentMessage, + insufficientContentTitle = constants.insufficientContentTitle, } diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index c322b77bfb..e5f3fcaae0 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -1,216 +1,216 @@ import { NativeInstabug } from '../native'; -const NativeConstants = NativeInstabug.getConstants(); +const constants = NativeInstabug.getConstants(); /** * Verbosity level of the SDK debug logs. This has nothing to do with `Instabug.log`, * and only affect the logs used to debug the SDK itself. */ export enum LogLevel { - verbose = NativeConstants.sdkDebugLogsLevelVerbose, - debug = NativeConstants.sdkDebugLogsLevelDebug, - error = NativeConstants.sdkDebugLogsLevelError, - none = NativeConstants.sdkDebugLogsLevelNone, + verbose = constants.sdkDebugLogsLevelVerbose, + debug = constants.sdkDebugLogsLevelDebug, + error = constants.sdkDebugLogsLevelError, + none = constants.sdkDebugLogsLevelNone, } /** * The event used to invoke the feedback form. */ export enum InvocationEvent { - none = NativeConstants.invocationEventNone, - shake = NativeConstants.invocationEventShake, - screenshot = NativeConstants.invocationEventScreenshot, - twoFingersSwipe = NativeConstants.invocationEventTwoFingersSwipeLeft, - floatingButton = NativeConstants.invocationEventFloatingButton, + none = constants.invocationEventNone, + shake = constants.invocationEventShake, + screenshot = constants.invocationEventScreenshot, + twoFingersSwipe = constants.invocationEventTwoFingersSwipeLeft, + floatingButton = constants.invocationEventFloatingButton, } /** * Options added while invoking bug reporting. */ export enum InvocationOption { - emailFieldHidden = NativeConstants.optionEmailFieldHidden, - emailFieldOptional = NativeConstants.optionEmailFieldOptional, - commentFieldRequired = NativeConstants.optionCommentFieldRequired, - disablePostSendingDialog = NativeConstants.optionDisablePostSendingDialog, + emailFieldHidden = constants.optionEmailFieldHidden, + emailFieldOptional = constants.optionEmailFieldOptional, + commentFieldRequired = constants.optionCommentFieldRequired, + disablePostSendingDialog = constants.optionDisablePostSendingDialog, } /** * The color theme of the different UI elements. */ export enum ColorTheme { - light = NativeConstants.colorThemeLight, - dark = NativeConstants.colorThemeDark, + light = constants.colorThemeLight, + dark = constants.colorThemeDark, } /** * Floating button positions. */ export enum FloatingButtonPosition { - left = NativeConstants.rectMinXEdge, - right = NativeConstants.rectMaxXEdge, + left = constants.rectMinXEdge, + right = constants.rectMaxXEdge, } /** * Video recording button positions. */ export enum RecordingButtonPosition { - bottomRight = NativeConstants.bottomRight, - topRight = NativeConstants.topRight, - bottomLeft = NativeConstants.bottomLeft, - topLeft = NativeConstants.topLeft, + bottomRight = constants.bottomRight, + topRight = constants.topRight, + bottomLeft = constants.bottomLeft, + topLeft = constants.topLeft, } /** * The welcome message mode. */ export enum WelcomeMessageMode { - live = NativeConstants.welcomeMessageModeLive, - beta = NativeConstants.welcomeMessageModeBeta, - disabled = NativeConstants.welcomeMessageModeDisabled, + live = constants.welcomeMessageModeLive, + beta = constants.welcomeMessageModeBeta, + disabled = constants.welcomeMessageModeDisabled, } /** * Type of the report either feedback or bug. */ export enum ReportType { - bug = NativeConstants.bugReportingReportTypeBug, - feedback = NativeConstants.bugReportingReportTypeFeedback, - question = NativeConstants.bugReportingReportTypeQuestion, + bug = constants.bugReportingReportTypeBug, + feedback = constants.bugReportingReportTypeFeedback, + question = constants.bugReportingReportTypeQuestion, } /** * Type of SDK dismiss. */ export enum DismissType { - submit = NativeConstants.dismissTypeSubmit, - cancel = NativeConstants.dismissTypeCancel, - addAttachment = NativeConstants.dismissTypeAddAttachment, + submit = constants.dismissTypeSubmit, + cancel = constants.dismissTypeCancel, + addAttachment = constants.dismissTypeAddAttachment, } /** * Types of possible actions inside Feature Requests. */ export enum ActionType { - all = NativeConstants.allActions, - reportBug = NativeConstants.reportBugAction, - requestNewFeature = NativeConstants.requestNewFeature, - addCommentToFeature = NativeConstants.addCommentToFeature, + all = constants.allActions, + reportBug = constants.reportBugAction, + requestNewFeature = constants.requestNewFeature, + addCommentToFeature = constants.addCommentToFeature, } /** * The extended bug report mode. */ export enum ExtendedBugReportMode { - enabledWithRequiredFields = NativeConstants.enabledWithRequiredFields, - enabledWithOptionalFields = NativeConstants.enabledWithOptionalFields, - disabled = NativeConstants.disabled, + enabledWithRequiredFields = constants.enabledWithRequiredFields, + enabledWithOptionalFields = constants.enabledWithOptionalFields, + disabled = constants.disabled, } /** * The user steps option. */ export enum ReproStepsMode { - enabledWithNoScreenshots = NativeConstants.reproStepsEnabledWithNoScreenshots, - enabled = NativeConstants.reproStepsEnabled, - disabled = NativeConstants.reproStepsDisabled, + enabledWithNoScreenshots = constants.reproStepsEnabledWithNoScreenshots, + enabled = constants.reproStepsEnabled, + disabled = constants.reproStepsDisabled, } /** * Supported locales */ export enum Locale { - arabic = NativeConstants.localeArabic, - azerbaijani = NativeConstants.localeAzerbaijani, - chineseSimplified = NativeConstants.localeChineseSimplified, - chineseTraditional = NativeConstants.localeChineseTraditional, - czech = NativeConstants.localeCzech, - danish = NativeConstants.localeDanish, - dutch = NativeConstants.localeDutch, - english = NativeConstants.localeEnglish, - french = NativeConstants.localeFrench, - german = NativeConstants.localeGerman, - italian = NativeConstants.localeItalian, - japanese = NativeConstants.localeJapanese, - korean = NativeConstants.localeKorean, - polish = NativeConstants.localePolish, - portugueseBrazil = NativeConstants.localePortugueseBrazil, - romanian = NativeConstants.localeRomanian, - russian = NativeConstants.localeRussian, - spanish = NativeConstants.localeSpanish, - swedish = NativeConstants.localeSwedish, - turkish = NativeConstants.localeTurkish, + arabic = constants.localeArabic, + azerbaijani = constants.localeAzerbaijani, + chineseSimplified = constants.localeChineseSimplified, + chineseTraditional = constants.localeChineseTraditional, + czech = constants.localeCzech, + danish = constants.localeDanish, + dutch = constants.localeDutch, + english = constants.localeEnglish, + french = constants.localeFrench, + german = constants.localeGerman, + italian = constants.localeItalian, + japanese = constants.localeJapanese, + korean = constants.localeKorean, + polish = constants.localePolish, + portugueseBrazil = constants.localePortugueseBrazil, + romanian = constants.localeRomanian, + russian = constants.localeRussian, + spanish = constants.localeSpanish, + swedish = constants.localeSwedish, + turkish = constants.localeTurkish, } /** * Overridable strings in Instabug's UI */ export enum StringKey { - addAttachmentButtonTitleStringName = NativeConstants.addAttachmentButtonTitleStringName, - addExtraScreenshot = NativeConstants.addExtraScreenshot, - addImageFromGallery = NativeConstants.addImageFromGallery, - addVideoMessage = NativeConstants.addVideoMessage, - addVoiceMessage = NativeConstants.addVoiceMessage, - audio = NativeConstants.audio, - audioRecordingPermissionDeniedMessage = NativeConstants.audioRecordingPermissionDeniedMessage, - audioRecordingPermissionDeniedTitle = NativeConstants.audioRecordingPermissionDeniedTitle, - cancelButtonText = NativeConstants.cancelButtonTitle, - collectingDataText = NativeConstants.collectingDataText, - commentFieldHintForBugReport = NativeConstants.commentFieldHintForBugReport, - commentFieldHintForFeedback = NativeConstants.commentFieldHintForFeedback, - commentFieldHintForQuestion = NativeConstants.commentFieldHintForQuestion, - conversationsHeaderTitle = NativeConstants.conversationsHeaderTitle, - conversationTextFieldHint = NativeConstants.conversationTextFieldHint, - discardAlertAction = NativeConstants.discardAlertAction, - discardAlertCancel = NativeConstants.discardAlertCancel, - discardAlertMessage = NativeConstants.discardAlertMessage, - discardAlertTitle = NativeConstants.discardAlertTitle, - edgeSwipeStartHint = NativeConstants.edgeSwipeStartHint, - emailFieldHint = NativeConstants.emailFieldHint, - image = NativeConstants.image, - insufficientContentMessage = NativeConstants.insufficientContentMessage, - insufficientContentTitle = NativeConstants.insufficientContentTitle, - invalidCommentMessage = NativeConstants.invalidCommentMessage, - invalidCommentTitle = NativeConstants.invalidCommentTitle, - invalidEmailMessage = NativeConstants.invalidEmailMessage, - invalidEmailTitle = NativeConstants.invalidEmailTitle, - invocationHeader = NativeConstants.invocationHeader, - messagesNotification = NativeConstants.messagesNotification, - messagesNotificationAndOthers = NativeConstants.messagesNotificationAndOthers, - microphonePermissionAlertSettingsButtonText = NativeConstants.microphonePermissionAlertSettingsButtonTitle, - okButtonText = NativeConstants.okButtonTitle, - recordingMessageToHoldText = NativeConstants.recordingMessageToHoldText, - recordingMessageToReleaseText = NativeConstants.recordingMessageToReleaseText, - reportBug = NativeConstants.reportBug, - reportBugDescription = NativeConstants.reportBugDescription, - reportFeedback = NativeConstants.reportFeedback, - reportFeedbackDescription = NativeConstants.reportFeedbackDescription, - reportQuestion = NativeConstants.reportQuestion, - reportQuestionDescription = NativeConstants.reportQuestionDescription, - reportReproStepsDisclaimerBody = NativeConstants.reportReproStepsDisclaimerBody, - reportReproStepsDisclaimerLink = NativeConstants.reportReproStepsDisclaimerLink, - reproStepsListDescription = NativeConstants.reproStepsListDescription, - reproStepsListEmptyStateDescription = NativeConstants.reproStepsListEmptyStateDescription, - reproStepsListHeader = NativeConstants.reproStepsListHeader, - reproStepsListItemTitle = NativeConstants.reproStepsListItemTitle, - reproStepsProgressDialogBody = NativeConstants.reproStepsProgressDialogBody, - requestFeatureDescription = NativeConstants.requestFeatureDescription, - screenRecording = NativeConstants.screenRecording, - screenshotHeaderTitle = NativeConstants.screenshotHeaderTitle, - shakeHint = NativeConstants.shakeHint, - startAlertText = NativeConstants.startAlertText, - surveysStoreRatingThanksSubtitle = NativeConstants.surveysStoreRatingThanksSubtitle, - surveysStoreRatingThanksTitle = NativeConstants.surveysStoreRatingThanksTitle, - swipeHint = NativeConstants.swipeHint, - team = NativeConstants.team, - thankYouAlertText = NativeConstants.thankYouAlertText, - thankYouText = NativeConstants.thankYouText, - videoPressRecord = NativeConstants.videoPressRecord, - welcomeMessageBetaFinishStepContent = NativeConstants.welcomeMessageBetaFinishStepContent, - welcomeMessageBetaFinishStepTitle = NativeConstants.welcomeMessageBetaFinishStepTitle, - welcomeMessageBetaHowToReportStepContent = NativeConstants.welcomeMessageBetaHowToReportStepContent, - welcomeMessageBetaHowToReportStepTitle = NativeConstants.welcomeMessageBetaHowToReportStepTitle, - welcomeMessageBetaWelcomeStepContent = NativeConstants.welcomeMessageBetaWelcomeStepContent, - welcomeMessageBetaWelcomeStepTitle = NativeConstants.welcomeMessageBetaWelcomeStepTitle, - welcomeMessageLiveWelcomeStepContent = NativeConstants.welcomeMessageLiveWelcomeStepContent, - welcomeMessageLiveWelcomeStepTitle = NativeConstants.welcomeMessageLiveWelcomeStepTitle, + addAttachmentButtonTitleStringName = constants.addAttachmentButtonTitleStringName, + addExtraScreenshot = constants.addExtraScreenshot, + addImageFromGallery = constants.addImageFromGallery, + addVideoMessage = constants.addVideoMessage, + addVoiceMessage = constants.addVoiceMessage, + audio = constants.audio, + audioRecordingPermissionDeniedMessage = constants.audioRecordingPermissionDeniedMessage, + audioRecordingPermissionDeniedTitle = constants.audioRecordingPermissionDeniedTitle, + cancelButtonText = constants.cancelButtonTitle, + collectingDataText = constants.collectingDataText, + commentFieldHintForBugReport = constants.commentFieldHintForBugReport, + commentFieldHintForFeedback = constants.commentFieldHintForFeedback, + commentFieldHintForQuestion = constants.commentFieldHintForQuestion, + conversationsHeaderTitle = constants.conversationsHeaderTitle, + conversationTextFieldHint = constants.conversationTextFieldHint, + discardAlertAction = constants.discardAlertAction, + discardAlertCancel = constants.discardAlertCancel, + discardAlertMessage = constants.discardAlertMessage, + discardAlertTitle = constants.discardAlertTitle, + edgeSwipeStartHint = constants.edgeSwipeStartHint, + emailFieldHint = constants.emailFieldHint, + image = constants.image, + insufficientContentMessage = constants.insufficientContentMessage, + insufficientContentTitle = constants.insufficientContentTitle, + invalidCommentMessage = constants.invalidCommentMessage, + invalidCommentTitle = constants.invalidCommentTitle, + invalidEmailMessage = constants.invalidEmailMessage, + invalidEmailTitle = constants.invalidEmailTitle, + invocationHeader = constants.invocationHeader, + messagesNotification = constants.messagesNotification, + messagesNotificationAndOthers = constants.messagesNotificationAndOthers, + microphonePermissionAlertSettingsButtonText = constants.microphonePermissionAlertSettingsButtonTitle, + okButtonText = constants.okButtonTitle, + recordingMessageToHoldText = constants.recordingMessageToHoldText, + recordingMessageToReleaseText = constants.recordingMessageToReleaseText, + reportBug = constants.reportBug, + reportBugDescription = constants.reportBugDescription, + reportFeedback = constants.reportFeedback, + reportFeedbackDescription = constants.reportFeedbackDescription, + reportQuestion = constants.reportQuestion, + reportQuestionDescription = constants.reportQuestionDescription, + reportReproStepsDisclaimerBody = constants.reportReproStepsDisclaimerBody, + reportReproStepsDisclaimerLink = constants.reportReproStepsDisclaimerLink, + reproStepsListDescription = constants.reproStepsListDescription, + reproStepsListEmptyStateDescription = constants.reproStepsListEmptyStateDescription, + reproStepsListHeader = constants.reproStepsListHeader, + reproStepsListItemTitle = constants.reproStepsListItemTitle, + reproStepsProgressDialogBody = constants.reproStepsProgressDialogBody, + requestFeatureDescription = constants.requestFeatureDescription, + screenRecording = constants.screenRecording, + screenshotHeaderTitle = constants.screenshotHeaderTitle, + shakeHint = constants.shakeHint, + startAlertText = constants.startAlertText, + surveysStoreRatingThanksSubtitle = constants.surveysStoreRatingThanksSubtitle, + surveysStoreRatingThanksTitle = constants.surveysStoreRatingThanksTitle, + swipeHint = constants.swipeHint, + team = constants.team, + thankYouAlertText = constants.thankYouAlertText, + thankYouText = constants.thankYouText, + videoPressRecord = constants.videoPressRecord, + welcomeMessageBetaFinishStepContent = constants.welcomeMessageBetaFinishStepContent, + welcomeMessageBetaFinishStepTitle = constants.welcomeMessageBetaFinishStepTitle, + welcomeMessageBetaHowToReportStepContent = constants.welcomeMessageBetaHowToReportStepContent, + welcomeMessageBetaHowToReportStepTitle = constants.welcomeMessageBetaHowToReportStepTitle, + welcomeMessageBetaWelcomeStepContent = constants.welcomeMessageBetaWelcomeStepContent, + welcomeMessageBetaWelcomeStepTitle = constants.welcomeMessageBetaWelcomeStepTitle, + welcomeMessageLiveWelcomeStepContent = constants.welcomeMessageLiveWelcomeStepContent, + welcomeMessageLiveWelcomeStepTitle = constants.welcomeMessageLiveWelcomeStepTitle, } diff --git a/src/utils/IBGEventEmitter.ts b/src/utils/IBGEventEmitter.ts index 29e00218de..57503d8388 100644 --- a/src/utils/IBGEventEmitter.ts +++ b/src/utils/IBGEventEmitter.ts @@ -1,6 +1,4 @@ -import { DeviceEventEmitter, NativeAppEventEmitter, Platform } from 'react-native'; - -import type { NativeModule } from '../native'; +import { DeviceEventEmitter, NativeAppEventEmitter, NativeModule, Platform } from 'react-native'; export default { addListener: (nativeModule: NativeModule, eventName: string, callback: (data: any) => void) => { diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 97c7a0c611..f107eb1377 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -8,6 +8,7 @@ import type { NavigationState as NavigationStateV5, PartialState } from '@react- import type { NavigationState as NavigationStateV4 } from 'react-navigation'; import { NativeCrashReporting } from '../native'; +import type { CrashData } from '../native/CrashReportingNativeModule'; export const parseErrorStack = (error: ExtendedError): StackFrame[] => { return parseErrorStackLib(error); @@ -70,7 +71,7 @@ export const captureJsErrors = () => { const jsStackTrace = getStackTrace(err); // JSON object to be sent to the native SDK - const jsonObject = { + const jsonObject: CrashData = { message: err.name + ' - ' + err.message, e_message: err.message, e_name: err.name, diff --git a/test/mocks/mockAPM.ts b/test/mocks/mockAPM.ts index 3f61fe15ab..8b8c4c6815 100644 --- a/test/mocks/mockAPM.ts +++ b/test/mocks/mockAPM.ts @@ -1,17 +1,20 @@ -export default { - IBGAPM: { - setEnabled: jest.fn(), - setAppLaunchEnabled: jest.fn(), - setAutoUITraceEnabled: jest.fn(), - setLogLevel: jest.fn(), - startExecutionTrace: jest.fn(), - setExecutionTraceAttribute: jest.fn(), - endExecutionTrace: jest.fn(), - startUITrace: jest.fn(), - endUITrace: jest.fn(), - endAppLaunch: jest.fn(), - setNetworkEnabledIOS: jest.fn(), - ibgSleep: jest.fn(), - networkLog: jest.fn(), - }, +import type { ApmNativeModule } from '../../src/native/ApmNativeModule'; + +const mockAPM: ApmNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + setAppLaunchEnabled: jest.fn(), + setAutoUITraceEnabled: jest.fn(), + setLogLevel: jest.fn(), + startExecutionTrace: jest.fn(), + setExecutionTraceAttribute: jest.fn(), + endExecutionTrace: jest.fn(), + startUITrace: jest.fn(), + endUITrace: jest.fn(), + endAppLaunch: jest.fn(), + ibgSleep: jest.fn(), + networkLog: jest.fn(), }; + +export default mockAPM; diff --git a/test/mocks/mockBugReporting.ts b/test/mocks/mockBugReporting.ts index 8b3f77482f..fa0f07d19a 100644 --- a/test/mocks/mockBugReporting.ts +++ b/test/mocks/mockBugReporting.ts @@ -1,25 +1,28 @@ -export default { - IBGBugReporting: { - setEnabled: jest.fn(), - setInvocationEvents: jest.fn(), - setOptions: jest.fn(), - setFloatingButtonEdge: jest.fn(), - setShakingThresholdForiPhone: jest.fn(), - setShakingThresholdForiPad: jest.fn(), - setShakingThresholdForAndroid: jest.fn(), - setExtendedBugReportMode: jest.fn(), - setReportTypes: jest.fn(), - show: jest.fn(), - setOnInvokeHandler: jest.fn(), - addListener: jest.fn(), - setOnSDKDismissedHandler: jest.fn(), - setAutoScreenRecordingEnabled: jest.fn(), - setAutoScreenRecordingDuration: jest.fn(), - setViewHierarchyEnabled: jest.fn(), - setEnabledAttachmentTypes: jest.fn(), - setDidSelectPromptOptionHandler: jest.fn(), - setVideoRecordingFloatingButtonPosition: jest.fn(), - setDisclaimerText: jest.fn(), - setCommentMinimumCharacterCount: jest.fn(), - }, +import type { BugReportingNativeModule } from '../../src/native/BugReportingNativeModule'; + +const mockBugReporting: BugReportingNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + setInvocationEvents: jest.fn(), + setOptions: jest.fn(), + setFloatingButtonEdge: jest.fn(), + setShakingThresholdForiPhone: jest.fn(), + setShakingThresholdForiPad: jest.fn(), + setShakingThresholdForAndroid: jest.fn(), + setExtendedBugReportMode: jest.fn(), + setReportTypes: jest.fn(), + show: jest.fn(), + setOnInvokeHandler: jest.fn(), + setOnSDKDismissedHandler: jest.fn(), + setAutoScreenRecordingEnabled: jest.fn(), + setAutoScreenRecordingDuration: jest.fn(), + setViewHierarchyEnabled: jest.fn(), + setEnabledAttachmentTypes: jest.fn(), + setDidSelectPromptOptionHandler: jest.fn(), + setVideoRecordingFloatingButtonPosition: jest.fn(), + setDisclaimerText: jest.fn(), + setCommentMinimumCharacterCount: jest.fn(), }; + +export default mockBugReporting; diff --git a/test/mocks/mockCrashReporting.ts b/test/mocks/mockCrashReporting.ts index 27be17d433..43daecca05 100644 --- a/test/mocks/mockCrashReporting.ts +++ b/test/mocks/mockCrashReporting.ts @@ -1,7 +1,11 @@ -export default { - IBGCrashReporting: { - setEnabled: jest.fn(), - sendHandledJSCrash: jest.fn(), - sendJSCrash: jest.fn(), - }, +import type { CrashReportingNativeModule } from '../../src/native/CrashReportingNativeModule'; + +const mockCrashReporting: CrashReportingNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + sendHandledJSCrash: jest.fn(), + sendJSCrash: jest.fn(), }; + +export default mockCrashReporting; diff --git a/test/mocks/mockFeatureRequests.ts b/test/mocks/mockFeatureRequests.ts index f95fc0cbd4..9ed48c02b4 100644 --- a/test/mocks/mockFeatureRequests.ts +++ b/test/mocks/mockFeatureRequests.ts @@ -1,8 +1,11 @@ -export default { - IBGFeatureRequests: { - setEmailFieldRequiredForFeatureRequests: jest.fn(), - show: jest.fn(), - showFeatureRequests: jest.fn(), - setEnabled: jest.fn(), - }, +import type { FeatureRequestsNativeModule } from '../../src/native/FeatureRequestsNativeModule'; + +const mockFeatureRequests: FeatureRequestsNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEmailFieldRequiredForFeatureRequests: jest.fn(), + show: jest.fn(), + setEnabled: jest.fn(), }; + +export default mockFeatureRequests; diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index f9eb1916bd..f8bf85ff14 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -1,66 +1,66 @@ -export default { - Instabug: { - getConstants: jest.fn().mockReturnValue({}), - setEnabled: jest.fn(), - init: jest.fn(), - setUserData: jest.fn(), - setTrackUserSteps: jest.fn(), - setIBGLogPrintsToConsole: jest.fn(), - didSelectPromptOptionHandler: jest.fn(), - setSessionProfilerEnabled: jest.fn(), - setLocale: jest.fn(), - setColorTheme: jest.fn(), - setPrimaryColor: jest.fn(), - appendTags: jest.fn(), - resetTags: jest.fn(), - getTags: jest.fn((cb) => cb(['tags1', 'tags2'])), - setString: jest.fn(), - identifyUser: jest.fn(), - logOut: jest.fn(), - logUserEvent: jest.fn(), - log: jest.fn(), - logVerbose: jest.fn(), - logInfo: jest.fn(), - logWarn: jest.fn(), - logError: jest.fn(), - logDebug: jest.fn(), - clearLogs: jest.fn(), - setReproStepsMode: jest.fn(), - setSdkDebugLogsLevel: jest.fn(), - setUserAttribute: jest.fn(), - getUserAttribute: jest.fn((_, cb) => cb('24')), - removeUserAttribute: jest.fn(), - getAllUserAttributes: jest.fn((cb) => cb([{ age: '24' }])), - clearAllUserAttributes: jest.fn(), - setDebugEnabled: jest.fn(), - enable: jest.fn(), - disable: jest.fn(), - isRunningLive: jest.fn((cb) => cb(true)), - showWelcomeMessageWithMode: jest.fn(), - setWelcomeMessageMode: jest.fn(), - setFileAttachment: jest.fn(), - addPrivateView: jest.fn(), - removePrivateView: jest.fn(), - show: jest.fn(), - setPreSendingHandler: jest.fn(), - callPrivateApi: jest.fn(), - addListener: jest.fn(), - getReport: jest.fn(), - reportScreenChange: jest.fn(), - addExperiments: jest.fn(), - removeExperiments: jest.fn(), - clearAllExperiments: jest.fn(), - networkLog: jest.fn(), - appendTagToReport: jest.fn(), - appendConsoleLogToReport: jest.fn(), - setUserAttributeToReport: jest.fn(), - logDebugToReport: jest.fn(), - logVerboseToReport: jest.fn(), - logWarnToReport: jest.fn(), - logErrorToReport: jest.fn(), - logInfoToReport: jest.fn(), - addFileAttachmentWithURLToReport: jest.fn(), - addFileAttachmentWithDataToReport: jest.fn(), - setNetworkLoggingEnabled: jest.fn(), - }, +import type { InstabugNativeModule } from '../../src/native/InstabugNativeModule'; + +const mockInstabug: InstabugNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + getConstants: jest.fn().mockReturnValue({}), + setEnabled: jest.fn(), + init: jest.fn(), + setUserData: jest.fn(), + setTrackUserSteps: jest.fn(), + setIBGLogPrintsToConsole: jest.fn(), + setSessionProfilerEnabled: jest.fn(), + setLocale: jest.fn(), + setColorTheme: jest.fn(), + setPrimaryColor: jest.fn(), + appendTags: jest.fn(), + resetTags: jest.fn(), + getTags: jest.fn((cb) => cb(['tags1', 'tags2'])), + setString: jest.fn(), + identifyUser: jest.fn(), + logOut: jest.fn(), + logUserEvent: jest.fn(), + logVerbose: jest.fn(), + logInfo: jest.fn(), + logWarn: jest.fn(), + logError: jest.fn(), + logDebug: jest.fn(), + clearLogs: jest.fn(), + setReproStepsMode: jest.fn(), + setSdkDebugLogsLevel: jest.fn(), + setUserAttribute: jest.fn(), + getUserAttribute: jest.fn((_, cb) => cb('24')), + removeUserAttribute: jest.fn(), + getAllUserAttributes: jest.fn((cb) => cb({ age: '24' })), + clearAllUserAttributes: jest.fn(), + setDebugEnabled: jest.fn(), + enable: jest.fn(), + disable: jest.fn(), + isRunningLive: jest.fn((cb) => cb(true)), + showWelcomeMessageWithMode: jest.fn(), + setWelcomeMessageMode: jest.fn(), + setFileAttachment: jest.fn(), + addPrivateView: jest.fn(), + removePrivateView: jest.fn(), + show: jest.fn(), + setPreSendingHandler: jest.fn(), + callPrivateApi: jest.fn(), + reportScreenChange: jest.fn(), + addExperiments: jest.fn(), + removeExperiments: jest.fn(), + clearAllExperiments: jest.fn(), + networkLog: jest.fn(), + appendTagToReport: jest.fn(), + appendConsoleLogToReport: jest.fn(), + setUserAttributeToReport: jest.fn(), + logDebugToReport: jest.fn(), + logVerboseToReport: jest.fn(), + logWarnToReport: jest.fn(), + logErrorToReport: jest.fn(), + logInfoToReport: jest.fn(), + addFileAttachmentWithURLToReport: jest.fn(), + addFileAttachmentWithDataToReport: jest.fn(), + setNetworkLoggingEnabled: jest.fn(), }; + +export default mockInstabug; diff --git a/test/mocks/mockNativeModules.ts b/test/mocks/mockNativeModules.ts index 0ba3191f9c..9112004f11 100644 --- a/test/mocks/mockNativeModules.ts +++ b/test/mocks/mockNativeModules.ts @@ -1,3 +1,4 @@ +import type { InstabugNativePackage } from '../../src/native'; import mockAPM from './mockAPM'; import mockBugReporting from './mockBugReporting'; import mockCrashReporting from './mockCrashReporting'; @@ -6,22 +7,19 @@ import mockInstabug from './mockInstabug'; import mockReplies from './mockReplies'; import mockSurveys from './mockSurveys'; -const mockModules = [ - mockAPM, - mockBugReporting, - mockCrashReporting, - mockFeatureRequests, - mockInstabug, - mockReplies, - mockSurveys, -]; - jest.mock('react-native', () => { const RN = jest.requireActual('react-native'); + const mockNativeModules: InstabugNativePackage = { + IBGAPM: mockAPM, + IBGBugReporting: mockBugReporting, + IBGCrashReporting: mockCrashReporting, + IBGFeatureRequests: mockFeatureRequests, + Instabug: mockInstabug, + IBGReplies: mockReplies, + IBGSurveys: mockSurveys, + }; - mockModules.forEach((mockModule) => { - Object.assign(RN.NativeModules, mockModule); - }); + Object.assign(RN.NativeModules, mockNativeModules); return RN; }); diff --git a/test/mocks/mockReplies.ts b/test/mocks/mockReplies.ts index 0fe09219fa..c2c86b731c 100644 --- a/test/mocks/mockReplies.ts +++ b/test/mocks/mockReplies.ts @@ -1,18 +1,21 @@ -export default { - IBGReplies: { - setEnabled: jest.fn(), - hasChats: jest.fn((cb) => cb(true)), - show: jest.fn(), - setOnNewReplyReceivedHandler: jest.fn(), - getUnreadRepliesCount: jest.fn((cb) => cb(2)), - setInAppNotificationEnabled: jest.fn(), - setInAppNotificationSound: jest.fn(), - addListener: jest.fn(), - setPushNotificationsEnabled: jest.fn(), - setPushNotificationRegistrationToken: jest.fn(), - showNotification: jest.fn(), - setNotificationIcon: jest.fn(), - setPushNotificationChannelId: jest.fn(), - setSystemReplyNotificationSoundEnabled: jest.fn(), - }, +import type { RepliesNativeModule } from '../../src/native/RepliesNativeModule'; + +const mockReplies: RepliesNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + hasChats: jest.fn((cb) => cb(true)), + show: jest.fn(), + setOnNewReplyReceivedHandler: jest.fn(), + getUnreadRepliesCount: jest.fn((cb) => cb(2)), + setInAppNotificationEnabled: jest.fn(), + setInAppNotificationSound: jest.fn(), + setPushNotificationsEnabled: jest.fn(), + setPushNotificationRegistrationToken: jest.fn(), + showNotification: jest.fn(), + setNotificationIcon: jest.fn(), + setPushNotificationChannelId: jest.fn(), + setSystemReplyNotificationSoundEnabled: jest.fn(), }; + +export default mockReplies; diff --git a/test/mocks/mockSurveys.ts b/test/mocks/mockSurveys.ts index de68916414..d94af4f511 100644 --- a/test/mocks/mockSurveys.ts +++ b/test/mocks/mockSurveys.ts @@ -1,15 +1,18 @@ -export default { - IBGSurveys: { - setEnabled: jest.fn(), - setAppStoreURL: jest.fn(), - showSurveysIfAvailable: jest.fn(), - getAvailableSurveys: jest.fn(), - setAutoShowingEnabled: jest.fn(), - setOnShowHandler: jest.fn(), - setOnDismissHandler: jest.fn(), - showSurvey: jest.fn(), - hasRespondedToSurvey: jest.fn((_, cb) => cb(true)), - setShouldShowWelcomeScreen: jest.fn(), - addListener: jest.fn(), - }, +import type { SurveysNativeModule } from '../../src/native/SurveysNativeModule'; + +const mockSurveys: SurveysNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + setAppStoreURL: jest.fn(), + showSurveysIfAvailable: jest.fn(), + getAvailableSurveys: jest.fn(), + setAutoShowingEnabled: jest.fn(), + setOnShowHandler: jest.fn(), + setOnDismissHandler: jest.fn(), + showSurvey: jest.fn(), + hasRespondedToSurvey: jest.fn((_, cb) => cb(true)), + setShouldShowWelcomeScreen: jest.fn(), }; + +export default mockSurveys; diff --git a/test/modules/APM.spec.ts b/test/modules/APM.spec.ts index 94ec8493b5..b8dcfd29db 100644 --- a/test/modules/APM.spec.ts +++ b/test/modules/APM.spec.ts @@ -1,5 +1,7 @@ import { Platform } from 'react-native'; +import { mocked } from 'ts-jest/utils'; + import Trace from '../../src/models/Trace'; import * as APM from '../../src/modules/APM'; import { NativeAPM, NativeInstabug } from '../../src/native'; @@ -67,8 +69,8 @@ describe('APM Module', () => { }); it("should throw an error if native startExecutionTrace didn't return an ID", async () => { - NativeAPM.startExecutionTrace.mockImplementationOnce((_: any, __: any, callback: () => any) => - callback(), + mocked(NativeAPM).startExecutionTrace.mockImplementationOnce((_, __, callback) => + callback(null), ); const promise = APM.startExecutionTrace('trace'); @@ -77,8 +79,8 @@ describe('APM Module', () => { }); it('should resolve with an Trace object if native startExecutionTrace returned an ID', async () => { - NativeAPM.startExecutionTrace.mockImplementationOnce( - (_: any, __: any, callback: (arg0: string) => any) => callback('trace-id'), + mocked(NativeAPM).startExecutionTrace.mockImplementationOnce((_, __, callback) => + callback('trace-id'), ); const promise = APM.startExecutionTrace('trace'); diff --git a/test/modules/FeatureRequests.spec.ts b/test/modules/FeatureRequests.spec.ts index 5126606735..b19aeeb491 100644 --- a/test/modules/FeatureRequests.spec.ts +++ b/test/modules/FeatureRequests.spec.ts @@ -8,10 +8,9 @@ describe('Feature Requests Module', () => { FeatureRequests.setEmailFieldRequired(true, actionType); expect(NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests).toBeCalledTimes(1); - expect(NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests).toBeCalledWith( - true, + expect(NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests).toBeCalledWith(true, [ actionType, - ); + ]); }); it('should call the native method showFeatureRequests', () => {