mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-11 09:54:10 +01:00
chore(suite-native): refactor and update intl mocks
This commit is contained in:
committed by
Jiří Bažant
parent
d28e166086
commit
c2be542f83
@@ -18,9 +18,9 @@ module.exports = {
|
||||
watchPathIgnorePatterns,
|
||||
moduleNameMapper: {
|
||||
...moduleNameMapper,
|
||||
'^@evolu/common/evolu$': '<rootDir>/../../suite-native/test-utils/src/evoluMock.ts',
|
||||
'^@evolu/common/evolu$': '<rootDir>/../../suite-native/test-utils/src/mocks/evoluMock.ts',
|
||||
'^@evolu/react-native/expo-sqlite$':
|
||||
'<rootDir>/../../suite-native/test-utils/src/evoluMock.ts',
|
||||
'<rootDir>/../../suite-native/test-utils/src/mocks/evoluMock.ts',
|
||||
},
|
||||
testEnvironment: 'jsdom',
|
||||
preset: 'jest-expo',
|
||||
@@ -32,13 +32,12 @@ module.exports = {
|
||||
'node_modules/(?!((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|@shopify/react-native-skia|@shopify/flash-list|@noble|@scure|@evolu|nanoid|msgpackr|@gorhom|uuid)',
|
||||
],
|
||||
setupFiles: [
|
||||
'<rootDir>/../../suite-native/test-utils/src/nitroModulesMock.js',
|
||||
'<rootDir>/../../suite-native/test-utils/src/mocks/expoAndRNMock.jsx',
|
||||
'<rootDir>/../../suite-native/test-utils/src/mocks/everstakeJestSetup.js',
|
||||
'<rootDir>/../../suite-native/test-utils/src/mocks/TextEncoderMock.js',
|
||||
'<rootDir>/../../node_modules/@shopify/react-native-skia/jestSetup.js',
|
||||
'<rootDir>/../../node_modules/@shopify/flash-list/jestSetup.js',
|
||||
'<rootDir>/../../node_modules/react-native-gesture-handler/jestSetup.js',
|
||||
'<rootDir>/../../suite-native/test-utils/src/everstakeJestSetup.js',
|
||||
'<rootDir>/../../suite-native/test-utils/src/expoMock.jsx',
|
||||
'<rootDir>/../../suite-native/test-utils/src/TextEncoderMock.js',
|
||||
'<rootDir>/../../suite-native/firmware/src/jestSetup.js',
|
||||
'<rootDir>/../../suite-native/connection-status/src/jestSetup.js',
|
||||
'<rootDir>/../../suite-native/react-native-graph/src/jestSetup.js',
|
||||
@@ -48,5 +47,6 @@ module.exports = {
|
||||
'<rootDir>/../../suite-native/module-connect-popup/src/jest.setup.ts',
|
||||
'<rootDir>/../../suite-native/module-device-onboarding/src/jest.setup.ts',
|
||||
'<rootDir>/../../suite-native/config/src/jest.setup.ts',
|
||||
'<rootDir>/../../suite-native/intl/src/jest.setup.ts',
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { IntlProvider as ReactIntlProvider } from 'react-intl';
|
||||
|
||||
// direct imports are used to avoid exposing the internal objects from the intl package.
|
||||
import { messages } from '@suite-native/intl/src/messages';
|
||||
import { flatten } from '@suite-native/intl/src/utils';
|
||||
import { messages } from './messages';
|
||||
import { flatten } from './utils';
|
||||
|
||||
// For uni test we always expect the messages to be in english, so the language selection logic can be omitted here.
|
||||
export const IntlProviderForTests = ({ children }: { children: React.ReactNode }) => {
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './hooks/useTranslate';
|
||||
export * from './IntlProvider';
|
||||
export { IntlProviderForTests } from './IntlProviderForTests';
|
||||
export * from './Translate';
|
||||
export * from './types';
|
||||
export * from './localeSlice';
|
||||
|
||||
6
suite-native/intl/src/jest.setup.ts
Normal file
6
suite-native/intl/src/jest.setup.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { messages as mockMessages } from './messages';
|
||||
|
||||
// Do not import those big message files in every test. We use EN only anyway.
|
||||
jest.mock('./hooks/useTranslatedMessages', () => ({
|
||||
useTranslatedMessages: () => mockMessages,
|
||||
}));
|
||||
@@ -20,7 +20,6 @@
|
||||
"@trezor/styles": "workspace:*",
|
||||
"@trezor/theme": "workspace:*",
|
||||
"react": "19.1.0",
|
||||
"react-intl": "^7.1.11",
|
||||
"react-native": "0.81.4",
|
||||
"react-native-keyboard-controller": "1.19.2",
|
||||
"react-native-permissions": "5.4.2",
|
||||
|
||||
@@ -5,11 +5,10 @@ import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
|
||||
import { NavigationContainer } from '@react-navigation/native';
|
||||
|
||||
import { FormatterProvider, FormatterProviderConfig } from '@suite-common/formatters';
|
||||
import { IntlProviderForTests } from '@suite-native/intl';
|
||||
import { StylesProvider, createRenderer } from '@trezor/styles';
|
||||
import { prepareNativeTheme } from '@trezor/theme';
|
||||
|
||||
import { IntlProviderForTests } from './IntlProviderForTests';
|
||||
|
||||
type ProviderProps = {
|
||||
children: ReactNode;
|
||||
formattersConfig?: FormatterProviderConfig;
|
||||
|
||||
@@ -3,7 +3,6 @@ import { View } from 'react-native';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { useFormattersConfig } from '@suite-native/formatters-config';
|
||||
import { IntlProvider } from '@suite-native/intl';
|
||||
import { PreloadedState, Store, initStore } from '@suite-native/state';
|
||||
|
||||
import { BasicProviderForTests } from './BasicProviderForTests';
|
||||
@@ -60,10 +59,7 @@ export const StoreProviderForTests = ({
|
||||
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<IntlProvider>
|
||||
{/* Intl is accessing redux store to get the locale. */}
|
||||
<BasicProviderWithFormattingConfig>{children}</BasicProviderWithFormattingConfig>
|
||||
</IntlProvider>
|
||||
<BasicProviderWithFormattingConfig>{children}</BasicProviderWithFormattingConfig>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -407,7 +407,7 @@ jest.mock('expo-constants', () => {
|
||||
|
||||
jest.mock('expo-video', () => ({ VideoView: () => null }));
|
||||
|
||||
jest.mock('redux-devtools-expo-dev-plugin', () => () => next => next);
|
||||
jest.mock('react-native-nitro-modules', () => ({}));
|
||||
|
||||
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
|
||||
|
||||
@@ -417,6 +417,8 @@ jest.mock('react-native-keyboard-controller', () =>
|
||||
require('react-native-keyboard-controller/jest'),
|
||||
);
|
||||
|
||||
jest.mock('redux-devtools-expo-dev-plugin', () => () => next => next);
|
||||
|
||||
jest.mock('@gorhom/bottom-sheet', () => {
|
||||
const { ScrollView } = require('react-native');
|
||||
const GorhomBottomSheetMock = require('@gorhom/bottom-sheet/mock');
|
||||
@@ -1 +0,0 @@
|
||||
jest.mock('react-native-nitro-modules', () => ({}));
|
||||
Reference in New Issue
Block a user