mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
086003555c
Co-authored-by: Olaf Tomalka <olaf.tomalka@gmail.com> Co-authored-by: Vincent Shadbolt <vince.shadbolt@gmail.com> Co-authored-by: Brad Decker <bhdecker84@gmail.com> Co-authored-by: Brad Decker <git@braddecker.dev>
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
let mapStateToProps;
|
|
let mapDispatchToProps;
|
|
|
|
jest.mock('react-redux', () => ({
|
|
connect: (ms, md) => {
|
|
mapStateToProps = ms;
|
|
mapDispatchToProps = md;
|
|
return () => ({});
|
|
},
|
|
}));
|
|
|
|
jest.mock('../../../../selectors', () => ({
|
|
getAddressBook: (s) => [{ name: `mockAddressBook:${s}` }],
|
|
getAddressBookEntry: (s) => `mockAddressBookEntry:${s}`,
|
|
getMetaMaskAccountsOrdered: () => [
|
|
{ name: `account1:mockState` },
|
|
{ name: `account2:mockState` },
|
|
],
|
|
}));
|
|
|
|
jest.mock('../../../../ducks/domains', () => ({
|
|
getDomainResolution: (s) => `mockSendDomainResolution:${s}`,
|
|
getDomainError: (s) => `mockSendDomainResolutionError:${s}`,
|
|
getDomainWarning: (s) => `mockSendDomainResolutionWarning:${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}`,
|
|
}));
|
|
|
|
require('./add-recipient.container');
|
|
|
|
describe('add-recipient container', () => {
|
|
describe('mapStateToProps()', () => {
|
|
it('should map the correct properties to props', () => {
|
|
expect(mapStateToProps('mockState')).toStrictEqual({
|
|
addressBook: [{ name: 'mockAddressBook:mockState' }],
|
|
addressBookEntryName: undefined,
|
|
contacts: [{ name: 'mockAddressBook:mockState' }],
|
|
domainResolution: 'mockSendDomainResolution:mockState',
|
|
domainError: 'mockSendDomainResolutionError:mockState',
|
|
domainWarning: 'mockSendDomainResolutionWarning:mockState',
|
|
nonContacts: [],
|
|
ownedAccounts: [
|
|
{ name: 'account1:mockState' },
|
|
{ name: 'account2:mockState' },
|
|
],
|
|
isUsingMyAccountsForRecipientSearch:
|
|
'mockGetIsUsingMyAccountForRecipientSearch:mockState',
|
|
userInput: 'mockRecipientUserInput:mockState',
|
|
recipient: 'mockRecipient:mockState',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('mapDispatchToProps()', () => {
|
|
describe('updateRecipient()', () => {
|
|
const dispatchSpy = jest.fn();
|
|
|
|
const mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
|
|
|
it('should dispatch an action', () => {
|
|
mapDispatchToPropsObject.updateRecipient({
|
|
address: 'mockAddress',
|
|
nickname: 'mockNickname',
|
|
});
|
|
|
|
expect(dispatchSpy).toHaveBeenCalledTimes(1);
|
|
expect(dispatchSpy.mock.calls[0][0]).toStrictEqual(
|
|
'{mockUpdateRecipient: {address: mockAddress, nickname: mockNickname}}',
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|