diff --git a/jest.config.js b/jest.config.js index 4b993cd4..404ff992 100644 --- a/jest.config.js +++ b/jest.config.js @@ -31,7 +31,7 @@ const baseTransform = { const baseTransformIgnorePatterns = [ // 'node_modules/(?!(.pnpm/|@op-engineering|drizzle-orm|lodash-es|@babel/runtime))', - 'node_modules/(?!(?:.pnpm/)?((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|color|@op-engineering|drizzle-orm|lodash-es))', + 'node_modules/(?!(?:.pnpm/)?((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|@material/material-color-utilities|@pchmn/expo-material3-theme|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|color|@op-engineering|drizzle-orm|lodash-es))', ]; module.exports = { diff --git a/src/screens/settings/SettingsCustomCodeScreen/Components/__tests__/CustomCodeCards.test.tsx b/src/screens/settings/SettingsCustomCodeScreen/Components/__tests__/CustomCodeCards.test.tsx index c051a02b..3b86c90b 100644 --- a/src/screens/settings/SettingsCustomCodeScreen/Components/__tests__/CustomCodeCards.test.tsx +++ b/src/screens/settings/SettingsCustomCodeScreen/Components/__tests__/CustomCodeCards.test.tsx @@ -1,4 +1,5 @@ import { fireEvent, render, screen } from '@test-utils'; +import type { ReactNode } from 'react'; import { ReplaceItem } from '../ListItems'; import Snippet from '../Snippet'; @@ -24,6 +25,33 @@ jest.mock('@hooks/persisted', () => ({ useTheme: () => theme, })); +jest.mock('@components/AppErrorBoundary/AppErrorBoundary', () => ({ + __esModule: true, + default: ({ children }: { children: ReactNode }) => children, +})); + +jest.mock('@screens/novel/NovelContext', () => ({ + NovelContextProvider: ({ children }: { children: ReactNode }) => children, +})); + +jest.mock('react-native-safe-area-context', () => { + const ReactModule = require('react'); + const { View } = jest.requireActual('react-native'); + const frame = { height: 800, width: 400, x: 0, y: 0 }; + const insets = { bottom: 0, left: 0, right: 0, top: 0 }; + + return { + SafeAreaFrameContext: ReactModule.createContext(frame), + SafeAreaInsetsContext: ReactModule.createContext(insets), + SafeAreaProvider: ({ children }: { children: ReactNode }) => children, + SafeAreaView: ({ children, ...props }: { children: ReactNode }) => + ReactModule.createElement(View, props, children), + initialWindowMetrics: { frame, insets }, + useSafeAreaFrame: () => frame, + useSafeAreaInsets: () => insets, + }; +}); + jest.mock('@i18n/translations', () => ({ getString: (key: string) => ({ @@ -76,7 +104,9 @@ describe('custom code cards', () => { />, ); - const card = screen.getByLabelText('Bigger paragraph spacing'); + const card = screen.getByRole('button', { + name: 'Bigger paragraph spacing', + }); expect(card.props.onPress).toBeUndefined(); fireEvent(card, 'longPress'); diff --git a/test/mocks/nativeModules.js b/test/mocks/nativeModules.js index 6f2256e1..e5f48124 100644 --- a/test/mocks/nativeModules.js +++ b/test/mocks/nativeModules.js @@ -1,6 +1,27 @@ // require('react-native-gesture-handler/jestSetup'); // require('react-native-reanimated').setUpTests(); +jest.mock('react-native-device-info', () => ({ + __esModule: true, + default: { + getApiLevel: jest.fn().mockResolvedValue(35), + getBrand: jest.fn(() => 'mock-brand'), + getBuildId: jest.fn().mockResolvedValue('mock-build-id'), + getBuildNumber: jest.fn(() => '1'), + getBundleId: jest.fn(() => 'com.lnreader'), + getDeviceId: jest.fn(() => 'mock-device'), + getManufacturer: jest.fn().mockResolvedValue('mock-manufacturer'), + getModel: jest.fn(() => 'mock-model'), + getSystemName: jest.fn(() => 'Android'), + getSystemVersion: jest.fn(() => '15'), + supportedAbis: jest.fn().mockResolvedValue([]), + }, + getBatteryLevel: jest.fn().mockResolvedValue(1), + getBatteryLevelSync: jest.fn(() => 1), + getUserAgentSync: jest.fn(() => 'LNReader test'), + useBatteryLevel: jest.fn(() => 1), +})); + jest.mock('@modules/native-file', () => ({ __esModule: true, default: {