2019-07-31 21:56:44 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
|
|
|
|
let mapStateToProps
|
|
|
|
let mapDispatchToProps
|
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
updateSendTo: sinon.spy(),
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyquire('../add-recipient.container.js', {
|
|
|
|
'react-redux': {
|
|
|
|
connect: (ms, md) => {
|
|
|
|
mapStateToProps = ms
|
|
|
|
mapDispatchToProps = md
|
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
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-03-06 22:34:56 +01:00
|
|
|
accountsWithSendEtherInfoSelector: (s) => `mockAccountsWithSendEtherInfoSelector:${s}`,
|
2019-07-31 21:56:44 +02:00
|
|
|
},
|
|
|
|
'../../../../store/actions': actionSpies,
|
|
|
|
})
|
|
|
|
|
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 () {
|
2019-07-31 21:56:44 +02:00
|
|
|
assert.deepEqual(mapStateToProps('mockState'), {
|
|
|
|
addressBook: [{ name: 'mockAddressBook:mockState' }],
|
|
|
|
contacts: [{ name: 'mockAddressBook:mockState' }],
|
|
|
|
ensResolution: 'mockSendEnsResolution:mockState',
|
|
|
|
ensResolutionError: 'mockSendEnsResolutionError:mockState',
|
|
|
|
ownedAccounts: 'mockAccountsWithSendEtherInfoSelector:mockState',
|
|
|
|
addressBookEntryName: undefined,
|
|
|
|
nonContacts: [],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('mapDispatchToProps()', function () {
|
|
|
|
describe('updateSendTo()', function () {
|
|
|
|
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 () {
|
2019-07-31 21:56:44 +02:00
|
|
|
mapDispatchToPropsObject.updateSendTo('mockTo', 'mockNickname')
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert(actionSpies.updateSendTo.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.updateSendTo.getCall(0).args,
|
2020-07-14 17:20:41 +02:00
|
|
|
['mockTo', 'mockNickname'],
|
2019-07-31 21:56:44 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|