Files
inji-wallet/__mocks__/jest-init.js
Harsh Vardhan c05408413d [INJI-314] [INJI-900] add jest testing config, mocks and sample unit tests for Inji (#1340)
* [INJI-314] initial commit

Signed-off-by: Sri Kanth Kola <srikanthsri7447@gmail.com>

* [INJI-314] add WIP ut stuff

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-314] fix tsconfig for project type

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-314] kludge - skip checking types during unit tests

* mock image imports globally
* enable tests to run from any dir

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-314]: mocked modules

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-314]: mock react-native-google-signin

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-314]: use defined mock from google-signin lib

other details:
- mock base58.., rn-linear-gradient, expo-camera
- add @react-native/assets-registry to make jest-expo babel preset work

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-314] reorganise global const mocks into jest's setupFiles

Co-authored-by: srikanth716 <srikanthsri7447@gmail.com>
Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] write tests for ActivityLogEvent

* init relevant mocks
* remove redundant global mocks from test files

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] fixup mocks of mmkv, zip-archive, rnfs

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900]: write unit test for commonUtil

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-900]: write unit test for commonUtil

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-900]: sample unit test for settingsScreen

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-900] add SettingScreen test

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] update sample tests for commonUtil

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900]: refactoring the settingsScreen test for Android and IOS

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-900] update test snapshots and add kludge in auth for testing

kludge: auth state machine now exports a selector with optional fields
as state machine isn't running in a test environment

Co-authored-by: srikanth716 <srikanthsri7447@gmail.com>
Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900]: snapshot test to settings screen

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>

* [INJIMOB-900] update mocks for testing and ACK reviews

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] downgrade expo to match compatibility matrix

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] upgrade expo to 49 to build the iOS app(kludge)

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJIMOB-900] configure react-native-vector-icons as per README

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

---------

Signed-off-by: Sri Kanth Kola <srikanthsri7447@gmail.com>
Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>
Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>
Co-authored-by: Sri Kanth Kola <srikanthsri7447@gmail.com>
2024-04-02 11:22:01 +05:30

170 lines
4.6 KiB
JavaScript

import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
import mockedConstants from 'react-native.mock';
import mockArgon2 from 'react-native-argon2.mock';
import mockLocalAuthentication from 'expo-local-authentication.mock';
import mockRNLocalize from './react-native-localize.mock';
import mockReactNativeKeychain from 'react-native-keychain.mock';
import mockRNSecureKeyStore from 'react-native-secure-key-store.mock';
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js';
import mockLocalization from 'expo-localization.mock';
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
jest.mock('react-native-device-info', () => mockRNDeviceInfo);
jest.mock('react-native', () => require('./react-native.mock'));
jest.mock('expo-constants', () => mockedConstants);
jest.mock('react-native-argon2', () => mockArgon2);
jest.mock('react-native-securerandom');
jest.mock('expo-local-authentication', () => mockLocalAuthentication);
jest.mock('react-native-rsa-native', () =>
require('react-native-rsa-native.mock'),
);
jest.mock('telemetry-sdk', () => require('./telemetry-sdk.mock'));
jest.mock('react-native-localize', () => mockRNLocalize);
jest.mock('expo-localization', () => mockLocalization);
jest.mock('iso-639-3');
jest.mock('react-native-keychain', () => mockReactNativeKeychain);
jest.mock('react-native-secure-key-store', () => mockRNSecureKeyStore);
jest.mock('react-native-fs', () => require('react-native-fs.mock'));
jest.mock('react-native-zip-archive', () =>
require('./react-native-zip-archive.mock'),
);
jest.mock('react-native-biometrics-changed');
jest.mock('@react-navigation/native');
jest.mock('@mosip/tuvali');
jest.mock('react-native-bluetooth-state-manager');
jest.mock('react-native-permissions');
jest.mock('react-native-linear-gradient', () => (LinearGradient = jest.fn()));
jest.mock('expo-camera', () => {
return {
Camera: {
Constants: {
Type: {front: 0, back: 1},
},
},
CameraCapturedPicture: jest.fn(),
PermissionResponse: jest.fn(),
ImageType: jest.fn(),
Face: jest.fn(),
CameraType: jest.fn(),
};
});
jest.mock('base58-universal/main', () => require('base58-universal-main'));
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
jest.mock(
'react-native-shimmer-placeholder',
() => (ShimmerPlaceHolder = jest.fn()),
);
jest.mock(
'expo-camera/build/Camera.types',
() => (
(CameraType = jest.requireActual()),
(Face = jest.fn()),
(ImageType = jest.fn())
),
);
jest.mock(
'react-native-app-auth',
() => ((authorize = jest.fn()), (AuthorizeResult = jest.fn())),
);
jest.mock('react-native-vector-icons/MaterialIcons', () => (Icon = jest.fn()));
jest.mock(
'react-native-vector-icons/MaterialCommunityIcons',
() => (Icon = jest.fn()),
);
jest.mock('react-native-qrcode-svg', () => (QRCode = jest.fn()));
jest.mock('react-native-spinkit', () => (Spinner = jest.fn()));
jest.mock(
'react-native-zip-archive',
() => ((zip = jest.fn()), (unzip = jest.fn())),
);
jest.mock('react', () => ({
...jest.requireActual('react'),
useState: jest.fn(),
}));
jest.mock('react-i18next', () => ({
// this mock makes sure any components using the translate hook can use it without a warning being shown
useTranslation: () => {
return {
t: str => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
},
};
},
initReactI18next: {
type: '3rdParty',
init: () => {},
},
}));
jest.mock('@iriscan/biometric-sdk-react-native', () => ({
configure: jest.fn(),
// Add other functions or constants you need to mock here
}));
jest.mock('react-native-gesture-handler', () => {
const mockScrollView = jest.fn().mockReturnValue(null); // Mock ScrollView component
return {
ScrollView: mockScrollView,
// Add other components or utilities you want to mock from react-native-gesture-handler
};
});
jest.mock('@mosip/secure-keystore', () => ({
sign: jest.fn(),
encryptData: input => (input ? String(input) : 'mockedString'),
decryptData: input => (input ? String(input) : 'mockedString'),
deviceSupportsHardware: () => true,
}));
jest.mock('../machines/store', () => ({
getItem: jest.fn(),
StoreEvents: {
GET: () => 'mockedString',
EXPORT: () => 'mockedString',
},
}));
// Mocking useState
const mockState = jest.fn();
jest.mock('react', () => ({
...jest.requireActual('react'),
useState: initialState => [initialState, mockState],
useEffect: jest.fn(),
}));