BlueWallet/tests/setup.js

174 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-06-29 15:58:43 +03:00
/* global jest */
2021-07-21 09:46:03 -04:00
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js';
const consoleWarnOrig = console.warn;
console.warn = (...args) => {
if (!args[0].startsWith('WARNING: Sending to a future segwit version address can lead to loss of funds')) {
consoleWarnOrig.apply(consoleWarnOrig, args);
}
};
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
global.fetch = require('node-fetch');
2021-07-21 09:46:03 -04:00
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
2019-10-21 11:13:16 -04:00
jest.mock('react-native-watch-connectivity', () => {
return {
getIsWatchAppInstalled: jest.fn(() => Promise.resolve(false)),
2019-10-21 11:13:16 -04:00
subscribeToMessages: jest.fn(),
updateApplicationContext: jest.fn(),
2020-06-29 15:58:43 +03:00
};
});
jest.mock('react-native-secure-key-store', () => {
2021-05-18 21:38:18 +01:00
return {};
2020-06-29 15:58:43 +03:00
});
2020-07-31 14:43:55 +01:00
jest.mock('@react-native-community/push-notification-ios', () => {
return {};
});
jest.mock('react-native-device-info', () => {
2020-08-10 20:27:14 -04:00
return {
2021-05-24 13:16:03 +01:00
getUniqueId: jest.fn().mockReturnValue('uniqueId'),
2020-08-10 20:27:14 -04:00
getSystemName: jest.fn(),
getDeviceType: jest.fn().mockReturnValue(false),
2021-01-25 10:55:09 -05:00
hasGmsSync: jest.fn().mockReturnValue(true),
hasHmsSync: jest.fn().mockReturnValue(false),
2020-08-10 20:27:14 -04:00
};
2020-07-31 14:43:55 +01:00
});
jest.mock('react-native-quick-actions', () => {
return {
clearShortcutItems: jest.fn(),
setQuickActions: jest.fn(),
isSupported: jest.fn(),
2020-06-29 15:58:43 +03:00
};
});
jest.mock('react-native-default-preference', () => {
return {
setName: jest.fn(),
set: jest.fn(),
2020-06-29 15:58:43 +03:00
};
});
2020-02-25 12:36:49 +00: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 15:58:43 +03:00
};
});
jest.mock('react-native-document-picker', () => ({}));
2020-09-22 17:00:36 +01:00
jest.mock('react-native-haptic-feedback', () => ({}));
2020-12-19 23:23:20 +00:00
2021-09-09 12:00:11 +01:00
jest.mock('rn-ldk/lib/module', () => ({}));
jest.mock('rn-ldk/src/index', () => ({}));
2020-12-19 23:23:20 +00:00
const realmInstanceMock = {
close: function () {},
2021-04-27 20:37:23 +01:00
write: function () {},
2021-05-18 21:38:18 +01:00
objectForPrimaryKey: function () {
return {};
},
2020-12-19 23:23:20 +00:00
objects: function () {
const wallets = {
filtered: function () {
return [];
},
};
return wallets;
},
};
jest.mock('realm', () => {
return {
open: jest.fn(() => realmInstanceMock),
};
});
2021-03-25 15:28:25 +00:00
jest.mock('react-native-idle-timer', () => {
return {
setIdleTimerDisabled: jest.fn(),
};
});
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 06:24:04 -04:00
jest.mock('react-native-share', () => {
return {
open: jest.fn(),
};
});
2021-08-03 13:14:32 -04:00
jest.mock('../blue_modules/WidgetCommunication', () => {
return {
reloadAllTimelines: jest.fn(),
};
});
2021-06-02 17:33:37 +01:00
const keychainMock = {
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(),
};
jest.mock('react-native-keychain', () => keychainMock);
2021-03-25 15:28:25 +00:00
global.alert = () => {};