1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 19:10:22 +01:00
metamask-extension/ui/app/pages/send/send-content/send-to-row/tests/send-to-row-container.test.js
Chi Kei Chan 931aaeb700 Add token selection to the send screen (#6445)
* Move send to pages/

* Fix unit tests

* Finish UI

* Integrate asset dropdown to send actions

* Remove console.log

* Hide asset change during edit

* Enable switch from send token to seand eth

* Enable switching from token to eth when editing

* Fix linter

* Fixing test

* Fix unit tests

* Fix linter

* Fix react warning; remove console.log

* fix flat test

* Add metrics

* Address code review comments

* Consistent spacing between send screen form rows.

* Reduce height of gas buttons on send screen.

* Make send screen gas button height dependent on size of contents.
2019-04-17 16:45:13 -02:30

135 lines
3.8 KiB
JavaScript

import assert from 'assert'
import proxyquire from 'proxyquire'
import sinon from 'sinon'
let mapStateToProps
let mapDispatchToProps
const actionSpies = {
updateSendTo: sinon.spy(),
}
const duckActionSpies = {
closeToDropdown: sinon.spy(),
openToDropdown: sinon.spy(),
updateSendErrors: sinon.spy(),
updateSendWarnings: sinon.spy(),
}
proxyquire('../send-to-row.container.js', {
'react-redux': {
connect: (ms, md) => {
mapStateToProps = ms
mapDispatchToProps = md
return () => ({})
},
},
'../../send.selectors.js': {
getCurrentNetwork: (s) => `mockNetwork:${s}`,
getSelectedToken: (s) => `mockSelectedToken:${s}`,
getSendHexData: (s) => s,
getSendTo: (s) => `mockTo:${s}`,
getSendToAccounts: (s) => `mockToAccounts:${s}`,
},
'./send-to-row.selectors.js': {
getToDropdownOpen: (s) => `mockToDropdownOpen:${s}`,
sendToIsInError: (s) => `mockInError:${s}`,
sendToIsInWarning: (s) => `mockInWarning:${s}`,
getTokens: (s) => `mockTokens:${s}`,
},
'../../../../store/actions': actionSpies,
'../../../../ducks/send/send.duck': duckActionSpies,
})
describe('send-to-row container', () => {
describe('mapStateToProps()', () => {
it('should map the correct properties to props', () => {
assert.deepEqual(mapStateToProps('mockState'), {
hasHexData: true,
inError: 'mockInError:mockState',
inWarning: 'mockInWarning:mockState',
network: 'mockNetwork:mockState',
selectedToken: 'mockSelectedToken:mockState',
to: 'mockTo:mockState',
toAccounts: 'mockToAccounts:mockState',
toDropdownOpen: 'mockToDropdownOpen:mockState',
tokens: 'mockTokens:mockState',
})
})
})
describe('mapDispatchToProps()', () => {
let dispatchSpy
let mapDispatchToPropsObject
beforeEach(() => {
dispatchSpy = sinon.spy()
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
})
describe('closeToDropdown()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.closeToDropdown()
assert(dispatchSpy.calledOnce)
assert(duckActionSpies.closeToDropdown.calledOnce)
assert.equal(
duckActionSpies.closeToDropdown.getCall(0).args[0],
undefined
)
})
})
describe('openToDropdown()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.openToDropdown()
assert(dispatchSpy.calledOnce)
assert(duckActionSpies.openToDropdown.calledOnce)
assert.equal(
duckActionSpies.openToDropdown.getCall(0).args[0],
undefined
)
})
})
describe('updateSendTo()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.updateSendTo('mockTo', 'mockNickname')
assert(dispatchSpy.calledOnce)
assert(actionSpies.updateSendTo.calledOnce)
assert.deepEqual(
actionSpies.updateSendTo.getCall(0).args,
['mockTo', 'mockNickname']
)
})
})
describe('updateSendToError()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.updateSendToError('mockToErrorObject')
assert(dispatchSpy.calledOnce)
assert(duckActionSpies.updateSendErrors.calledOnce)
assert.equal(
duckActionSpies.updateSendErrors.getCall(0).args[0],
'mockToErrorObject'
)
})
})
describe('updateSendToWarning()', () => {
it('should dispatch an action', () => {
mapDispatchToPropsObject.updateSendToWarning('mockToWarningObject')
assert(dispatchSpy.calledOnce)
assert(duckActionSpies.updateSendWarnings.calledOnce)
assert.equal(
duckActionSpies.updateSendWarnings.getCall(0).args[0],
'mockToWarningObject'
)
})
})
})
})