Skip to content

Commit

Permalink
Merge pull request #611 from juanky201271/dev_pin_based_and_address_book
Browse files Browse the repository at this point in the history
PIN based and address book for testing
  • Loading branch information
juanky201271 authored Mar 12, 2024
2 parents a3f5abb + 8f55dde commit 7c321a3
Show file tree
Hide file tree
Showing 65 changed files with 4,756 additions and 628 deletions.
118 changes: 118 additions & 0 deletions __tests__/AddressBook.AbDetail.snapshot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @format
*/

import 'react-native';
import React from 'react';

import { render } from '@testing-library/react-native';
import { defaultAppStateLoaded, ContextAppLoadedProvider } from '../app/context';
import { ThemeType } from '../app/types';
import AbDetail from '../components/AddressBook/components/AbDetail';
import { AddressBookFileClass } from '../app/AppState';

jest.useFakeTimers();
jest.mock('@fortawesome/react-native-fontawesome', () => ({
FontAwesomeIcon: '',
}));
jest.mock('react-native-localize', () => ({
getNumberFormatSettings: () => {
return {
decimalSeparator: '.', // us
groupingSeparator: ',', // us
};
},
}));
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('react-native-reanimated', () => {
return class Reanimated {
public static Value() {
return jest.fn(() => {});
}
public static View() {
return '';
}
};
});
jest.mock('@react-native-community/netinfo', () => {
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;
});
const Theme: ThemeType = {
dark: true,
colors: {
background: '#011401', //'#010101',
card: '#011401', //'#401717',
border: '#ffffff',
primary: '#18bd18', //'#df4100',
primaryDisabled: '#5a8c5a', //'rgba(90, 140, 90, 1)',
secondaryDisabled: '#233623',
text: '#c3c3c3',
zingo: '#888888',
placeholder: '#888888',
money: '#ffffff',
syncing: '#ebff5a',
notification: '',
},
};
jest.mock('@react-navigation/native', () => ({
useScrollToTop: jest.fn(),
useTheme: () => Theme,
}));

// test suite
describe('Component Address Book Details - test', () => {
//snapshot test
const state = defaultAppStateLoaded;
state.addressBook = [
{
label: 'pepe',
address: 'u1234567890_____________',
},
{
label: 'lolo',
address: 'u0987654321_____________',
},
];
state.translate = () => 'translated text';
const onCancel = jest.fn();
const onAction = jest.fn();
test('Address Book Datails - Add - snapshot', () => {
const ab: any = render(
<ContextAppLoadedProvider value={state}>
<AbDetail index={-1} item={{} as AddressBookFileClass} cancel={onCancel} action={'Add'} doAction={onAction} />
</ContextAppLoadedProvider>,
);
expect(ab.toJSON()).toMatchSnapshot();
});
test('Address Book Datails - Modify - snapshot', () => {
const ab: any = render(
<ContextAppLoadedProvider value={state}>
<AbDetail index={0} item={state.addressBook[0]} cancel={onCancel} action={'Modify'} doAction={onAction} />
</ContextAppLoadedProvider>,
);
expect(ab.toJSON()).toMatchSnapshot();
});
test('Address Book Datails - Delete - snapshot', () => {
const ab: any = render(
<ContextAppLoadedProvider value={state}>
<AbDetail index={1} item={state.addressBook[1]} cancel={onCancel} action={'Delete'} doAction={onAction} />
</ContextAppLoadedProvider>,
);
expect(ab.toJSON()).toMatchSnapshot();
});
});
101 changes: 101 additions & 0 deletions __tests__/AddressBook.snapshot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @format
*/

import 'react-native';
import React from 'react';

import { render } from '@testing-library/react-native';
import { defaultAppStateLoaded, ContextAppLoadedProvider } from '../app/context';
import AddressBook from '../components/AddressBook/AddressBook';
import { ThemeType } from '../app/types';

jest.useFakeTimers();
jest.mock('@fortawesome/react-native-fontawesome', () => ({
FontAwesomeIcon: '',
}));
jest.mock('react-native-localize', () => ({
getNumberFormatSettings: () => {
return {
decimalSeparator: '.', // us
groupingSeparator: ',', // us
};
},
}));
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('react-native-reanimated', () => {
return class Reanimated {
public static Value() {
return jest.fn(() => {});
}
public static View() {
return '';
}
};
});
jest.mock('@react-native-community/netinfo', () => {
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;
});
const Theme: ThemeType = {
dark: true,
colors: {
background: '#011401', //'#010101',
card: '#011401', //'#401717',
border: '#ffffff',
primary: '#18bd18', //'#df4100',
primaryDisabled: '#5a8c5a', //'rgba(90, 140, 90, 1)',
secondaryDisabled: '#233623',
text: '#c3c3c3',
zingo: '#888888',
placeholder: '#888888',
money: '#ffffff',
syncing: '#ebff5a',
notification: '',
},
};
jest.mock('@react-navigation/native', () => ({
useScrollToTop: jest.fn(),
useTheme: () => Theme,
}));

// test suite
describe('Component Address Book - test', () => {
//snapshot test
test('Address Book - snapshot', () => {
const state = defaultAppStateLoaded;
state.addressBook = [
{
label: 'pepe',
address: 'u1234567890_____________',
},
{
label: 'lolo',
address: 'u0987654321_____________',
},
];
state.translate = () => 'translated text';
const onClose = jest.fn();
const onSet = jest.fn();
const ab: any = render(
<ContextAppLoadedProvider value={state}>
<AddressBook closeModal={onClose} setAddressBook={onSet} setSendPageState={onSet} />
</ContextAppLoadedProvider>,
);
expect(ab.toJSON()).toMatchSnapshot();
});
});
24 changes: 21 additions & 3 deletions __tests__/History.TxDetail.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ describe('Component History TxDetail - test', () => {
} as TransactionType;
render(
<ContextAppLoadedProvider value={state}>
<TxDetail tx={tx} closeModal={onClose} set_privacy_option={onSetOption} />
<TxDetail
tx={tx}
closeModal={onClose}
openModal={onClose}
set_privacy_option={onSetOption}
setSendPageState={onClose}
/>
</ContextAppLoadedProvider>,
).toJSON();
screen.getByText('0.2234');
Expand Down Expand Up @@ -138,7 +144,13 @@ describe('Component History TxDetail - test', () => {
} as TransactionType;
render(
<ContextAppLoadedProvider value={state}>
<TxDetail tx={txSelfSend} closeModal={onClose} set_privacy_option={onSetOption} />
<TxDetail
tx={txSelfSend}
closeModal={onClose}
openModal={onClose}
set_privacy_option={onSetOption}
setSendPageState={onClose}
/>
</ContextAppLoadedProvider>,
);
const num = screen.getAllByText('0.0000');
Expand Down Expand Up @@ -173,7 +185,13 @@ describe('Component History TxDetail - test', () => {
} as TransactionType;
render(
<ContextAppLoadedProvider value={state}>
<TxDetail tx={txSelfSend} closeModal={onClose} set_privacy_option={onSetOption} />
<TxDetail
tx={txSelfSend}
closeModal={onClose}
openModal={onClose}
set_privacy_option={onSetOption}
setSendPageState={onClose}
/>
</ContextAppLoadedProvider>,
);
screen.getByText('0.8765');
Expand Down
2 changes: 2 additions & 0 deletions __tests__/History.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ describe('Component History - test', () => {
set_privacy_option={onFunction}
setPoolsToShieldSelectSapling={onFunction}
setPoolsToShieldSelectTransparent={onFunction}
setSendPageState={onFunction}
/>
</ContextAppLoadedProvider>,
);
Expand All @@ -206,6 +207,7 @@ describe('Component History - test', () => {
set_privacy_option={onFunction}
setPoolsToShieldSelectSapling={onFunction}
setPoolsToShieldSelectTransparent={onFunction}
setSendPageState={onFunction}
/>
</ContextAppLoadedProvider>,
);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/Insight.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Component Insight - test', () => {
const onClose = jest.fn();
const insight = render(
<ContextAppLoadedProvider value={state}>
<Insight closeModal={onClose} set_privacy_option={onClose} />
<Insight closeModal={onClose} openModal={onClose} set_privacy_option={onClose} setSendPageState={onClose} />
</ContextAppLoadedProvider>,
);
expect(insight.toJSON()).toMatchSnapshot();
Expand Down
16 changes: 15 additions & 1 deletion __tests__/LoadedApp.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ThemeType } from '../app/types';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { I18n } from 'i18n-js';
import { StackScreenProps } from '@react-navigation/stack';
import { BackgroundType, ServerType } from '../app/AppState';
import { BackgroundType, AddressBookFileClass, ServerType } from '../app/AppState';

// Crea un mock para el constructor de I18n
jest.mock('i18n-js', () => ({
Expand Down Expand Up @@ -129,6 +129,18 @@ describe('Component LoadedApp - test', () => {
};
const readOnly = false;
const toggleTheme = jest.fn();
const addressBook = [] as AddressBookFileClass[];
const security = {
startApp: true,
foregroundApp: true,
sendConfirm: true,
seedScreen: true,
ufvkScreen: true,
rescanScreen: true,
settingsScreen: true,
changeWalletScreen: true,
restoreWalletBackupScreen: true,
};
const receive = render(
<LoadedAppClass
navigation={navigationMock}
Expand All @@ -144,6 +156,8 @@ describe('Component LoadedApp - test', () => {
background={background}
readOnly={readOnly}
toggleTheme={toggleTheme}
addressBook={addressBook}
security={security}
/>,
);
expect(receive.toJSON()).toMatchSnapshot();
Expand Down
12 changes: 12 additions & 0 deletions __tests__/LoadingApp.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ describe('Component LoadingApp - test', () => {
};
const firstLaunchingMessage = false;
const toggleTheme = jest.fn();
const security = {
startApp: true,
foregroundApp: true,
sendConfirm: true,
seedScreen: true,
ufvkScreen: true,
rescanScreen: true,
settingsScreen: true,
changeWalletScreen: true,
restoreWalletBackupScreen: true,
};
const receive = render(
<LoadingAppClass
navigation={navigationMock}
Expand All @@ -144,6 +155,7 @@ describe('Component LoadingApp - test', () => {
background={background}
firstLaunchingMessage={firstLaunchingMessage}
toggleTheme={toggleTheme}
security={security}
/>,
);
expect(receive.toJSON()).toMatchSnapshot();
Expand Down
1 change: 1 addition & 0 deletions __tests__/Send.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jest.mock('@react-navigation/native', () => ({
useIsFocused: jest.fn(),
useTheme: () => Theme,
}));
jest.mock('react-native-picker-select', () => 'RNPickerSelect');

// test suite
describe('Component Send - test', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/Settings.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('Component Settings - test', () => {
set_sendAll_option={onSetOption}
set_privacy_option={onSetOption}
set_mode_option={onSetOption}
set_security_option={onSetOption}
/>
</ContextAppLoadedProvider>,
);
Expand Down
4 changes: 1 addition & 3 deletions __tests__/SingleAddress.snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ describe('Component SingleAddress - test', () => {
test('SingleAddress - snapshot', () => {
const onPrev = jest.fn();
const onNext = jest.fn();
const single = render(
<SingleAddress address="hvkausdfskidjlfs" addressKind="u" index={0} total={1} prev={onPrev} next={onNext} />,
);
const single = render(<SingleAddress address="hvkausdfskidjlfs" index={0} total={1} prev={onPrev} next={onNext} />);
expect(single.toJSON()).toMatchSnapshot();
});
});
Loading

0 comments on commit 7c321a3

Please sign in to comment.