Skip to content

Commit

Permalink
Merge pull request zingolabs#795 from juanky201271/dev_menu_moved_to_…
Browse files Browse the repository at this point in the history
…drawer

Menu moved to drawer & DRY tests
  • Loading branch information
dorianvp authored Mar 4, 2025
2 parents f441072 + 201ce0b commit d36c162
Show file tree
Hide file tree
Showing 73 changed files with 241 additions and 2,109 deletions.
1 change: 1 addition & 0 deletions __mocks__/@fortawesome/react-native-fontawesome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const FontAwesomeIcon = '';
2 changes: 2 additions & 0 deletions __mocks__/@react-native-clipboard/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const getString = jest.fn(() => Promise.resolve('mocked clipboard content'));
export const setString = jest.fn();
28 changes: 28 additions & 0 deletions __mocks__/@react-native-community/netinfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const RN = jest.requireActual('react-native');

export const NetInfoStateType = {
unknown: 'unknown',
none: 'none',
cellular: 'cellular',
wifi: 'wifi',
bluetooth: 'bluetooth',
ethernet: 'ethernet',
wimax: 'wimax',
vpn: 'vpn',
other: 'other',
};

RN.NativeModules.RNCNetInfo = {
execute: jest.fn(() => '{}'),
};

export default {
RNCNetInfo: RN,
addEventListener: jest.fn(),
fetch: jest.fn().mockImplementation(() =>
Promise.resolve({
isConnected: true,
isInternetReachable: true,
}),
),
};
28 changes: 28 additions & 0 deletions __mocks__/@react-native-community/netinfo/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const RN = jest.requireActual('react-native');

export const NetInfoStateType = {
unknown: 'unknown',
none: 'none',
cellular: 'cellular',
wifi: 'wifi',
bluetooth: 'bluetooth',
ethernet: 'ethernet',
wimax: 'wimax',
vpn: 'vpn',
other: 'other',
};

RN.NativeModules.RNCNetInfo = {
execute: jest.fn(() => '{}'),
};

export default {
RNCNetInfo: RN,
addEventListener: jest.fn(),
fetch: jest.fn().mockImplementation(() =>
Promise.resolve({
isConnected: true,
isInternetReachable: true,
}),
),
};
16 changes: 16 additions & 0 deletions __mocks__/@react-navigation/drawer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

const MockNavigator = ({ children }) => children;
const MockScreen = ({ _name, children, component }) => {
if (typeof children === 'function') {
return children({ navigation: {} });
}

const Component = component;
return Component ? <Component /> : <>{children}</>;
};

export const createDrawerNavigator = jest.fn(() => ({
Navigator: MockNavigator,
Screen: MockScreen,
}));
1 change: 1 addition & 0 deletions __mocks__/@react-navigation/elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PlatformPressable = jest.fn().mockImplementation(({ children }) => children);
7 changes: 7 additions & 0 deletions __mocks__/@react-navigation/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { mockTheme } from '../dataMocks/mockTheme';

export const useTheme = () => (mockTheme);
export const useScrollToTop = jest.fn();
export const useIsFocused = jest.fn();

export const NavigationContainer = ({ children }) => children;
8 changes: 2 additions & 6 deletions __mocks__/@sayem314/react-native-keep-awake.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// @sayem314/react-native-keep-awake.js

export const activateKeepAwake = jest.fn().mockImplementation(() => {
console.log('Mocked activateKeepAwake');
});
export const activateKeepAwake = jest.fn().mockImplementation(() => {});

export const deactivateKeepAwake = jest.fn().mockImplementation(() => {
console.log('Mocked deactivateKeepAwake');
});
export const deactivateKeepAwake = jest.fn().mockImplementation(() => {});
15 changes: 0 additions & 15 deletions __mocks__/createNativeStackNavigator.tsx

This file was deleted.

11 changes: 7 additions & 4 deletions __mocks__/i18n-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { LanguageEnum } from '../app/AppState';

export const I18n = {
t: jest.fn().mockImplementation(key => key),
locale: LanguageEnum.en,
};
export default () => ({
__esModule: true,
I18n: jest.fn().mockImplementation(() => ({
t: jest.fn(),
locale: LanguageEnum.en,
})),
});
17 changes: 17 additions & 0 deletions __mocks__/moment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mMoment = {
format: (p) => {
if (p === 'MMM YYYY') {
return 'Dec 2022';
} else if (p === 'YYYY MMM D h:mm a') {
return '2022 Dec 13 8:00 am';
} else if (p === 'MMM D, h:mm a') {
return 'Dec 13, 8:00 am';
}
},
};
const fn = () => {
return mMoment;
};
fn.default = fn;
fn.locale = jest.fn();
export default fn;
3 changes: 3 additions & 0 deletions __mocks__/moment/locale/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => () => ({
defineLocale: jest.fn(),
});
3 changes: 3 additions & 0 deletions __mocks__/moment/locale/pt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => () => ({
defineLocale: jest.fn(),
});
3 changes: 3 additions & 0 deletions __mocks__/moment/locale/ru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => () => ({
defineLocale: jest.fn(),
});
1 change: 1 addition & 0 deletions __mocks__/react-native-bouncy-checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'BouncyCheckbox';
Empty file.
4 changes: 4 additions & 0 deletions __mocks__/react-native-device-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const getSystemName = jest.fn(() => 'Mocked System Name');
export const getSystemVersion = jest.fn(() => 'Mocked System Version');
export const getManufacturer = jest.fn(() => 'Mocked Manufacturer');
export const getModel = jest.fn(() => 'Mocked Model');
1 change: 1 addition & 0 deletions __mocks__/react-native-easy-biometrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const requestBioAuth = jest.fn(() => Promise.resolve(true));
2 changes: 2 additions & 0 deletions __mocks__/react-native-fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const readFile = jest.fn(() => Promise.resolve('{}'));
export const writeFile = jest.fn(() => Promise.resolve());
16 changes: 16 additions & 0 deletions __mocks__/react-native-gesture-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const GestureHandlerRootView = ({ children }) => children;

export default {
Swipeable: jest.fn().mockImplementation(({ children }) => children),
RNGestureHandlerModule: {
attachGestureHandler: jest.fn(),
createGestureHandler: jest.fn(),
dropGestureHandler: jest.fn(),
updateGestureHandler: jest.fn(),
forceTouchAvailable: jest.fn(),
hasGenericPassword: jest.fn(),
getSupportedBiometryType: jest.fn(),
State: {},
Directions: {},
},
};
1 change: 1 addition & 0 deletions __mocks__/react-native-gifted-charts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PieChart = jest.fn().mockReturnValue(null);
24 changes: 24 additions & 0 deletions __mocks__/react-native-keychain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const ACCESS_CONTROL = {
BIOMETRY_CURRENT_SET: 'biometryCurrentSet',
};
export const ACCESSIBLE = {
WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'whenUnlockedThisDeviceOnly',
};
export const AUTHENTICATION_TYPE = {
BIOMETRICS: 'biometrics',
};
export const SECURITY_LEVEL = {
SECURE_SOFTWARE: 'secureSoftware',
};
export const SECURITY_RULES = {
NONE: 'none',
};
export const STORAGE_TYPE = {
RSA : 'RSA',
AES_GCM_NO_AUTH: 'AES_GCM_NO_AUTH',
};
export const setGenericPassword = jest.fn();
export const getGenericPassword = jest.fn();
export const resetGenericPassword = jest.fn();
export const getSupportedBiometryType = jest.fn();
export const hasGenericPassword = jest.fn();
6 changes: 6 additions & 0 deletions __mocks__/react-native-localize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const getNumberFormatSettings = () => {
return {
decimalSeparator: '.', // us
groupingSeparator: ',', // us
};
};
1 change: 1 addition & 0 deletions __mocks__/react-native-picker-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'RNPickerSelect';
3 changes: 3 additions & 0 deletions __mocks__/react-native-safe-area-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SafeAreaProvider = ({ children }) => children;
export const SafeAreaView = ({ children }) => children;
export const useSafeAreaInsets = () => ({ top: 0, left: 0, right: 0, bottom: 0 });
10 changes: 2 additions & 8 deletions __mocks__/react-native-snackbar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// react-native-snackbar.js

export default {
show: jest.fn().mockImplementation(message => {
console.log(`Mocked Snackbar show: ${message}`);
}),
dismiss: jest.fn().mockImplementation(() => {
console.log('Mocked Snackbar dismiss');
}),
show: jest.fn().mockImplementation(() => {}),
dismiss: jest.fn().mockImplementation(() => {}),
};
1 change: 0 additions & 1 deletion __mocks__/react-native-svg-charts.js

This file was deleted.

2 changes: 2 additions & 0 deletions __mocks__/react-native-tab-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TabView = '';
export const TabBar = '';
16 changes: 16 additions & 0 deletions __mocks__/react-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
getLatestBlock: jest.fn(() => '{}'),
walletExists: jest.fn(() => 'false'),
getValueTransfersList: jest.fn(() => '{ "value_transfers": [], "total": 0 }'),
setCryptoDefaultProvider: jest.fn(() => 'true'),
createNewWallet: jest.fn(() => '{ "seed": "seed phrase test", "birthday": 0 }'),
doSave: jest.fn(),
};
RN.View = jest.fn();

return RN;
});
46 changes: 0 additions & 46 deletions __tests__/About.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,6 @@ import { ContextAppLoadedProvider, defaultAppContextLoaded } from '../app/contex
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { mockTotalBalance } from '../__mocks__/dataMocks/mockTotalBalance';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockTheme } from '../__mocks__/dataMocks/mockTheme';

jest.mock('react-native-safe-area-context', () => ({
SafeAreaProvider: ({ children }: any) => children,
SafeAreaView: ({ children }: any) => children,
useSafeAreaInsets: () => ({ top: 0, left: 0, right: 0, bottom: 0 }),
}));
jest.useFakeTimers();
jest.mock('@fortawesome/react-native-fontawesome', () => ({
FontAwesomeIcon: '',
}));
jest.mock('react-native-localize', () => ({
getNumberFormatSettings: () => {
return {
decimalSeparator: '.',
groupingSeparator: ',',
};
},
}));
jest.mock('react-native/src/private/animated/NativeAnimatedHelper');
jest.mock('@react-native-community/netinfo/src/index', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RNCNetInfo = {
execute: jest.fn(() => '{}'),
};

return RN;
});
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
};

return RN;
});
jest.mock('@react-native-clipboard/clipboard', () => ({
getString: jest.fn(() => Promise.resolve('mocked clipboard content')),
setString: jest.fn(),
}));
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
useTheme: () => (mockTheme),
}));

// test suite
describe('Component About - test', () => {
Expand Down
43 changes: 0 additions & 43 deletions __tests__/AddressBook.AbDetail.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,6 @@ import AbDetail from '../components/AddressBook/components/AbDetail';
import { AddressBookActionEnum, AddressBookFileClass } from '../app/AppState';
import { mockTranslate } from '../__mocks__/dataMocks/mockTranslate';
import { mockAddressBook } from '../__mocks__/dataMocks/mockAddressBook';
import { mockTheme } from '../__mocks__/dataMocks/mockTheme';

jest.mock('react-native-safe-area-context', () => ({
SafeAreaProvider: ({ children }: any) => children,
SafeAreaView: ({ children }: any) => children,
useSafeAreaInsets: () => ({ top: 0, left: 0, right: 0, bottom: 0 }),
}));
jest.useFakeTimers();
jest.mock('@fortawesome/react-native-fontawesome', () => ({
FontAwesomeIcon: '',
}));
jest.mock('react-native-localize', () => ({
getNumberFormatSettings: () => {
return {
decimalSeparator: '.', // us
groupingSeparator: ',', // us
};
},
}));
jest.mock('react-native/src/private/animated/NativeAnimatedHelper');
jest.mock('@react-native-community/netinfo/src/index', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RNCNetInfo = {
execute: jest.fn(() => '{}'),
};

return RN;
});
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');

RN.NativeModules.RPCModule = {
execute: jest.fn(() => '{}'),
};

return RN;
});
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
useScrollToTop: jest.fn(),
useTheme: () => mockTheme,
}));

// test suite
describe('Component Address Book Details - test', () => {
Expand Down
Loading

0 comments on commit d36c162

Please sign in to comment.