Add missing unit tests in send_/: now 100% function test coverage in send_/

feature/default_network_editable
Dan 7 years ago
parent c2ed2d4e50
commit b3f08681fd
  1. 11
      ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js
  2. 1
      ui/app/components/send_/send.selectors.js
  3. 45
      ui/app/components/send_/tests/send-selectors-test-data.js
  4. 353
      ui/app/components/send_/tests/send-selectors.test.js

@ -46,6 +46,17 @@ describe('AccountListItem Component', function () {
assert(wrapper.find('.mockClassName').hasClass('account-list-item')) assert(wrapper.find('.mockClassName').hasClass('account-list-item'))
}) })
it('should call handleClick with the expected props when the root div is clicked', () => {
const { onClick } = wrapper.find('.mockClassName').props()
assert.equal(propsMethodSpies.handleClick.callCount, 0)
onClick()
assert.equal(propsMethodSpies.handleClick.callCount, 1)
assert.deepEqual(
propsMethodSpies.handleClick.getCall(0).args,
[{ address: 'mockAddress', name: 'mockName', balance: 'mockBalance' }]
)
})
it('should have a top row div', () => { it('should have a top row div', () => {
assert.equal(wrapper.find('.mockClassName > .account-list-item__top-row').length, 1) assert.equal(wrapper.find('.mockClassName > .account-list-item__top-row').length, 1)
assert(wrapper.find('.mockClassName > .account-list-item__top-row').is('div')) assert(wrapper.find('.mockClassName > .account-list-item__top-row').is('div'))

@ -165,6 +165,7 @@ function getSelectedToken (state) {
function getSelectedTokenContract (state) { function getSelectedTokenContract (state) {
const selectedToken = getSelectedToken(state) const selectedToken = getSelectedToken(state)
return selectedToken return selectedToken
? global.eth.contract(abi).at(selectedToken.address) ? global.eth.contract(abi).at(selectedToken.address)
: null : null

@ -86,9 +86,42 @@ module.exports = {
}, },
}, },
'transactions': {}, 'transactions': {},
'selectedAddressTxList': [], 'selectedAddressTxList': [
{
'id': 'mockTokenTx1',
'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3'
},
'time': 1700000000000
},
{
'id': 'mockTokenTx2',
'txParams': {
'to': '0xafaketokenaddress'
},
'time': 1600000000000
},
{
'id': 'mockTokenTx3',
'txParams': {
'to': '0x8d6b81208414189a58339873ab429b6c47ab92d3'
},
'time': 1500000000000
},
{
'id': 'mockEthTx1',
'txParams': {
'to': '0xd85a4b6a394794842887b8284293d69163007bbb'
},
'time': 1400000000000
}
],
'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3', 'selectedTokenAddress': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'unapprovedMsgs': {}, 'unapprovedMsgs': {
'0xabc': { id: 'unapprovedMessage1', 'time': 1650000000000 },
'0xdef': { id: 'unapprovedMessage2', 'time': 1550000000000 },
'0xghi': { id: 'unapprovedMessage3', 'time': 1450000000000 },
},
'unapprovedMsgCount': 0, 'unapprovedMsgCount': 0,
'unapprovedPersonalMsgs': {}, 'unapprovedPersonalMsgs': {},
'unapprovedPersonalMsgCount': 0, 'unapprovedPersonalMsgCount': 0,
@ -116,7 +149,11 @@ module.exports = {
'provider': { 'provider': {
'type': 'testnet', 'type': 'testnet',
}, },
'shapeShiftTxList': [], 'shapeShiftTxList': [
{ id: 'shapeShiftTx1', 'time': 1675000000000 },
{ id: 'shapeShiftTx2', 'time': 1575000000000 },
{ id: 'shapeShiftTx3', 'time': 1475000000000 },
],
'lostAccounts': [], 'lostAccounts': [],
'send': { 'send': {
'gasLimit': '0xFFFF', 'gasLimit': '0xFFFF',
@ -158,7 +195,7 @@ module.exports = {
'txValue': 'de0b6b3a7640000', 'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800', 'maxCost': 'de234b52e4a0800',
'gasPrice': '4a817c800', 'gasPrice': '4a817c800',
}, }
}, },
'currentLocale': 'en', 'currentLocale': 'en',
}, },

@ -1,4 +1,5 @@
import assert from 'assert' import assert from 'assert'
import sinon from 'sinon'
import selectors from '../send.selectors.js' import selectors from '../send.selectors.js'
const { const {
accountsWithSendEtherInfoSelector, accountsWithSendEtherInfoSelector,
@ -20,7 +21,7 @@ const {
getSelectedAddress, getSelectedAddress,
getSelectedIdentity, getSelectedIdentity,
getSelectedToken, getSelectedToken,
// getSelectedTokenContract, getSelectedTokenContract,
getSelectedTokenExchangeRate, getSelectedTokenExchangeRate,
getSelectedTokenToFiatRate, getSelectedTokenToFiatRate,
getSendAmount, getSendAmount,
@ -36,11 +37,23 @@ const {
getTokenExchangeRate, getTokenExchangeRate,
getUnapprovedTxs, getUnapprovedTxs,
isSendFormInError, isSendFormInError,
// transactionsSelector, transactionsSelector,
} = selectors } = selectors
import mockState from './send-selectors-test-data' import mockState from './send-selectors-test-data'
describe('send selectors', () => { describe('send selectors', () => {
let tempGlobalEth = Object.assign({}, global.eth)
beforeEach(() => {
global.eth = {
contract: sinon.stub().returns({
at: address => 'mockAt:' + address
})
}
})
afterEach(() => {
global.eth = tempGlobalEth
})
describe('accountsWithSendEtherInfoSelector()', () => { describe('accountsWithSendEtherInfoSelector()', () => {
it('should return an array of account objects with name info from identities', () => { it('should return an array of account objects with name info from identities', () => {
@ -48,32 +61,32 @@ describe('send selectors', () => {
accountsWithSendEtherInfoSelector(mockState), accountsWithSendEtherInfoSelector(mockState),
[ [
{ {
'code': '0x', code: '0x',
'balance': '0x47c9d71831c76efe', balance: '0x47c9d71831c76efe',
'nonce': '0x1b', nonce: '0x1b',
'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825', address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
'name': 'Send Account 1', name: 'Send Account 1',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x37452b1315889f80', balance: '0x37452b1315889f80',
'nonce': '0xa', nonce: '0xa',
'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb', address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'name': 'Send Account 2', name: 'Send Account 2',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x30c9d71831c76efe', balance: '0x30c9d71831c76efe',
'nonce': '0x1c', nonce: '0x1c',
'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d', address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
'name': 'Send Account 3', name: 'Send Account 3',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x0', balance: '0x0',
'nonce': '0x0', nonce: '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4', name: 'Send Account 4',
}, },
] ]
) )
@ -95,8 +108,8 @@ describe('send selectors', () => {
getAddressBook(mockState), getAddressBook(mockState),
[ [
{ {
'address': '0x06195827297c7a80a443b6894d3bdb8824b43896', address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
'name': 'Address Book Account 1', name: 'Address Book Account 1',
}, },
], ],
) )
@ -145,11 +158,11 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getCurrentAccountWithSendEtherInfo(mockState), getCurrentAccountWithSendEtherInfo(mockState),
{ {
'code': '0x', code: '0x',
'balance': '0x0', balance: '0x0',
'nonce': '0x0', nonce: '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4', name: 'Send Account 4',
} }
) )
}) })
@ -232,10 +245,10 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSelectedAccount(mockState), getSelectedAccount(mockState),
{ {
'code': '0x', code: '0x',
'balance': '0x0', balance: '0x0',
'nonce': '0x0', nonce: '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
} }
) )
}) })
@ -255,8 +268,8 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSelectedIdentity(mockState), getSelectedIdentity(mockState),
{ {
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4', name: 'Send Account 4',
} }
) )
}) })
@ -267,18 +280,18 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSelectedToken(mockState), getSelectedToken(mockState),
{ {
'address': '0x8d6b81208414189a58339873ab429b6c47ab92d3', address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
'decimals': 4, decimals: 4,
'symbol': 'DEF', symbol: 'DEF',
} }
) )
}) })
it('should return the send token if none is currently selected, but a send token exists', () => { it('should return the send token if none is currently selected, but a send token exists', () => {
const mockSendToken = { const mockSendToken = {
'address': '0x123456708414189a58339873ab429b6c47ab92d3', address: '0x123456708414189a58339873ab429b6c47ab92d3',
'decimals': 4, decimals: 4,
'symbol': 'JKL', symbol: 'JKL',
} }
const editedMockState = { const editedMockState = {
metamask: Object.assign({}, mockState.metamask, { metamask: Object.assign({}, mockState.metamask, {
@ -295,15 +308,22 @@ describe('send selectors', () => {
}) })
}) })
// TODO describe('getSelectedTokenContract()', () => {
// describe('getSelectedTokenContract()', () => { it('should return the contract at the selected token address', () => {
// it('should', () => { assert.equal(
// assert.deepEqual( getSelectedTokenContract(mockState),
// getSelectedTokenContract(mockState), 'mockAt:0x8d6b81208414189a58339873ab429b6c47ab92d3'
)
})
// ) it('should return null if no token is selected', () => {
// }) const modifiedMetamaskState = Object.assign({}, mockState.metamask, { selectedTokenAddress: false })
// }) assert.equal(
getSelectedTokenContract(Object.assign({}, mockState, { metamask: modifiedMetamaskState })),
null
)
})
})
describe('getSelectedTokenExchangeRate()', () => { describe('getSelectedTokenExchangeRate()', () => {
it('should return the exchange rate for the selected token', () => { it('should return the exchange rate for the selected token', () => {
@ -345,7 +365,7 @@ describe('send selectors', () => {
it('should return the send.errors', () => { it('should return the send.errors', () => {
assert.deepEqual( assert.deepEqual(
getSendErrors(mockState), getSendErrors(mockState),
{ 'someError': null } { someError: null }
) )
}) })
}) })
@ -355,8 +375,8 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSendFrom(mockState), getSendFrom(mockState),
{ {
'address': '0xabcdefg', address: '0xabcdefg',
'balance': '0x5f4e3d2c1', balance: '0x5f4e3d2c1',
} }
) )
}) })
@ -390,8 +410,8 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSendFromObject(mockState), getSendFromObject(mockState),
{ {
'address': '0xabcdefg', address: '0xabcdefg',
'balance': '0x5f4e3d2c1', balance: '0x5f4e3d2c1',
} }
) )
}) })
@ -407,11 +427,11 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getSendFromObject(editedMockState), getSendFromObject(editedMockState),
{ {
'code': '0x', code: '0x',
'balance': '0x0', balance: '0x0',
'nonce': '0x0', nonce: '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4', name: 'Send Account 4',
} }
) )
}) })
@ -441,36 +461,36 @@ describe('send selectors', () => {
getSendToAccounts(mockState), getSendToAccounts(mockState),
[ [
{ {
'code': '0x', code: '0x',
'balance': '0x47c9d71831c76efe', balance: '0x47c9d71831c76efe',
'nonce': '0x1b', nonce: '0x1b',
'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825', address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
'name': 'Send Account 1', name: 'Send Account 1',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x37452b1315889f80', balance: '0x37452b1315889f80',
'nonce': '0xa', nonce: '0xa',
'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb', address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'name': 'Send Account 2', name: 'Send Account 2',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x30c9d71831c76efe', balance: '0x30c9d71831c76efe',
'nonce': '0x1c', nonce: '0x1c',
'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d', address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
'name': 'Send Account 3', name: 'Send Account 3',
}, },
{ {
'code': '0x', code: '0x',
'balance': '0x0', balance: '0x0',
'nonce': '0x0', nonce: '0x0',
'address': '0xd85a4b6a394794842887b8284293d69163007bbb', address: '0xd85a4b6a394794842887b8284293d69163007bbb',
'name': 'Send Account 4', name: 'Send Account 4',
}, },
{ {
'address': '0x06195827297c7a80a443b6894d3bdb8824b43896', address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
'name': 'Address Book Account 1', name: 'Address Book Account 1',
}, },
] ]
) )
@ -500,26 +520,26 @@ describe('send selectors', () => {
assert.deepEqual( assert.deepEqual(
getUnapprovedTxs(mockState), getUnapprovedTxs(mockState),
{ {
'4768706228115573': { 4768706228115573: {
'id': 4768706228115573, id: 4768706228115573,
'time': 1487363153561, time: 1487363153561,
'status': 'unapproved', status: 'unapproved',
'gasMultiplier': 1, gasMultiplier: 1,
'metamaskNetworkId': '3', metamaskNetworkId: '3',
'txParams': { txParams: {
'from': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb', from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'to': '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761', to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
'value': '0xde0b6b3a7640000', value: '0xde0b6b3a7640000',
'metamaskId': 4768706228115573, metamaskId: 4768706228115573,
'metamaskNetworkId': '3', metamaskNetworkId: '3',
'gas': '0x5209', gas: '0x5209',
}, },
'gasLimitSpecified': false, gasLimitSpecified: false,
'estimatedGas': '0x5209', estimatedGas: '0x5209',
'txFee': '17e0186e60800', txFee: '17e0186e60800',
'txValue': 'de0b6b3a7640000', txValue: 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800', maxCost: 'de234b52e4a0800',
'gasPrice': '4a817c800', gasPrice: '4a817c800',
}, },
} }
) )
@ -559,14 +579,131 @@ describe('send selectors', () => {
}) })
}) })
// TODO describe('transactionsSelector()', () => {
// describe('transactionsSelector()', () => { it('should return the selected addresses selected token transactions', () => {
// it('should', () => { assert.deepEqual(
// assert.deepEqual( transactionsSelector(mockState),
// transactionsSelector(mockState), [
{
id: 'mockTokenTx1',
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
time: 1700000000000,
},
{
id: 'mockTokenTx3',
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
time: 1500000000000,
},
]
)
})
// ) it('should return all transactions if no token is selected', () => {
// }) const modifiedMetamaskState = Object.assign({}, mockState.metamask, { selectedTokenAddress: false })
// }) const modifiedState = Object.assign({}, mockState, { metamask: modifiedMetamaskState })
assert.deepEqual(
transactionsSelector(modifiedState),
[
{
id: 'mockTokenTx1',
time: 1700000000000,
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
},
{
id: 'unapprovedMessage1',
time: 1650000000000,
},
{
id: 'mockTokenTx2',
time: 1600000000000,
txParams: {
to: '0xafaketokenaddress',
},
},
{
id: 'unapprovedMessage2',
time: 1550000000000,
},
{
id: 'mockTokenTx3',
time: 1500000000000,
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
},
{
id: 'unapprovedMessage3',
time: 1450000000000,
},
{
id: 'mockEthTx1',
time: 1400000000000,
txParams: {
to: '0xd85a4b6a394794842887b8284293d69163007bbb',
},
},
]
)
})
it('should return shapeshift transactions if current network is 1', () => {
const modifiedMetamaskState = Object.assign({}, mockState.metamask, { selectedTokenAddress: false, network: '1' })
const modifiedState = Object.assign({}, mockState, { metamask: modifiedMetamaskState })
assert.deepEqual(
transactionsSelector(modifiedState),
[
{
id: 'mockTokenTx1',
time: 1700000000000,
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
},
{ id: 'shapeShiftTx1', 'time': 1675000000000 },
{
id: 'unapprovedMessage1',
time: 1650000000000,
},
{
id: 'mockTokenTx2',
time: 1600000000000,
txParams: {
to: '0xafaketokenaddress',
},
},
{ id: 'shapeShiftTx2', 'time': 1575000000000 },
{
id: 'unapprovedMessage2',
time: 1550000000000,
},
{
id: 'mockTokenTx3',
time: 1500000000000,
txParams: {
to: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
},
},
{ id: 'shapeShiftTx3', 'time': 1475000000000 },
{
id: 'unapprovedMessage3',
time: 1450000000000,
},
{
id: 'mockEthTx1',
time: 1400000000000,
txParams: {
to: '0xd85a4b6a394794842887b8284293d69163007bbb',
},
},
]
)
})
})
}) })

Loading…
Cancel
Save