2020-06-29 14:58:43 +02:00
|
|
|
/* global jest */
|
|
|
|
|
2021-07-21 15:46:03 +02:00
|
|
|
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js';
|
|
|
|
|
2022-09-03 01:48:07 +02:00
|
|
|
const consoleWarnOrig = console.warn;
|
|
|
|
console.warn = (...args) => {
|
2023-01-28 13:46:43 +01:00
|
|
|
if (
|
2023-03-15 21:42:25 +01:00
|
|
|
typeof args[0] === 'string' &&
|
2023-03-15 22:42:53 +01:00
|
|
|
(args[0].startsWith('WARNING: Sending to a future segwit version address can lead to loss of funds') ||
|
|
|
|
args[0].startsWith('only compressed public keys are good'))
|
2023-01-28 13:46:43 +01:00
|
|
|
) {
|
|
|
|
return;
|
2022-09-03 01:48:07 +02:00
|
|
|
}
|
2023-01-28 13:46:43 +01:00
|
|
|
consoleWarnOrig.apply(consoleWarnOrig, args);
|
|
|
|
};
|
|
|
|
|
|
|
|
const consoleLogOrig = console.log;
|
|
|
|
console.log = (...args) => {
|
|
|
|
if (
|
2023-03-15 21:42:25 +01:00
|
|
|
typeof args[0] === 'string' &&
|
2023-03-15 22:42:53 +01:00
|
|
|
(args[0].startsWith('updating exchange rate') ||
|
|
|
|
args[0].startsWith('begin connection') ||
|
|
|
|
args[0].startsWith('TLS Connected to') ||
|
|
|
|
args[0].startsWith('connected to'))
|
2023-01-28 13:46:43 +01:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
consoleLogOrig.apply(consoleLogOrig, args);
|
2022-09-03 01:48:07 +02:00
|
|
|
};
|
|
|
|
|
2021-08-04 22:23:57 +02:00
|
|
|
global.net = require('net'); // needed by Electrum client. For RN it is proviced in shim.js
|
|
|
|
global.tls = require('tls'); // needed by Electrum client. For RN it is proviced in shim.js
|
2021-09-09 19:02:15 +02:00
|
|
|
global.fetch = require('node-fetch');
|
2021-08-04 22:23:57 +02:00
|
|
|
|
2021-07-21 15:46:03 +02:00
|
|
|
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
|
|
|
|
|
2019-10-21 17:13:16 +02:00
|
|
|
jest.mock('react-native-watch-connectivity', () => {
|
|
|
|
return {
|
2020-09-07 13:35:08 +02:00
|
|
|
getIsWatchAppInstalled: jest.fn(() => Promise.resolve(false)),
|
2019-10-21 17:13:16 +02:00
|
|
|
subscribeToMessages: jest.fn(),
|
|
|
|
updateApplicationContext: jest.fn(),
|
2020-06-29 14:58:43 +02:00
|
|
|
};
|
|
|
|
});
|
2019-11-03 01:25:55 +01:00
|
|
|
|
2020-03-20 16:25:23 +01:00
|
|
|
jest.mock('react-native-secure-key-store', () => {
|
2021-05-18 22:38:18 +02:00
|
|
|
return {};
|
2020-06-29 14:58:43 +02:00
|
|
|
});
|
2020-03-20 16:25:23 +01:00
|
|
|
|
2020-07-31 15:43:55 +02:00
|
|
|
jest.mock('@react-native-community/push-notification-ios', () => {
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
|
2023-10-20 21:06:45 +02:00
|
|
|
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'));
|
|
|
|
|
2020-07-31 15:43:55 +02:00
|
|
|
jest.mock('react-native-device-info', () => {
|
2020-08-11 02:27:14 +02:00
|
|
|
return {
|
2021-05-24 14:16:03 +02:00
|
|
|
getUniqueId: jest.fn().mockReturnValue('uniqueId'),
|
2020-08-11 02:27:14 +02:00
|
|
|
getSystemName: jest.fn(),
|
2021-07-18 18:34:03 +02:00
|
|
|
getDeviceType: jest.fn().mockReturnValue(false),
|
2021-01-25 16:55:09 +01:00
|
|
|
hasGmsSync: jest.fn().mockReturnValue(true),
|
|
|
|
hasHmsSync: jest.fn().mockReturnValue(false),
|
2024-05-15 16:08:22 +02:00
|
|
|
isTablet: jest.fn().mockReturnValue(false),
|
2020-08-11 02:27:14 +02:00
|
|
|
};
|
2020-07-31 15:43:55 +02:00
|
|
|
});
|
|
|
|
|
2019-11-03 01:25:55 +01:00
|
|
|
jest.mock('react-native-quick-actions', () => {
|
|
|
|
return {
|
|
|
|
clearShortcutItems: jest.fn(),
|
|
|
|
setQuickActions: jest.fn(),
|
|
|
|
isSupported: jest.fn(),
|
2020-06-29 14:58:43 +02:00
|
|
|
};
|
|
|
|
});
|
2019-11-03 01:25:55 +01:00
|
|
|
|
|
|
|
jest.mock('react-native-default-preference', () => {
|
|
|
|
return {
|
|
|
|
setName: jest.fn(),
|
|
|
|
set: jest.fn(),
|
2020-06-29 14:58:43 +02:00
|
|
|
};
|
|
|
|
});
|
2020-02-25 13:36:49 +01:00
|
|
|
|
2024-06-30 19:20:12 +02:00
|
|
|
jest.mock('@lodev09/react-native-true-sheet');
|
|
|
|
|
2020-02-25 13:36:49 +01:00
|
|
|
jest.mock('react-native-fs', () => {
|
|
|
|
return {
|
|
|
|
mkdir: jest.fn(),
|
|
|
|
moveFile: jest.fn(),
|
|
|
|
copyFile: jest.fn(),
|
|
|
|
pathForBundle: jest.fn(),
|
|
|
|
pathForGroup: jest.fn(),
|
|
|
|
getFSInfo: jest.fn(),
|
|
|
|
getAllExternalFilesDirs: jest.fn(),
|
|
|
|
unlink: jest.fn(),
|
|
|
|
exists: jest.fn(),
|
|
|
|
stopDownload: jest.fn(),
|
|
|
|
resumeDownload: jest.fn(),
|
|
|
|
isResumable: jest.fn(),
|
|
|
|
stopUpload: jest.fn(),
|
|
|
|
completeHandlerIOS: jest.fn(),
|
|
|
|
readDir: jest.fn(),
|
|
|
|
readDirAssets: jest.fn(),
|
|
|
|
existsAssets: jest.fn(),
|
|
|
|
readdir: jest.fn(),
|
|
|
|
setReadable: jest.fn(),
|
|
|
|
stat: jest.fn(),
|
|
|
|
readFile: jest.fn(),
|
|
|
|
read: jest.fn(),
|
|
|
|
readFileAssets: jest.fn(),
|
|
|
|
hash: jest.fn(),
|
|
|
|
copyFileAssets: jest.fn(),
|
|
|
|
copyFileAssetsIOS: jest.fn(),
|
|
|
|
copyAssetsVideoIOS: jest.fn(),
|
|
|
|
writeFile: jest.fn(),
|
|
|
|
appendFile: jest.fn(),
|
|
|
|
write: jest.fn(),
|
|
|
|
downloadFile: jest.fn(),
|
|
|
|
uploadFiles: jest.fn(),
|
|
|
|
touch: jest.fn(),
|
|
|
|
MainBundlePath: jest.fn(),
|
|
|
|
CachesDirectoryPath: jest.fn(),
|
|
|
|
DocumentDirectoryPath: jest.fn(),
|
|
|
|
ExternalDirectoryPath: jest.fn(),
|
|
|
|
ExternalStorageDirectoryPath: jest.fn(),
|
|
|
|
TemporaryDirectoryPath: jest.fn(),
|
|
|
|
LibraryDirectoryPath: jest.fn(),
|
|
|
|
PicturesDirectoryPath: jest.fn(),
|
2020-06-29 14:58:43 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-09-19 17:04:19 +02:00
|
|
|
jest.mock('react-native-document-picker', () => ({}));
|
2020-09-22 18:00:36 +02:00
|
|
|
|
|
|
|
jest.mock('react-native-haptic-feedback', () => ({}));
|
2020-12-20 00:23:20 +01:00
|
|
|
|
2021-09-09 13:00:11 +02:00
|
|
|
jest.mock('rn-ldk/lib/module', () => ({}));
|
|
|
|
jest.mock('rn-ldk/src/index', () => ({}));
|
|
|
|
|
2020-12-20 00:23:20 +01:00
|
|
|
const realmInstanceMock = {
|
2023-12-24 23:27:50 +01:00
|
|
|
create: function () {},
|
|
|
|
delete: function () {},
|
2020-12-20 00:23:20 +01:00
|
|
|
close: function () {},
|
2023-12-24 23:27:50 +01:00
|
|
|
write: function (transactionFn) {
|
|
|
|
if (typeof transactionFn === 'function') {
|
|
|
|
// to test if something is not right in Realm transactional database write
|
|
|
|
transactionFn();
|
|
|
|
}
|
|
|
|
},
|
2021-05-18 22:38:18 +02:00
|
|
|
objectForPrimaryKey: function () {
|
|
|
|
return {};
|
|
|
|
},
|
2020-12-20 00:23:20 +01:00
|
|
|
objects: function () {
|
|
|
|
const wallets = {
|
|
|
|
filtered: function () {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return wallets;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
jest.mock('realm', () => {
|
|
|
|
return {
|
2023-12-24 23:27:50 +01:00
|
|
|
UpdateMode: { Modified: 1 },
|
2020-12-20 00:23:20 +01:00
|
|
|
open: jest.fn(() => realmInstanceMock),
|
|
|
|
};
|
|
|
|
});
|
2021-03-25 16:28:25 +01:00
|
|
|
|
|
|
|
jest.mock('react-native-idle-timer', () => {
|
|
|
|
return {
|
|
|
|
setIdleTimerDisabled: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-03-04 18:51:11 +01:00
|
|
|
jest.mock('react-native-ios-context-menu', () => {
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
|
2021-03-25 16:28:25 +01:00
|
|
|
jest.mock('react-native-haptic-feedback', () => {
|
|
|
|
return {
|
|
|
|
trigger: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.mock('../blue_modules/analytics', () => {
|
|
|
|
const ret = jest.fn();
|
|
|
|
ret.ENUM = { CREATED_WALLET: '' };
|
|
|
|
return ret;
|
|
|
|
});
|
|
|
|
|
2021-04-19 12:24:04 +02:00
|
|
|
jest.mock('react-native-share', () => {
|
|
|
|
return {
|
|
|
|
open: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-03-04 18:51:11 +01:00
|
|
|
const mockKeychain = {
|
2021-06-02 18:33:37 +02:00
|
|
|
SECURITY_LEVEL_ANY: 'MOCK_SECURITY_LEVEL_ANY',
|
|
|
|
SECURITY_LEVEL_SECURE_SOFTWARE: 'MOCK_SECURITY_LEVEL_SECURE_SOFTWARE',
|
|
|
|
SECURITY_LEVEL_SECURE_HARDWARE: 'MOCK_SECURITY_LEVEL_SECURE_HARDWARE',
|
|
|
|
setGenericPassword: jest.fn().mockResolvedValue(),
|
|
|
|
getGenericPassword: jest.fn().mockResolvedValue(),
|
|
|
|
resetGenericPassword: jest.fn().mockResolvedValue(),
|
|
|
|
};
|
2023-03-04 18:51:11 +01:00
|
|
|
jest.mock('react-native-keychain', () => mockKeychain);
|
2021-06-02 18:33:37 +02:00
|
|
|
|
2023-04-21 17:39:12 +02:00
|
|
|
jest.mock('react-native-tcp-socket', () => mockKeychain);
|
|
|
|
|
2021-03-25 16:28:25 +01:00
|
|
|
global.alert = () => {};
|