From 76d749201efab5e7ebd8008827c40790f4ebef1c Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 14:46:41 +0200 Subject: [PATCH 01/16] Create `native` directory --- src/{native.ts => native/index.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{native.ts => native/index.ts} (100%) diff --git a/src/native.ts b/src/native/index.ts similarity index 100% rename from src/native.ts rename to src/native/index.ts From c7b9d1e659d8aa1888a690f2d6f273db2383b15e Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:05:59 +0200 Subject: [PATCH 02/16] Add APM types --- src/native/ApmNativeModule.ts | 30 ++++++++++++++++++++++++++++++ src/native/index.ts | 4 +++- test/mocks/mockAPM.ts | 35 ++++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/native/ApmNativeModule.ts diff --git a/src/native/ApmNativeModule.ts b/src/native/ApmNativeModule.ts new file mode 100644 index 000000000..f398509ea --- /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/index.ts b/src/native/index.ts index d06fff464..b8e638387 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -3,12 +3,14 @@ import { NativeModules as ReactNativeModules, } from 'react-native'; +import type { ApmNativeModule } from './ApmNativeModule'; + export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; } interface InstabugNativeModules { - IBGAPM: NativeModule; + IBGAPM: ApmNativeModule; IBGBugReporting: NativeModule; IBGCrashReporting: NativeModule; IBGFeatureRequests: NativeModule; diff --git a/test/mocks/mockAPM.ts b/test/mocks/mockAPM.ts index 3f61fe15a..08cf38045 100644 --- a/test/mocks/mockAPM.ts +++ b/test/mocks/mockAPM.ts @@ -1,17 +1,22 @@ +import type { ApmNativeModule } from '../../src/native/ApmNativeModule'; + +const mockedApm: 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 { - 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(), - }, + IBGAPM: mockedApm, }; From e063a11664f478399a7d1fe41d03a7187b19d672 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:20:24 +0200 Subject: [PATCH 03/16] Add BugReporting types --- src/native/BugReportingNativeModule.ts | 59 ++++++++++++++++++++++++++ src/native/index.ts | 3 +- src/utils/IBGEventEmitter.ts | 13 +++++- test/mocks/mockBugReporting.ts | 51 ++++++++++++---------- 4 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 src/native/BugReportingNativeModule.ts diff --git a/src/native/BugReportingNativeModule.ts b/src/native/BugReportingNativeModule.ts new file mode 100644 index 000000000..c8b339fa5 --- /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, arg1: 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, arg1: 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/index.ts b/src/native/index.ts index b8e638387..c11675a3b 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -4,6 +4,7 @@ import { } from 'react-native'; import type { ApmNativeModule } from './ApmNativeModule'; +import type { BugReportingNativeModule } from './BugReportingNativeModule'; export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; @@ -11,7 +12,7 @@ export interface NativeModule extends ReactNativeModule, Record { interface InstabugNativeModules { IBGAPM: ApmNativeModule; - IBGBugReporting: NativeModule; + IBGBugReporting: BugReportingNativeModule; IBGCrashReporting: NativeModule; IBGFeatureRequests: NativeModule; Instabug: NativeModule; diff --git a/src/utils/IBGEventEmitter.ts b/src/utils/IBGEventEmitter.ts index 29e00218d..70ce536d5 100644 --- a/src/utils/IBGEventEmitter.ts +++ b/src/utils/IBGEventEmitter.ts @@ -1,9 +1,18 @@ -import { DeviceEventEmitter, NativeAppEventEmitter, Platform } from 'react-native'; +import { + DeviceEventEmitter, + NativeAppEventEmitter, + Platform, + NativeModule as ReactNativeModule, +} from 'react-native'; import type { NativeModule } from '../native'; export default { - addListener: (nativeModule: NativeModule, eventName: string, callback: (data: any) => void) => { + addListener: ( + nativeModule: NativeModule | ReactNativeModule, + eventName: string, + callback: (data: any) => void, + ) => { if (Platform.OS === 'ios') { nativeModule.addListener(eventName); NativeAppEventEmitter.addListener(eventName, callback); diff --git a/test/mocks/mockBugReporting.ts b/test/mocks/mockBugReporting.ts index 8b3f77482..8222f58c8 100644 --- a/test/mocks/mockBugReporting.ts +++ b/test/mocks/mockBugReporting.ts @@ -1,25 +1,30 @@ +import type { BugReportingNativeModule } from '../../src/native/BugReportingNativeModule'; + +const mockedBugReporting: 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 { - 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(), - }, + IBGBugReporting: mockedBugReporting, }; From 6f9210153ce7d880ef7350c0ffe2159565d838fd Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:33:07 +0200 Subject: [PATCH 04/16] Add CrashReporting types --- src/modules/CrashReporting.ts | 7 ++++--- src/native/CrashReportingNativeModule.ts | 17 +++++++++++++++++ src/native/index.ts | 3 ++- src/utils/InstabugUtils.ts | 7 ++++--- test/mocks/mockCrashReporting.ts | 16 +++++++++++----- 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 src/native/CrashReportingNativeModule.ts diff --git a/src/modules/CrashReporting.ts b/src/modules/CrashReporting.ts index 0eff9140a..03f536184 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,12 +32,12 @@ 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, - os: Platform.OS, - platform: 'react_native', + os: Platform.select({ ios: 'ios' as const, android: 'android' as const })!, + platform: 'react_native' as const, exception: jsStackTrace, }; diff --git a/src/native/CrashReportingNativeModule.ts b/src/native/CrashReportingNativeModule.ts new file mode 100644 index 000000000..8b7d78668 --- /dev/null +++ b/src/native/CrashReportingNativeModule.ts @@ -0,0 +1,17 @@ +import type { NativeModule } 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: 'android' | 'ios'; + 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/index.ts b/src/native/index.ts index c11675a3b..57e427f62 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -5,6 +5,7 @@ import { import type { ApmNativeModule } from './ApmNativeModule'; import type { BugReportingNativeModule } from './BugReportingNativeModule'; +import type { CrashReportingNativeModule } from './CrashReportingNativeModule'; export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; @@ -13,7 +14,7 @@ export interface NativeModule extends ReactNativeModule, Record { interface InstabugNativeModules { IBGAPM: ApmNativeModule; IBGBugReporting: BugReportingNativeModule; - IBGCrashReporting: NativeModule; + IBGCrashReporting: CrashReportingNativeModule; IBGFeatureRequests: NativeModule; Instabug: NativeModule; IBGReplies: NativeModule; diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 97c7a0c61..299b684a1 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,12 +71,12 @@ 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, - os: Platform.OS, - platform: 'react_native', + os: Platform.select({ ios: 'ios' as const, android: 'android' as const })!, + platform: 'react_native' as const, exception: jsStackTrace, }; diff --git a/test/mocks/mockCrashReporting.ts b/test/mocks/mockCrashReporting.ts index 27be17d43..24c7c8014 100644 --- a/test/mocks/mockCrashReporting.ts +++ b/test/mocks/mockCrashReporting.ts @@ -1,7 +1,13 @@ +import type { CrashReportingNativeModule } from '../../src/native/CrashReportingNativeModule'; + +const mockedCrashReporting: CrashReportingNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEnabled: jest.fn(), + sendHandledJSCrash: jest.fn(), + sendJSCrash: jest.fn(), +}; + export default { - IBGCrashReporting: { - setEnabled: jest.fn(), - sendHandledJSCrash: jest.fn(), - sendJSCrash: jest.fn(), - }, + IBGCrashReporting: mockedCrashReporting, }; From 8eea87a8befb138f92715571f21a651eb6d688af Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:40:25 +0200 Subject: [PATCH 05/16] Add FeatureRequests types --- src/native/FeatureRequestsNativeModule.ts | 13 +++++++++++++ src/native/index.ts | 3 ++- test/mocks/mockFeatureRequests.ts | 17 +++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 src/native/FeatureRequestsNativeModule.ts diff --git a/src/native/FeatureRequestsNativeModule.ts b/src/native/FeatureRequestsNativeModule.ts new file mode 100644 index 000000000..ecce98be8 --- /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/index.ts b/src/native/index.ts index 57e427f62..590ad59f6 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -6,6 +6,7 @@ import { import type { ApmNativeModule } from './ApmNativeModule'; import type { BugReportingNativeModule } from './BugReportingNativeModule'; import type { CrashReportingNativeModule } from './CrashReportingNativeModule'; +import type { FeatureRequestsNativeModule } from './FeatureRequestsNativeModule'; export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; @@ -15,7 +16,7 @@ interface InstabugNativeModules { IBGAPM: ApmNativeModule; IBGBugReporting: BugReportingNativeModule; IBGCrashReporting: CrashReportingNativeModule; - IBGFeatureRequests: NativeModule; + IBGFeatureRequests: FeatureRequestsNativeModule; Instabug: NativeModule; IBGReplies: NativeModule; IBGSurveys: NativeModule; diff --git a/test/mocks/mockFeatureRequests.ts b/test/mocks/mockFeatureRequests.ts index f95fc0cbd..53cb5311e 100644 --- a/test/mocks/mockFeatureRequests.ts +++ b/test/mocks/mockFeatureRequests.ts @@ -1,8 +1,13 @@ +import type { FeatureRequestsNativeModule } from '../../src/native/FeatureRequestsNativeModule'; + +const mockedFeatureRequests: FeatureRequestsNativeModule = { + addListener: jest.fn(), + removeListeners: jest.fn(), + setEmailFieldRequiredForFeatureRequests: jest.fn(), + show: jest.fn(), + setEnabled: jest.fn(), +}; + export default { - IBGFeatureRequests: { - setEmailFieldRequiredForFeatureRequests: jest.fn(), - show: jest.fn(), - showFeatureRequests: jest.fn(), - setEnabled: jest.fn(), - }, + IBGFeatureRequests: mockedFeatureRequests, }; From 532825a60a15f601a85edf09aed83091f1b74378 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:49:40 +0200 Subject: [PATCH 06/16] Add Instabug types --- src/modules/Instabug.ts | 2 +- src/native/InstabugNativeModule.ts | 122 ++++++++++++ src/native/index.ts | 3 +- src/utils/ArgsRegistry.ts | 286 +++++++++++++++-------------- test/mocks/mockInstabug.ts | 131 ++++++------- 5 files changed, 336 insertions(+), 208 deletions(-) create mode 100644 src/native/InstabugNativeModule.ts diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index cb7b39956..dd569ebb9 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/native/InstabugNativeModule.ts b/src/native/InstabugNativeModule.ts new file mode 100644 index 000000000..1962057ae --- /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'; + +export interface InstabugNativeModule extends NativeModule { + getConstants(): Record; + + // 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 // + getReport(): void; + setPreSendingHandler(handler?: (report: Report) => void): void; + appendTagToReport(tag: string): unknown; + appendConsoleLogToReport(consoleLog: string): unknown; + setUserAttributeToReport(key: string, value: string): unknown; + logDebugToReport(log: string): unknown; + logVerboseToReport(log: string): unknown; + logWarnToReport(log: string): unknown; + logErrorToReport(log: string): unknown; + logInfoToReport(log: string): unknown; + addFileAttachmentWithURLToReport(url: string, filename?: string): unknown; + addFileAttachmentWithDataToReport(data: string, filename?: string): unknown; + + // 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/index.ts b/src/native/index.ts index 590ad59f6..a2c991f86 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -7,6 +7,7 @@ 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'; export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; @@ -17,7 +18,7 @@ interface InstabugNativeModules { IBGBugReporting: BugReportingNativeModule; IBGCrashReporting: CrashReportingNativeModule; IBGFeatureRequests: FeatureRequestsNativeModule; - Instabug: NativeModule; + Instabug: InstabugNativeModule; IBGReplies: NativeModule; IBGSurveys: NativeModule; } diff --git a/src/utils/ArgsRegistry.ts b/src/utils/ArgsRegistry.ts index 479d6370f..88425088e 100644 --- a/src/utils/ArgsRegistry.ts +++ b/src/utils/ArgsRegistry.ts @@ -1,5 +1,7 @@ import { NativeInstabug } from '../native'; +const NativeConstants = 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 = NativeConstants.sdkDebugLogsLevelVerbose, + sdkDebugLogsLevelDebug = NativeConstants.sdkDebugLogsLevelDebug, + sdkDebugLogsLevelError = NativeConstants.sdkDebugLogsLevelError, + sdkDebugLogsLevelNone = NativeConstants.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 = NativeConstants.logLevelNone, + error = NativeConstants.logLevelError, + warning = NativeConstants.logLevelWarning, + info = NativeConstants.logLevelInfo, + debug = NativeConstants.logLevelDebug, + verbose = NativeConstants.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 = NativeConstants.invocationEventNone, + shake = NativeConstants.invocationEventShake, + screenshot = NativeConstants.invocationEventScreenshot, + twoFingersSwipe = NativeConstants.invocationEventTwoFingersSwipeLeft, + floatingButton = NativeConstants.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 = NativeConstants.optionEmailFieldHidden, + emailFieldOptional = NativeConstants.optionEmailFieldOptional, + commentFieldRequired = NativeConstants.optionCommentFieldRequired, + disablePostSendingDialog = NativeConstants.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 = NativeConstants.colorThemeLight, + dark = NativeConstants.colorThemeDark, } /** @@ -68,32 +70,32 @@ export enum colorTheme { * Floating Button edges */ export enum floatingButtonEdge { - left = NativeInstabug.rectMinXEdge, - right = NativeInstabug.rectMaxXEdge, + left = NativeConstants.rectMinXEdge, + right = NativeConstants.rectMaxXEdge, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeInstabug floating buttons positions. + * NativeConstants floating buttons positions. */ export enum position { - bottomRight = NativeInstabug.bottomRight, - topRight = NativeInstabug.topRight, - bottomLeft = NativeInstabug.bottomLeft, - topLeft = NativeInstabug.topLeft, + bottomRight = NativeConstants.bottomRight, + topRight = NativeConstants.topRight, + bottomLeft = NativeConstants.bottomLeft, + topLeft = NativeConstants.topLeft, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeInstabug floating buttons positions. + * NativeConstants floating buttons positions. */ export enum IBGPosition { - bottomRight = NativeInstabug.bottomRight, - topRight = NativeInstabug.topRight, - bottomLeft = NativeInstabug.bottomLeft, - topLeft = NativeInstabug.topLeft, + bottomRight = NativeConstants.bottomRight, + topRight = NativeConstants.topRight, + bottomLeft = NativeConstants.bottomLeft, + topLeft = NativeConstants.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 = NativeConstants.welcomeMessageModeLive, + beta = NativeConstants.welcomeMessageModeBeta, + disabled = NativeConstants.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 = NativeConstants.bugReportingReportTypeBug, + feedback = NativeConstants.bugReportingReportTypeFeedback, + question = NativeConstants.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 = NativeConstants.dismissTypeSubmit, + cancel = NativeConstants.dismissTypeCancel, + addAttachment = NativeConstants.dismissTypeAddAttachment, } /** * @deprecated Use `ActionType` instead. * - * NativeInstabug action types. + * NativeConstants action types. */ export enum actionTypes { - allActions = NativeInstabug.allActions, - reportBug = NativeInstabug.reportBugAction, - requestNewFeature = NativeInstabug.requestNewFeature, - addCommentToFeature = NativeInstabug.addCommentToFeature, + allActions = NativeConstants.allActions, + reportBug = NativeConstants.reportBugAction, + requestNewFeature = NativeConstants.requestNewFeature, + addCommentToFeature = NativeConstants.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 = NativeConstants.enabledWithRequiredFields, + enabledWithOptionalFields = NativeConstants.enabledWithOptionalFields, + disabled = NativeConstants.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 = NativeConstants.reproStepsEnabled, + disabled = NativeConstants.reproStepsDisabled, + enabledWithNoScreenshots = NativeConstants.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 = 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, } /** * @deprecated Use `StringKey` instead. * - * NativeInstabug strings + * NativeConstants 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 = NativeConstants.shakeHint, + swipeHint = NativeConstants.swipeHint, + edgeSwipeStartHint = NativeConstants.edgeSwipeStartHint, + startAlertText = NativeConstants.startAlertText, + invalidEmailMessage = NativeConstants.invalidEmailMessage, + invalidEmailTitle = NativeConstants.invalidEmailTitle, + invalidCommentMessage = NativeConstants.invalidCommentMessage, + invalidCommentTitle = NativeConstants.invalidCommentTitle, + invocationHeader = NativeConstants.invocationHeader, + reportQuestion = NativeConstants.reportQuestion, + reportBug = NativeConstants.reportBug, + reportFeedback = NativeConstants.reportFeedback, + emailFieldHint = NativeConstants.emailFieldHint, + commentFieldHintForBugReport = NativeConstants.commentFieldHintForBugReport, + commentFieldHintForFeedback = NativeConstants.commentFieldHintForFeedback, + commentFieldHintForQuestion = NativeConstants.commentFieldHintForQuestion, + videoPressRecord = NativeConstants.videoPressRecord, + addVideoMessage = NativeConstants.addVideoMessage, + addVoiceMessage = NativeConstants.addVoiceMessage, + addImageFromGallery = NativeConstants.addImageFromGallery, + addExtraScreenshot = NativeConstants.addExtraScreenshot, + audioRecordingPermissionDeniedTitle = NativeConstants.audioRecordingPermissionDeniedTitle, + audioRecordingPermissionDeniedMessage = NativeConstants.audioRecordingPermissionDeniedMessage, + microphonePermissionAlertSettingsButtonText = NativeConstants.microphonePermissionAlertSettingsButtonTitle, + recordingMessageToHoldText = NativeConstants.recordingMessageToHoldText, + recordingMessageToReleaseText = NativeConstants.recordingMessageToReleaseText, + conversationsHeaderTitle = NativeConstants.conversationsHeaderTitle, + screenshotHeaderTitle = NativeConstants.screenshotHeaderTitle, + okButtonText = NativeConstants.okButtonTitle, + cancelButtonText = NativeConstants.cancelButtonTitle, + thankYouText = NativeConstants.thankYouText, + audio = NativeConstants.audio, + image = NativeConstants.image, + team = NativeConstants.team, + messagesNotification = NativeConstants.messagesNotification, + messagesNotificationAndOthers = NativeConstants.messagesNotificationAndOthers, + conversationTextFieldHint = NativeConstants.conversationTextFieldHint, + collectingDataText = NativeConstants.collectingDataText, + thankYouAlertText = NativeConstants.thankYouAlertText, + welcomeMessageBetaWelcomeStepTitle = NativeConstants.welcomeMessageBetaWelcomeStepTitle, + welcomeMessageBetaWelcomeStepContent = NativeConstants.welcomeMessageBetaWelcomeStepContent, + welcomeMessageBetaHowToReportStepTitle = NativeConstants.welcomeMessageBetaHowToReportStepTitle, + welcomeMessageBetaHowToReportStepContent = NativeConstants.welcomeMessageBetaHowToReportStepContent, + welcomeMessageBetaFinishStepTitle = NativeConstants.welcomeMessageBetaFinishStepTitle, + welcomeMessageBetaFinishStepContent = NativeConstants.welcomeMessageBetaFinishStepContent, + welcomeMessageLiveWelcomeStepTitle = NativeConstants.welcomeMessageLiveWelcomeStepTitle, + welcomeMessageLiveWelcomeStepContent = NativeConstants.welcomeMessageLiveWelcomeStepContent, + surveysStoreRatingThanksTitle = NativeConstants.surveysStoreRatingThanksTitle, + surveysStoreRatingThanksSubtitle = NativeConstants.surveysStoreRatingThanksSubtitle, + reportBugDescription = NativeConstants.reportBugDescription, + reportFeedbackDescription = NativeConstants.reportFeedbackDescription, + reportQuestionDescription = NativeConstants.reportQuestionDescription, + requestFeatureDescription = NativeConstants.requestFeatureDescription, + discardAlertTitle = NativeConstants.discardAlertTitle, + discardAlertMessage = NativeConstants.discardAlertMessage, + discardAlertCancel = NativeConstants.discardAlertCancel, + discardAlertAction = NativeConstants.discardAlertAction, + addAttachmentButtonTitleStringName = NativeConstants.addAttachmentButtonTitleStringName, + reportReproStepsDisclaimerBody = NativeConstants.reportReproStepsDisclaimerBody, + reportReproStepsDisclaimerLink = NativeConstants.reportReproStepsDisclaimerLink, + reproStepsProgressDialogBody = NativeConstants.reproStepsProgressDialogBody, + reproStepsListHeader = NativeConstants.reproStepsListHeader, + reproStepsListDescription = NativeConstants.reproStepsListDescription, + reproStepsListEmptyStateDescription = NativeConstants.reproStepsListEmptyStateDescription, + reproStepsListItemTitle = NativeConstants.reproStepsListItemTitle, + screenRecording = NativeConstants.screenRecording, + insufficientContentMessage = NativeConstants.insufficientContentMessage, + insufficientContentTitle = NativeConstants.insufficientContentTitle, } diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index f9eb1916b..6fdc25805 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -1,66 +1,69 @@ +import type { InstabugNativeModule } from '../../src/native/InstabugNativeModule'; + +const mockedInstabug: 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(), + 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(), +}; + 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(), - }, + Instabug: mockedInstabug, }; From d39126937b901608534b3ec7d57a224c26bdcef4 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 15:56:10 +0200 Subject: [PATCH 07/16] Add Constants types --- src/native/InstabugNativeModule.ts | 3 +- src/native/NativeConstants.ts | 198 ++++++++++++++++++++ src/utils/ArgsRegistry.ts | 286 ++++++++++++++--------------- src/utils/Enums.ts | 258 +++++++++++++------------- 4 files changed, 472 insertions(+), 273 deletions(-) create mode 100644 src/native/NativeConstants.ts diff --git a/src/native/InstabugNativeModule.ts b/src/native/InstabugNativeModule.ts index 1962057ae..6d4669588 100644 --- a/src/native/InstabugNativeModule.ts +++ b/src/native/InstabugNativeModule.ts @@ -20,9 +20,10 @@ import type { WelcomeMessageMode, } from '../utils/Enums'; import type { NetworkData } from '../utils/XhrNetworkInterceptor'; +import type { NativeConstants } from './NativeConstants'; export interface InstabugNativeModule extends NativeModule { - getConstants(): Record; + getConstants(): NativeConstants; // Essential APIs // setEnabled(isEnabled: boolean): void; diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts new file mode 100644 index 000000000..2d754bdbf --- /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/utils/ArgsRegistry.ts b/src/utils/ArgsRegistry.ts index 88425088e..028d57039 100644 --- a/src/utils/ArgsRegistry.ts +++ b/src/utils/ArgsRegistry.ts @@ -1,6 +1,6 @@ import { NativeInstabug } from '../native'; -const NativeConstants = NativeInstabug.getConstants(); +const constants = NativeInstabug.getConstants(); /** * @deprecated Pass a `LogLevel` to `debugLogsLevel` in `Instabug.init` instead. @@ -9,10 +9,10 @@ const NativeConstants = NativeInstabug.getConstants(); * and only affect the logs used to debug the SDK itself. */ export enum sdkDebugLogsLevel { - sdkDebugLogsLevelVerbose = NativeConstants.sdkDebugLogsLevelVerbose, - sdkDebugLogsLevelDebug = NativeConstants.sdkDebugLogsLevelDebug, - sdkDebugLogsLevelError = NativeConstants.sdkDebugLogsLevelError, - sdkDebugLogsLevelNone = NativeConstants.sdkDebugLogsLevelNone, + sdkDebugLogsLevelVerbose = constants.sdkDebugLogsLevelVerbose, + sdkDebugLogsLevelDebug = constants.sdkDebugLogsLevelDebug, + sdkDebugLogsLevelError = constants.sdkDebugLogsLevelError, + sdkDebugLogsLevelNone = constants.sdkDebugLogsLevelNone, } /** @@ -21,12 +21,12 @@ export enum sdkDebugLogsLevel { * APM Log Level. */ export enum logLevel { - none = NativeConstants.logLevelNone, - error = NativeConstants.logLevelError, - warning = NativeConstants.logLevelWarning, - info = NativeConstants.logLevelInfo, - debug = NativeConstants.logLevelDebug, - verbose = NativeConstants.logLevelVerbose, + none = constants.logLevelNone, + error = constants.logLevelError, + warning = constants.logLevelWarning, + info = constants.logLevelInfo, + debug = constants.logLevelDebug, + verbose = constants.logLevelVerbose, } /** @@ -35,11 +35,11 @@ export enum logLevel { * 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, } /** @@ -48,10 +48,10 @@ export enum invocationEvent { * Options added while invoking bug reporting. */ export enum option { - emailFieldHidden = NativeConstants.optionEmailFieldHidden, - emailFieldOptional = NativeConstants.optionEmailFieldOptional, - commentFieldRequired = NativeConstants.optionCommentFieldRequired, - disablePostSendingDialog = NativeConstants.optionDisablePostSendingDialog, + emailFieldHidden = constants.optionEmailFieldHidden, + emailFieldOptional = constants.optionEmailFieldOptional, + commentFieldRequired = constants.optionCommentFieldRequired, + disablePostSendingDialog = constants.optionDisablePostSendingDialog, } /** @@ -60,8 +60,8 @@ export enum option { * The color theme of the different UI elements */ export enum colorTheme { - light = NativeConstants.colorThemeLight, - dark = NativeConstants.colorThemeDark, + light = constants.colorThemeLight, + dark = constants.colorThemeDark, } /** @@ -70,32 +70,32 @@ export enum colorTheme { * Floating Button edges */ export enum floatingButtonEdge { - left = NativeConstants.rectMinXEdge, - right = NativeConstants.rectMaxXEdge, + left = constants.rectMinXEdge, + right = constants.rectMaxXEdge, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeConstants floating buttons positions. + * constants floating buttons positions. */ export enum position { - bottomRight = NativeConstants.bottomRight, - topRight = NativeConstants.topRight, - bottomLeft = NativeConstants.bottomLeft, - topLeft = NativeConstants.topLeft, + bottomRight = constants.bottomRight, + topRight = constants.topRight, + bottomLeft = constants.bottomLeft, + topLeft = constants.topLeft, } /** * @deprecated Use `RecordingButtonPosition` instead. * - * NativeConstants floating buttons positions. + * constants floating buttons positions. */ export enum IBGPosition { - bottomRight = NativeConstants.bottomRight, - topRight = NativeConstants.topRight, - bottomLeft = NativeConstants.bottomLeft, - topLeft = NativeConstants.topLeft, + bottomRight = constants.bottomRight, + topRight = constants.topRight, + bottomLeft = constants.bottomLeft, + topLeft = constants.topLeft, } /** @@ -104,9 +104,9 @@ export enum IBGPosition { * 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, } /** @@ -115,9 +115,9 @@ export enum welcomeMessageMode { * 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, } /** @@ -126,21 +126,21 @@ export enum reportType { * 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, } /** * @deprecated Use `ActionType` instead. * - * NativeConstants action types. + * constants action types. */ export enum actionTypes { - allActions = NativeConstants.allActions, - reportBug = NativeConstants.reportBugAction, - requestNewFeature = NativeConstants.requestNewFeature, - addCommentToFeature = NativeConstants.addCommentToFeature, + allActions = constants.allActions, + reportBug = constants.reportBugAction, + requestNewFeature = constants.requestNewFeature, + addCommentToFeature = constants.addCommentToFeature, } /** @@ -149,9 +149,9 @@ export enum actionTypes { * 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, } /** @@ -160,9 +160,9 @@ export enum extendedBugReportMode { * The user steps option. */ export enum reproStepsMode { - enabled = NativeConstants.reproStepsEnabled, - disabled = NativeConstants.reproStepsDisabled, - enabledWithNoScreenshots = NativeConstants.reproStepsEnabledWithNoScreenshots, + enabled = constants.reproStepsEnabled, + disabled = constants.reproStepsDisabled, + enabledWithNoScreenshots = constants.reproStepsEnabledWithNoScreenshots, } /** @@ -171,100 +171,100 @@ export enum reproStepsMode { * The 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, } /** * @deprecated Use `StringKey` instead. * - * NativeConstants strings + * constants strings */ export enum strings { - shakeHint = NativeConstants.shakeHint, - swipeHint = NativeConstants.swipeHint, - edgeSwipeStartHint = NativeConstants.edgeSwipeStartHint, - startAlertText = NativeConstants.startAlertText, - invalidEmailMessage = NativeConstants.invalidEmailMessage, - invalidEmailTitle = NativeConstants.invalidEmailTitle, - invalidCommentMessage = NativeConstants.invalidCommentMessage, - invalidCommentTitle = NativeConstants.invalidCommentTitle, - invocationHeader = NativeConstants.invocationHeader, - reportQuestion = NativeConstants.reportQuestion, - reportBug = NativeConstants.reportBug, - reportFeedback = NativeConstants.reportFeedback, - emailFieldHint = NativeConstants.emailFieldHint, - commentFieldHintForBugReport = NativeConstants.commentFieldHintForBugReport, - commentFieldHintForFeedback = NativeConstants.commentFieldHintForFeedback, - commentFieldHintForQuestion = NativeConstants.commentFieldHintForQuestion, - videoPressRecord = NativeConstants.videoPressRecord, - addVideoMessage = NativeConstants.addVideoMessage, - addVoiceMessage = NativeConstants.addVoiceMessage, - addImageFromGallery = NativeConstants.addImageFromGallery, - addExtraScreenshot = NativeConstants.addExtraScreenshot, - audioRecordingPermissionDeniedTitle = NativeConstants.audioRecordingPermissionDeniedTitle, - audioRecordingPermissionDeniedMessage = NativeConstants.audioRecordingPermissionDeniedMessage, - microphonePermissionAlertSettingsButtonText = NativeConstants.microphonePermissionAlertSettingsButtonTitle, - recordingMessageToHoldText = NativeConstants.recordingMessageToHoldText, - recordingMessageToReleaseText = NativeConstants.recordingMessageToReleaseText, - conversationsHeaderTitle = NativeConstants.conversationsHeaderTitle, - screenshotHeaderTitle = NativeConstants.screenshotHeaderTitle, - okButtonText = NativeConstants.okButtonTitle, - cancelButtonText = NativeConstants.cancelButtonTitle, - thankYouText = NativeConstants.thankYouText, - audio = NativeConstants.audio, - image = NativeConstants.image, - team = NativeConstants.team, - messagesNotification = NativeConstants.messagesNotification, - messagesNotificationAndOthers = NativeConstants.messagesNotificationAndOthers, - conversationTextFieldHint = NativeConstants.conversationTextFieldHint, - collectingDataText = NativeConstants.collectingDataText, - thankYouAlertText = NativeConstants.thankYouAlertText, - welcomeMessageBetaWelcomeStepTitle = NativeConstants.welcomeMessageBetaWelcomeStepTitle, - welcomeMessageBetaWelcomeStepContent = NativeConstants.welcomeMessageBetaWelcomeStepContent, - welcomeMessageBetaHowToReportStepTitle = NativeConstants.welcomeMessageBetaHowToReportStepTitle, - welcomeMessageBetaHowToReportStepContent = NativeConstants.welcomeMessageBetaHowToReportStepContent, - welcomeMessageBetaFinishStepTitle = NativeConstants.welcomeMessageBetaFinishStepTitle, - welcomeMessageBetaFinishStepContent = NativeConstants.welcomeMessageBetaFinishStepContent, - welcomeMessageLiveWelcomeStepTitle = NativeConstants.welcomeMessageLiveWelcomeStepTitle, - welcomeMessageLiveWelcomeStepContent = NativeConstants.welcomeMessageLiveWelcomeStepContent, - surveysStoreRatingThanksTitle = NativeConstants.surveysStoreRatingThanksTitle, - surveysStoreRatingThanksSubtitle = NativeConstants.surveysStoreRatingThanksSubtitle, - reportBugDescription = NativeConstants.reportBugDescription, - reportFeedbackDescription = NativeConstants.reportFeedbackDescription, - reportQuestionDescription = NativeConstants.reportQuestionDescription, - requestFeatureDescription = NativeConstants.requestFeatureDescription, - discardAlertTitle = NativeConstants.discardAlertTitle, - discardAlertMessage = NativeConstants.discardAlertMessage, - discardAlertCancel = NativeConstants.discardAlertCancel, - discardAlertAction = NativeConstants.discardAlertAction, - addAttachmentButtonTitleStringName = NativeConstants.addAttachmentButtonTitleStringName, - reportReproStepsDisclaimerBody = NativeConstants.reportReproStepsDisclaimerBody, - reportReproStepsDisclaimerLink = NativeConstants.reportReproStepsDisclaimerLink, - reproStepsProgressDialogBody = NativeConstants.reproStepsProgressDialogBody, - reproStepsListHeader = NativeConstants.reproStepsListHeader, - reproStepsListDescription = NativeConstants.reproStepsListDescription, - reproStepsListEmptyStateDescription = NativeConstants.reproStepsListEmptyStateDescription, - reproStepsListItemTitle = NativeConstants.reproStepsListItemTitle, - screenRecording = NativeConstants.screenRecording, - insufficientContentMessage = NativeConstants.insufficientContentMessage, - insufficientContentTitle = NativeConstants.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 c322b77bf..e5f3fcaae 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, } From 91917003438c99ca363dd6b04b7ccdf68c557266 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 16:07:14 +0200 Subject: [PATCH 08/16] Add Replies types --- src/native/RepliesNativeModule.ts | 24 ++++++++++++++++++++ src/native/index.ts | 3 ++- test/mocks/mockReplies.ts | 37 ++++++++++++++++++------------- 3 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 src/native/RepliesNativeModule.ts diff --git a/src/native/RepliesNativeModule.ts b/src/native/RepliesNativeModule.ts new file mode 100644 index 000000000..b3db292da --- /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/index.ts b/src/native/index.ts index a2c991f86..410e7fd95 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -8,6 +8,7 @@ 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'; export interface NativeModule extends ReactNativeModule, Record { getConstants: () => Record; @@ -19,7 +20,7 @@ interface InstabugNativeModules { IBGCrashReporting: CrashReportingNativeModule; IBGFeatureRequests: FeatureRequestsNativeModule; Instabug: InstabugNativeModule; - IBGReplies: NativeModule; + IBGReplies: RepliesNativeModule; IBGSurveys: NativeModule; } diff --git a/test/mocks/mockReplies.ts b/test/mocks/mockReplies.ts index 0fe09219f..793556bc8 100644 --- a/test/mocks/mockReplies.ts +++ b/test/mocks/mockReplies.ts @@ -1,18 +1,23 @@ +import type { RepliesNativeModule } from '../../src/native/RepliesNativeModule'; + +const mockedReplies: 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 { - 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(), - }, + IBGReplies: mockedReplies, }; From c61164b9585d314090e7408f2c48f77bf42006d2 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 16:16:43 +0200 Subject: [PATCH 09/16] Add Surveys types --- src/modules/Surveys.ts | 5 ++--- src/native/SurveysNativeModule.ts | 26 ++++++++++++++++++++++++++ src/native/index.ts | 12 +++--------- src/utils/IBGEventEmitter.ts | 15 ++------------- test/mocks/mockSurveys.ts | 31 ++++++++++++++++++------------- 5 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 src/native/SurveysNativeModule.ts diff --git a/src/modules/Surveys.ts b/src/modules/Surveys.ts index ec6b2a5e6..b66fdbff0 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/SurveysNativeModule.ts b/src/native/SurveysNativeModule.ts new file mode 100644 index 000000000..575a26d3e --- /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 index 410e7fd95..aabd4234b 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -1,7 +1,4 @@ -import { - NativeModule as ReactNativeModule, - NativeModules as ReactNativeModules, -} from 'react-native'; +import { NativeModules as ReactNativeModules } from 'react-native'; import type { ApmNativeModule } from './ApmNativeModule'; import type { BugReportingNativeModule } from './BugReportingNativeModule'; @@ -9,10 +6,7 @@ import type { CrashReportingNativeModule } from './CrashReportingNativeModule'; import type { FeatureRequestsNativeModule } from './FeatureRequestsNativeModule'; import type { InstabugNativeModule } from './InstabugNativeModule'; import type { RepliesNativeModule } from './RepliesNativeModule'; - -export interface NativeModule extends ReactNativeModule, Record { - getConstants: () => Record; -} +import type { SurveysNativeModule } from './SurveysNativeModule'; interface InstabugNativeModules { IBGAPM: ApmNativeModule; @@ -21,7 +15,7 @@ interface InstabugNativeModules { IBGFeatureRequests: FeatureRequestsNativeModule; Instabug: InstabugNativeModule; IBGReplies: RepliesNativeModule; - IBGSurveys: NativeModule; + IBGSurveys: SurveysNativeModule; } export const NativeModules = ReactNativeModules as InstabugNativeModules; diff --git a/src/utils/IBGEventEmitter.ts b/src/utils/IBGEventEmitter.ts index 70ce536d5..57503d838 100644 --- a/src/utils/IBGEventEmitter.ts +++ b/src/utils/IBGEventEmitter.ts @@ -1,18 +1,7 @@ -import { - DeviceEventEmitter, - NativeAppEventEmitter, - Platform, - NativeModule as ReactNativeModule, -} from 'react-native'; - -import type { NativeModule } from '../native'; +import { DeviceEventEmitter, NativeAppEventEmitter, NativeModule, Platform } from 'react-native'; export default { - addListener: ( - nativeModule: NativeModule | ReactNativeModule, - eventName: string, - callback: (data: any) => void, - ) => { + addListener: (nativeModule: NativeModule, eventName: string, callback: (data: any) => void) => { if (Platform.OS === 'ios') { nativeModule.addListener(eventName); NativeAppEventEmitter.addListener(eventName, callback); diff --git a/test/mocks/mockSurveys.ts b/test/mocks/mockSurveys.ts index de6891641..f58640073 100644 --- a/test/mocks/mockSurveys.ts +++ b/test/mocks/mockSurveys.ts @@ -1,15 +1,20 @@ +import type { SurveysNativeModule } from '../../src/native/SurveysNativeModule'; + +const mockedSurveys: 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 { - 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(), - }, + IBGSurveys: mockedSurveys, }; From 4e4e4325a50f8c72f3f593060fe36a482e14d155 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 16:21:52 +0200 Subject: [PATCH 10/16] Fix failing CrashReporting tests --- src/modules/CrashReporting.ts | 2 +- src/native/CrashReportingNativeModule.ts | 4 ++-- src/utils/InstabugUtils.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/CrashReporting.ts b/src/modules/CrashReporting.ts index 03f536184..d1859dda7 100644 --- a/src/modules/CrashReporting.ts +++ b/src/modules/CrashReporting.ts @@ -36,7 +36,7 @@ export const reportError = (error: ExtendedError) => { message: error.name + ' - ' + error.message, e_message: error.message, e_name: error.name, - os: Platform.select({ ios: 'ios' as const, android: 'android' as const })!, + os: Platform.OS, platform: 'react_native' as const, exception: jsStackTrace, }; diff --git a/src/native/CrashReportingNativeModule.ts b/src/native/CrashReportingNativeModule.ts index 8b7d78668..8124c2a0f 100644 --- a/src/native/CrashReportingNativeModule.ts +++ b/src/native/CrashReportingNativeModule.ts @@ -1,11 +1,11 @@ -import type { NativeModule } from 'react-native'; +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: 'android' | 'ios'; + os: typeof Platform['OS']; platform: 'react_native'; exception: StackFrame[]; } diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 299b684a1..9a63efaab 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -75,7 +75,7 @@ export const captureJsErrors = () => { message: err.name + ' - ' + err.message, e_message: err.message, e_name: err.name, - os: Platform.select({ ios: 'ios' as const, android: 'android' as const })!, + os: Platform.OS, platform: 'react_native' as const, exception: jsStackTrace, }; From 5d1bbc3bc1052f206f1f4514bef28fa9c883ddf3 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Thu, 16 Feb 2023 16:23:31 +0200 Subject: [PATCH 11/16] Fix failing APM tests --- test/modules/APM.spec.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/modules/APM.spec.ts b/test/modules/APM.spec.ts index 94ec8493b..cb606b3bf 100644 --- a/test/modules/APM.spec.ts +++ b/test/modules/APM.spec.ts @@ -67,9 +67,9 @@ 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(), - ); + NativeAPM.startExecutionTrace = jest + .fn() + .mockImplementationOnce((_: any, __: any, callback: () => any) => callback()); const promise = APM.startExecutionTrace('trace'); @@ -77,9 +77,11 @@ 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'), - ); + NativeAPM.startExecutionTrace = jest + .fn() + .mockImplementationOnce((_: any, __: any, callback: (arg0: string) => any) => + callback('trace-id'), + ); const promise = APM.startExecutionTrace('trace'); From 04518985141876ebc69299d303b919a83bdd5d12 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 26 Feb 2023 12:09:40 +0200 Subject: [PATCH 12/16] Fix Type Definitions --- src/modules/FeatureRequests.ts | 6 ++++-- src/native/BugReportingNativeModule.ts | 8 ++++---- src/native/FeatureRequestsNativeModule.ts | 2 +- src/native/InstabugNativeModule.ts | 21 ++++++++++----------- test/mocks/mockInstabug.ts | 1 - test/modules/FeatureRequests.spec.ts | 5 ++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/modules/FeatureRequests.ts b/src/modules/FeatureRequests.ts index 2ac2821a2..08453a7ee 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/native/BugReportingNativeModule.ts b/src/native/BugReportingNativeModule.ts index c8b339fa5..cc4dbe59d 100644 --- a/src/native/BugReportingNativeModule.ts +++ b/src/native/BugReportingNativeModule.ts @@ -20,9 +20,9 @@ import type { } from '../utils/Enums'; export interface BugReportingNativeModule extends NativeModule { - // Essential APIs// + // Essential APIs // setEnabled(isEnabled: boolean): void; - show(type: reportType | ReportType, arg1: option[] | InvocationOption[]): void; + show(type: reportType | ReportType, options: option[] | InvocationOption[]): void; // Customization APIs // setInvocationEvents(events: invocationEvent[] | InvocationEvent[]): void; @@ -30,7 +30,7 @@ export interface BugReportingNativeModule extends NativeModule { setExtendedBugReportMode(mode: extendedBugReportMode | ExtendedBugReportMode): void; setReportTypes(types: reportType[] | ReportType[]): void; setDisclaimerText(text: string): void; - setCommentMinimumCharacterCount(limit: number, arg1: reportType[] | ReportType[]): void; + setCommentMinimumCharacterCount(limit: number, reportTypes: reportType[] | ReportType[]): void; setFloatingButtonEdge(edge: floatingButtonEdge | FloatingButtonPosition, offset: number): void; setVideoRecordingFloatingButtonPosition(buttonPosition: position | RecordingButtonPosition): void; setEnabledAttachmentTypes( @@ -40,7 +40,7 @@ export interface BugReportingNativeModule extends NativeModule { screenRecording: boolean, ): void; - // Screen Recording APIs + // Screen Recording APIs // setAutoScreenRecordingEnabled(isEnabled: boolean): void; setAutoScreenRecordingDuration(maxDuration: number): void; setViewHierarchyEnabled(isEnabled: boolean): void; diff --git a/src/native/FeatureRequestsNativeModule.ts b/src/native/FeatureRequestsNativeModule.ts index ecce98be8..6fc8d6529 100644 --- a/src/native/FeatureRequestsNativeModule.ts +++ b/src/native/FeatureRequestsNativeModule.ts @@ -8,6 +8,6 @@ export interface FeatureRequestsNativeModule extends NativeModule { show(): void; setEmailFieldRequiredForFeatureRequests( isEmailFieldRequired: boolean, - types: actionTypes | ActionType, + types: actionTypes[] | ActionType[], ): void; } diff --git a/src/native/InstabugNativeModule.ts b/src/native/InstabugNativeModule.ts index 6d4669588..ab37e9c6b 100644 --- a/src/native/InstabugNativeModule.ts +++ b/src/native/InstabugNativeModule.ts @@ -94,18 +94,17 @@ export interface InstabugNativeModule extends NativeModule { setFileAttachment(filePath: string, fileName?: string): void; // Report APIs // - getReport(): void; setPreSendingHandler(handler?: (report: Report) => void): void; - appendTagToReport(tag: string): unknown; - appendConsoleLogToReport(consoleLog: string): unknown; - setUserAttributeToReport(key: string, value: string): unknown; - logDebugToReport(log: string): unknown; - logVerboseToReport(log: string): unknown; - logWarnToReport(log: string): unknown; - logErrorToReport(log: string): unknown; - logInfoToReport(log: string): unknown; - addFileAttachmentWithURLToReport(url: string, filename?: string): unknown; - addFileAttachmentWithDataToReport(data: string, filename?: string): unknown; + 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 */ diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 6fdc25805..f9b0d746f 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -45,7 +45,6 @@ const mockedInstabug: InstabugNativeModule = { show: jest.fn(), setPreSendingHandler: jest.fn(), callPrivateApi: jest.fn(), - getReport: jest.fn(), reportScreenChange: jest.fn(), addExperiments: jest.fn(), removeExperiments: jest.fn(), diff --git a/test/modules/FeatureRequests.spec.ts b/test/modules/FeatureRequests.spec.ts index 512660673..b19aeeb49 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', () => { From ed8ae1aae7392e466e8a0450e99916204826b2cb Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 26 Feb 2023 12:15:59 +0200 Subject: [PATCH 13/16] Remove Redundant `as const` --- src/modules/CrashReporting.ts | 2 +- src/utils/InstabugUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/CrashReporting.ts b/src/modules/CrashReporting.ts index d1859dda7..c9b827eea 100644 --- a/src/modules/CrashReporting.ts +++ b/src/modules/CrashReporting.ts @@ -37,7 +37,7 @@ export const reportError = (error: ExtendedError) => { e_message: error.message, e_name: error.name, os: Platform.OS, - platform: 'react_native' as const, + platform: 'react_native', exception: jsStackTrace, }; diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 9a63efaab..f107eb137 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -76,7 +76,7 @@ export const captureJsErrors = () => { e_message: err.message, e_name: err.name, os: Platform.OS, - platform: 'react_native' as const, + platform: 'react_native', exception: jsStackTrace, }; From 7d0cb9c8b6252d9554ad82cc034e5e4699a683e2 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 26 Feb 2023 12:22:13 +0200 Subject: [PATCH 14/16] Rename Mocks --- test/mocks/mockAPM.ts | 4 ++-- test/mocks/mockBugReporting.ts | 4 ++-- test/mocks/mockCrashReporting.ts | 4 ++-- test/mocks/mockFeatureRequests.ts | 4 ++-- test/mocks/mockInstabug.ts | 4 ++-- test/mocks/mockReplies.ts | 4 ++-- test/mocks/mockSurveys.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/mocks/mockAPM.ts b/test/mocks/mockAPM.ts index 08cf38045..1ed28c05a 100644 --- a/test/mocks/mockAPM.ts +++ b/test/mocks/mockAPM.ts @@ -1,6 +1,6 @@ import type { ApmNativeModule } from '../../src/native/ApmNativeModule'; -const mockedApm: ApmNativeModule = { +const mockAPM: ApmNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEnabled: jest.fn(), @@ -18,5 +18,5 @@ const mockedApm: ApmNativeModule = { }; export default { - IBGAPM: mockedApm, + IBGAPM: mockAPM, }; diff --git a/test/mocks/mockBugReporting.ts b/test/mocks/mockBugReporting.ts index 8222f58c8..17d3016a4 100644 --- a/test/mocks/mockBugReporting.ts +++ b/test/mocks/mockBugReporting.ts @@ -1,6 +1,6 @@ import type { BugReportingNativeModule } from '../../src/native/BugReportingNativeModule'; -const mockedBugReporting: BugReportingNativeModule = { +const mockBugReporting: BugReportingNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEnabled: jest.fn(), @@ -26,5 +26,5 @@ const mockedBugReporting: BugReportingNativeModule = { }; export default { - IBGBugReporting: mockedBugReporting, + IBGBugReporting: mockBugReporting, }; diff --git a/test/mocks/mockCrashReporting.ts b/test/mocks/mockCrashReporting.ts index 24c7c8014..822fa01d5 100644 --- a/test/mocks/mockCrashReporting.ts +++ b/test/mocks/mockCrashReporting.ts @@ -1,6 +1,6 @@ import type { CrashReportingNativeModule } from '../../src/native/CrashReportingNativeModule'; -const mockedCrashReporting: CrashReportingNativeModule = { +const mockCrashReporting: CrashReportingNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEnabled: jest.fn(), @@ -9,5 +9,5 @@ const mockedCrashReporting: CrashReportingNativeModule = { }; export default { - IBGCrashReporting: mockedCrashReporting, + IBGCrashReporting: mockCrashReporting, }; diff --git a/test/mocks/mockFeatureRequests.ts b/test/mocks/mockFeatureRequests.ts index 53cb5311e..d5a6d0f7a 100644 --- a/test/mocks/mockFeatureRequests.ts +++ b/test/mocks/mockFeatureRequests.ts @@ -1,6 +1,6 @@ import type { FeatureRequestsNativeModule } from '../../src/native/FeatureRequestsNativeModule'; -const mockedFeatureRequests: FeatureRequestsNativeModule = { +const mockFeatureRequests: FeatureRequestsNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEmailFieldRequiredForFeatureRequests: jest.fn(), @@ -9,5 +9,5 @@ const mockedFeatureRequests: FeatureRequestsNativeModule = { }; export default { - IBGFeatureRequests: mockedFeatureRequests, + IBGFeatureRequests: mockFeatureRequests, }; diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index f9b0d746f..6caf42051 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -1,6 +1,6 @@ import type { InstabugNativeModule } from '../../src/native/InstabugNativeModule'; -const mockedInstabug: InstabugNativeModule = { +const mockInstabug: InstabugNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), getConstants: jest.fn().mockReturnValue({}), @@ -64,5 +64,5 @@ const mockedInstabug: InstabugNativeModule = { }; export default { - Instabug: mockedInstabug, + Instabug: mockInstabug, }; diff --git a/test/mocks/mockReplies.ts b/test/mocks/mockReplies.ts index 793556bc8..dfde21d43 100644 --- a/test/mocks/mockReplies.ts +++ b/test/mocks/mockReplies.ts @@ -1,6 +1,6 @@ import type { RepliesNativeModule } from '../../src/native/RepliesNativeModule'; -const mockedReplies: RepliesNativeModule = { +const mockReplies: RepliesNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEnabled: jest.fn(), @@ -19,5 +19,5 @@ const mockedReplies: RepliesNativeModule = { }; export default { - IBGReplies: mockedReplies, + IBGReplies: mockReplies, }; diff --git a/test/mocks/mockSurveys.ts b/test/mocks/mockSurveys.ts index f58640073..d1e3487ed 100644 --- a/test/mocks/mockSurveys.ts +++ b/test/mocks/mockSurveys.ts @@ -1,6 +1,6 @@ import type { SurveysNativeModule } from '../../src/native/SurveysNativeModule'; -const mockedSurveys: SurveysNativeModule = { +const mockSurveys: SurveysNativeModule = { addListener: jest.fn(), removeListeners: jest.fn(), setEnabled: jest.fn(), @@ -16,5 +16,5 @@ const mockedSurveys: SurveysNativeModule = { }; export default { - IBGSurveys: mockedSurveys, + IBGSurveys: mockSurveys, }; From 4486ff49b27fc9a5bcb124aec30e6941ac74e066 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 26 Feb 2023 12:29:52 +0200 Subject: [PATCH 15/16] Fix Native APM mocks --- test/modules/APM.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/modules/APM.spec.ts b/test/modules/APM.spec.ts index cb606b3bf..b8dcfd29d 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,9 +69,9 @@ describe('APM Module', () => { }); it("should throw an error if native startExecutionTrace didn't return an ID", async () => { - NativeAPM.startExecutionTrace = jest - .fn() - .mockImplementationOnce((_: any, __: any, callback: () => any) => callback()); + mocked(NativeAPM).startExecutionTrace.mockImplementationOnce((_, __, callback) => + callback(null), + ); const promise = APM.startExecutionTrace('trace'); @@ -77,11 +79,9 @@ describe('APM Module', () => { }); it('should resolve with an Trace object if native startExecutionTrace returned an ID', async () => { - NativeAPM.startExecutionTrace = jest - .fn() - .mockImplementationOnce((_: any, __: any, callback: (arg0: string) => any) => - callback('trace-id'), - ); + mocked(NativeAPM).startExecutionTrace.mockImplementationOnce((_, __, callback) => + callback('trace-id'), + ); const promise = APM.startExecutionTrace('trace'); From 50353ab0ab18bd93746337d99129ef3957b08c49 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 26 Feb 2023 13:04:18 +0200 Subject: [PATCH 16/16] Add type-safety to native modules --- src/native/index.ts | 4 ++-- test/mocks/mockAPM.ts | 4 +--- test/mocks/mockBugReporting.ts | 4 +--- test/mocks/mockCrashReporting.ts | 4 +--- test/mocks/mockFeatureRequests.ts | 4 +--- test/mocks/mockInstabug.ts | 4 +--- test/mocks/mockNativeModules.ts | 24 +++++++++++------------- test/mocks/mockReplies.ts | 4 +--- test/mocks/mockSurveys.ts | 4 +--- 9 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/native/index.ts b/src/native/index.ts index aabd4234b..ba8940177 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -8,7 +8,7 @@ import type { InstabugNativeModule } from './InstabugNativeModule'; import type { RepliesNativeModule } from './RepliesNativeModule'; import type { SurveysNativeModule } from './SurveysNativeModule'; -interface InstabugNativeModules { +export interface InstabugNativePackage { IBGAPM: ApmNativeModule; IBGBugReporting: BugReportingNativeModule; IBGCrashReporting: CrashReportingNativeModule; @@ -18,7 +18,7 @@ interface InstabugNativeModules { IBGSurveys: SurveysNativeModule; } -export const NativeModules = ReactNativeModules as InstabugNativeModules; +export const NativeModules = ReactNativeModules as InstabugNativePackage; export const NativeAPM = NativeModules.IBGAPM; export const NativeBugReporting = NativeModules.IBGBugReporting; diff --git a/test/mocks/mockAPM.ts b/test/mocks/mockAPM.ts index 1ed28c05a..8b8c4c681 100644 --- a/test/mocks/mockAPM.ts +++ b/test/mocks/mockAPM.ts @@ -17,6 +17,4 @@ const mockAPM: ApmNativeModule = { networkLog: jest.fn(), }; -export default { - IBGAPM: mockAPM, -}; +export default mockAPM; diff --git a/test/mocks/mockBugReporting.ts b/test/mocks/mockBugReporting.ts index 17d3016a4..fa0f07d19 100644 --- a/test/mocks/mockBugReporting.ts +++ b/test/mocks/mockBugReporting.ts @@ -25,6 +25,4 @@ const mockBugReporting: BugReportingNativeModule = { setCommentMinimumCharacterCount: jest.fn(), }; -export default { - IBGBugReporting: mockBugReporting, -}; +export default mockBugReporting; diff --git a/test/mocks/mockCrashReporting.ts b/test/mocks/mockCrashReporting.ts index 822fa01d5..43daecca0 100644 --- a/test/mocks/mockCrashReporting.ts +++ b/test/mocks/mockCrashReporting.ts @@ -8,6 +8,4 @@ const mockCrashReporting: CrashReportingNativeModule = { sendJSCrash: jest.fn(), }; -export default { - IBGCrashReporting: mockCrashReporting, -}; +export default mockCrashReporting; diff --git a/test/mocks/mockFeatureRequests.ts b/test/mocks/mockFeatureRequests.ts index d5a6d0f7a..9ed48c02b 100644 --- a/test/mocks/mockFeatureRequests.ts +++ b/test/mocks/mockFeatureRequests.ts @@ -8,6 +8,4 @@ const mockFeatureRequests: FeatureRequestsNativeModule = { setEnabled: jest.fn(), }; -export default { - IBGFeatureRequests: mockFeatureRequests, -}; +export default mockFeatureRequests; diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 6caf42051..f8bf85ff1 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -63,6 +63,4 @@ const mockInstabug: InstabugNativeModule = { setNetworkLoggingEnabled: jest.fn(), }; -export default { - Instabug: mockInstabug, -}; +export default mockInstabug; diff --git a/test/mocks/mockNativeModules.ts b/test/mocks/mockNativeModules.ts index 0ba3191f9..9112004f1 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 dfde21d43..c2c86b731 100644 --- a/test/mocks/mockReplies.ts +++ b/test/mocks/mockReplies.ts @@ -18,6 +18,4 @@ const mockReplies: RepliesNativeModule = { setSystemReplyNotificationSoundEnabled: jest.fn(), }; -export default { - IBGReplies: mockReplies, -}; +export default mockReplies; diff --git a/test/mocks/mockSurveys.ts b/test/mocks/mockSurveys.ts index d1e3487ed..d94af4f51 100644 --- a/test/mocks/mockSurveys.ts +++ b/test/mocks/mockSurveys.ts @@ -15,6 +15,4 @@ const mockSurveys: SurveysNativeModule = { setShouldShowWelcomeScreen: jest.fn(), }; -export default { - IBGSurveys: mockSurveys, -}; +export default mockSurveys;