2021-02-04 19:15:23 +01:00
|
|
|
let mapStateToProps;
|
|
|
|
let mapDispatchToProps;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
jest.mock('react-redux', () => ({
|
|
|
|
connect: (ms, md) => {
|
|
|
|
mapStateToProps = ms;
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2019-07-31 21:56:44 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../selectors', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
getAddressBook: (s) => [{ name: `mockAddressBook:${s}` }],
|
|
|
|
getAddressBookEntry: (s) => `mockAddressBookEntry:${s}`,
|
|
|
|
accountsWithSendEtherInfoSelector: () => [
|
|
|
|
{ name: `account1:mockState` },
|
|
|
|
{ name: `account2:mockState` },
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
jest.mock('../../../../ducks/ens', () => ({
|
|
|
|
getEnsResolution: (s) => `mockSendEnsResolution:${s}`,
|
|
|
|
getEnsError: (s) => `mockSendEnsResolutionError:${s}`,
|
|
|
|
getEnsWarning: (s) => `mockSendEnsResolutionWarning:${s}`,
|
|
|
|
useMyAccountsForRecipientSearch: (s) =>
|
|
|
|
`useMyAccountsForRecipientSearch:${s}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../../ducks/send', () => ({
|
|
|
|
updateRecipient: ({ address, nickname }) =>
|
|
|
|
`{mockUpdateRecipient: {address: ${address}, nickname: ${nickname}}}`,
|
|
|
|
updateRecipientUserInput: (s) => `mockUpdateRecipientUserInput:${s}`,
|
|
|
|
useMyAccountsForRecipientSearch: (s) =>
|
|
|
|
`mockUseMyAccountsForRecipientSearch:${s}`,
|
|
|
|
useContactListForRecipientSearch: (s) =>
|
|
|
|
`mockUseContactListForRecipientSearch:${s}`,
|
|
|
|
getIsUsingMyAccountForRecipientSearch: (s) =>
|
|
|
|
`mockGetIsUsingMyAccountForRecipientSearch:${s}`,
|
|
|
|
getRecipientUserInput: (s) => `mockRecipientUserInput:${s}`,
|
|
|
|
getRecipient: (s) => `mockRecipient:${s}`,
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
require('./add-recipient.container.js');
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('add-recipient container', () => {
|
|
|
|
describe('mapStateToProps()', () => {
|
|
|
|
it('should map the correct properties to props', () => {
|
|
|
|
expect(mapStateToProps('mockState')).toStrictEqual({
|
2019-07-31 21:56:44 +02:00
|
|
|
addressBook: [{ name: 'mockAddressBook:mockState' }],
|
2021-06-23 23:35:25 +02:00
|
|
|
addressBookEntryName: undefined,
|
2019-07-31 21:56:44 +02:00
|
|
|
contacts: [{ name: 'mockAddressBook:mockState' }],
|
|
|
|
ensResolution: 'mockSendEnsResolution:mockState',
|
2021-06-23 23:35:25 +02:00
|
|
|
ensError: 'mockSendEnsResolutionError:mockState',
|
|
|
|
ensWarning: 'mockSendEnsResolutionWarning:mockState',
|
|
|
|
nonContacts: [],
|
2020-11-07 00:16:51 +01:00
|
|
|
ownedAccounts: [
|
2021-06-23 23:35:25 +02:00
|
|
|
{ name: 'account1:mockState' },
|
|
|
|
{ name: 'account2:mockState' },
|
2020-11-07 00:16:51 +01:00
|
|
|
],
|
2021-06-23 23:35:25 +02:00
|
|
|
isUsingMyAccountsForRecipientSearch:
|
|
|
|
'mockGetIsUsingMyAccountForRecipientSearch:mockState',
|
|
|
|
userInput: 'mockRecipientUserInput:mockState',
|
|
|
|
recipient: 'mockRecipient:mockState',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('mapDispatchToProps()', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
describe('updateRecipient()', () => {
|
|
|
|
const dispatchSpy = jest.fn();
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
mapDispatchToPropsObject.updateRecipient({
|
|
|
|
address: 'mockAddress',
|
|
|
|
nickname: 'mockNickname',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(dispatchSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(dispatchSpy.mock.calls[0][0]).toStrictEqual(
|
|
|
|
'{mockUpdateRecipient: {address: mockAddress, nickname: mockNickname}}',
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|