2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import sinon from 'sinon';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapStateToProps;
|
|
|
|
let mapDispatchToProps;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
updateSendTo: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-03-16 22:00:08 +01:00
|
|
|
proxyquire('./add-recipient.container.js', {
|
2019-07-31 21:56:44 +02:00
|
|
|
'react-redux': {
|
|
|
|
connect: (ms, md) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapStateToProps = ms;
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2019-07-31 21:56:44 +02:00
|
|
|
},
|
|
|
|
},
|
2020-05-04 21:06:28 +02:00
|
|
|
'../../../../selectors': {
|
2019-07-31 21:56:44 +02:00
|
|
|
getSendEnsResolution: (s) => `mockSendEnsResolution:${s}`,
|
|
|
|
getSendEnsResolutionError: (s) => `mockSendEnsResolutionError:${s}`,
|
|
|
|
getAddressBook: (s) => [{ name: `mockAddressBook:${s}` }],
|
|
|
|
getAddressBookEntry: (s) => `mockAddressBookEntry:${s}`,
|
2020-11-07 00:16:51 +01:00
|
|
|
accountsWithSendEtherInfoSelector: (s) => [
|
|
|
|
{ name: `account2:${s}` },
|
|
|
|
{ name: `account1:${s}` },
|
|
|
|
],
|
2019-07-31 21:56:44 +02:00
|
|
|
},
|
|
|
|
'../../../../store/actions': actionSpies,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('add-recipient container', function () {
|
|
|
|
describe('mapStateToProps()', function () {
|
|
|
|
it('should map the correct properties to props', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(mapStateToProps('mockState'), {
|
2019-07-31 21:56:44 +02:00
|
|
|
addressBook: [{ name: 'mockAddressBook:mockState' }],
|
|
|
|
contacts: [{ name: 'mockAddressBook:mockState' }],
|
|
|
|
ensResolution: 'mockSendEnsResolution:mockState',
|
|
|
|
ensResolutionError: 'mockSendEnsResolutionError:mockState',
|
2020-11-07 00:16:51 +01:00
|
|
|
ownedAccounts: [
|
|
|
|
{ name: `account1:mockState` },
|
|
|
|
{ name: `account2:mockState` },
|
|
|
|
],
|
2019-07-31 21:56:44 +02:00
|
|
|
addressBookEntryName: undefined,
|
|
|
|
nonContacts: [],
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('mapDispatchToProps()', function () {
|
|
|
|
describe('updateSendTo()', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const dispatchSpy = sinon.spy();
|
|
|
|
const mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateSendTo('mockTo', 'mockNickname');
|
|
|
|
assert(dispatchSpy.calledOnce);
|
|
|
|
assert(actionSpies.updateSendTo.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(actionSpies.updateSendTo.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockTo',
|
|
|
|
'mockNickname',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|