aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-14 20:13:55 +0800
committerDan <danjm.com@gmail.com>2018-05-14 20:13:55 +0800
commitb3f08681fd943947526a294759896d093cdbd135 (patch)
tree8bb866ba7ec7aaea30533edd6841463e5f43d370 /ui
parentc2ed2d4e5003abd01552570452a5b0b38626abca (diff)
downloadtangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar.gz
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar.bz2
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar.lz
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar.xz
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.tar.zst
tangerine-wallet-browser-b3f08681fd943947526a294759896d093cdbd135.zip
Add missing unit tests in send_/: now 100% function test coverage in send_/
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js11
-rw-r--r--ui/app/components/send_/send.selectors.js1
-rw-r--r--ui/app/components/send_/tests/send-selectors-test-data.js45
-rw-r--r--ui/app/components/send_/tests/send-selectors.test.js353
4 files changed, 298 insertions, 112 deletions
diff --git a/ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js b/ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js
index f312896c4..bb7f3776c 100644
--- a/ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js
+++ b/ui/app/components/send_/account-list-item/tests/account-list-item-component.test.js
@@ -46,6 +46,17 @@ describe('AccountListItem Component', function () {
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', () => {
assert.equal(wrapper.find('.mockClassName > .account-list-item__top-row').length, 1)
assert(wrapper.find('.mockClassName > .account-list-item__top-row').is('div'))
diff --git a/ui/app/components/send_/send.selectors.js b/ui/app/components/send_/send.selectors.js
index 4fadf442c..476e77cac 100644
--- a/ui/app/components/send_/send.selectors.js
+++ b/ui/app/components/send_/send.selectors.js
@@ -165,6 +165,7 @@ function getSelectedToken (state) {
function getSelectedTokenContract (state) {
const selectedToken = getSelectedToken(state)
+
return selectedToken
? global.eth.contract(abi).at(selectedToken.address)
: null
diff --git a/ui/app/components/send_/tests/send-selectors-test-data.js b/ui/app/components/send_/tests/send-selectors-test-data.js
index bdea759fb..1a95b5f41 100644
--- a/ui/app/components/send_/tests/send-selectors-test-data.js
+++ b/ui/app/components/send_/tests/send-selectors-test-data.js
@@ -86,9 +86,42 @@ module.exports = {
},
},
'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',
- 'unapprovedMsgs': {},
+ 'unapprovedMsgs': {
+ '0xabc': { id: 'unapprovedMessage1', 'time': 1650000000000 },
+ '0xdef': { id: 'unapprovedMessage2', 'time': 1550000000000 },
+ '0xghi': { id: 'unapprovedMessage3', 'time': 1450000000000 },
+ },
'unapprovedMsgCount': 0,
'unapprovedPersonalMsgs': {},
'unapprovedPersonalMsgCount': 0,
@@ -116,7 +149,11 @@ module.exports = {
'provider': {
'type': 'testnet',
},
- 'shapeShiftTxList': [],
+ 'shapeShiftTxList': [
+ { id: 'shapeShiftTx1', 'time': 1675000000000 },
+ { id: 'shapeShiftTx2', 'time': 1575000000000 },
+ { id: 'shapeShiftTx3', 'time': 1475000000000 },
+ ],
'lostAccounts': [],
'send': {
'gasLimit': '0xFFFF',
@@ -158,7 +195,7 @@ module.exports = {
'txValue': 'de0b6b3a7640000',
'maxCost': 'de234b52e4a0800',
'gasPrice': '4a817c800',
- },
+ }
},
'currentLocale': 'en',
},
diff --git a/ui/app/components/send_/tests/send-selectors.test.js b/ui/app/components/send_/tests/send-selectors.test.js
index 43e7792a0..e2acc15f6 100644
--- a/ui/app/components/send_/tests/send-selectors.test.js
+++ b/ui/app/components/send_/tests/send-selectors.test.js
@@ -1,4 +1,5 @@
import assert from 'assert'
+import sinon from 'sinon'
import selectors from '../send.selectors.js'
const {
accountsWithSendEtherInfoSelector,
@@ -20,7 +21,7 @@ const {
getSelectedAddress,
getSelectedIdentity,
getSelectedToken,
- // getSelectedTokenContract,
+ getSelectedTokenContract,
getSelectedTokenExchangeRate,
getSelectedTokenToFiatRate,
getSendAmount,
@@ -36,11 +37,23 @@ const {
getTokenExchangeRate,
getUnapprovedTxs,
isSendFormInError,
- // transactionsSelector,
+ transactionsSelector,
} = selectors
import mockState from './send-selectors-test-data'
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()', () => {
it('should return an array of account objects with name info from identities', () => {
@@ -48,32 +61,32 @@ describe('send selectors', () => {
accountsWithSendEtherInfoSelector(mockState),
[
{
- 'code': '0x',
- 'balance': '0x47c9d71831c76efe',
- 'nonce': '0x1b',
- 'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
- 'name': 'Send Account 1',
+ code: '0x',
+ balance: '0x47c9d71831c76efe',
+ nonce: '0x1b',
+ address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
+ name: 'Send Account 1',
},
{
- 'code': '0x',
- 'balance': '0x37452b1315889f80',
- 'nonce': '0xa',
- 'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
- 'name': 'Send Account 2',
+ code: '0x',
+ balance: '0x37452b1315889f80',
+ nonce: '0xa',
+ address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
+ name: 'Send Account 2',
},
{
- 'code': '0x',
- 'balance': '0x30c9d71831c76efe',
- 'nonce': '0x1c',
- 'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
- 'name': 'Send Account 3',
+ code: '0x',
+ balance: '0x30c9d71831c76efe',
+ nonce: '0x1c',
+ address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
+ name: 'Send Account 3',
},
{
- 'code': '0x',
- 'balance': '0x0',
- 'nonce': '0x0',
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
- 'name': 'Send Account 4',
+ code: '0x',
+ balance: '0x0',
+ nonce: '0x0',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
+ name: 'Send Account 4',
},
]
)
@@ -95,8 +108,8 @@ describe('send selectors', () => {
getAddressBook(mockState),
[
{
- 'address': '0x06195827297c7a80a443b6894d3bdb8824b43896',
- 'name': 'Address Book Account 1',
+ address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
+ name: 'Address Book Account 1',
},
],
)
@@ -145,11 +158,11 @@ describe('send selectors', () => {
assert.deepEqual(
getCurrentAccountWithSendEtherInfo(mockState),
{
- 'code': '0x',
- 'balance': '0x0',
- 'nonce': '0x0',
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
- 'name': 'Send Account 4',
+ code: '0x',
+ balance: '0x0',
+ nonce: '0x0',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
+ name: 'Send Account 4',
}
)
})
@@ -232,10 +245,10 @@ describe('send selectors', () => {
assert.deepEqual(
getSelectedAccount(mockState),
{
- 'code': '0x',
- 'balance': '0x0',
- 'nonce': '0x0',
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
+ code: '0x',
+ balance: '0x0',
+ nonce: '0x0',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
}
)
})
@@ -255,8 +268,8 @@ describe('send selectors', () => {
assert.deepEqual(
getSelectedIdentity(mockState),
{
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
- 'name': 'Send Account 4',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
+ name: 'Send Account 4',
}
)
})
@@ -267,18 +280,18 @@ describe('send selectors', () => {
assert.deepEqual(
getSelectedToken(mockState),
{
- 'address': '0x8d6b81208414189a58339873ab429b6c47ab92d3',
- 'decimals': 4,
- 'symbol': 'DEF',
+ address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
+ decimals: 4,
+ symbol: 'DEF',
}
)
})
it('should return the send token if none is currently selected, but a send token exists', () => {
const mockSendToken = {
- 'address': '0x123456708414189a58339873ab429b6c47ab92d3',
- 'decimals': 4,
- 'symbol': 'JKL',
+ address: '0x123456708414189a58339873ab429b6c47ab92d3',
+ decimals: 4,
+ symbol: 'JKL',
}
const editedMockState = {
metamask: Object.assign({}, mockState.metamask, {
@@ -295,15 +308,22 @@ describe('send selectors', () => {
})
})
- // TODO
- // describe('getSelectedTokenContract()', () => {
- // it('should', () => {
- // assert.deepEqual(
- // getSelectedTokenContract(mockState),
+ describe('getSelectedTokenContract()', () => {
+ it('should return the contract at the selected token address', () => {
+ assert.equal(
+ 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()', () => {
it('should return the exchange rate for the selected token', () => {
@@ -345,7 +365,7 @@ describe('send selectors', () => {
it('should return the send.errors', () => {
assert.deepEqual(
getSendErrors(mockState),
- { 'someError': null }
+ { someError: null }
)
})
})
@@ -355,8 +375,8 @@ describe('send selectors', () => {
assert.deepEqual(
getSendFrom(mockState),
{
- 'address': '0xabcdefg',
- 'balance': '0x5f4e3d2c1',
+ address: '0xabcdefg',
+ balance: '0x5f4e3d2c1',
}
)
})
@@ -390,8 +410,8 @@ describe('send selectors', () => {
assert.deepEqual(
getSendFromObject(mockState),
{
- 'address': '0xabcdefg',
- 'balance': '0x5f4e3d2c1',
+ address: '0xabcdefg',
+ balance: '0x5f4e3d2c1',
}
)
})
@@ -407,11 +427,11 @@ describe('send selectors', () => {
assert.deepEqual(
getSendFromObject(editedMockState),
{
- 'code': '0x',
- 'balance': '0x0',
- 'nonce': '0x0',
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
- 'name': 'Send Account 4',
+ code: '0x',
+ balance: '0x0',
+ nonce: '0x0',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
+ name: 'Send Account 4',
}
)
})
@@ -441,36 +461,36 @@ describe('send selectors', () => {
getSendToAccounts(mockState),
[
{
- 'code': '0x',
- 'balance': '0x47c9d71831c76efe',
- 'nonce': '0x1b',
- 'address': '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
- 'name': 'Send Account 1',
+ code: '0x',
+ balance: '0x47c9d71831c76efe',
+ nonce: '0x1b',
+ address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
+ name: 'Send Account 1',
},
{
- 'code': '0x',
- 'balance': '0x37452b1315889f80',
- 'nonce': '0xa',
- 'address': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
- 'name': 'Send Account 2',
+ code: '0x',
+ balance: '0x37452b1315889f80',
+ nonce: '0xa',
+ address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
+ name: 'Send Account 2',
},
{
- 'code': '0x',
- 'balance': '0x30c9d71831c76efe',
- 'nonce': '0x1c',
- 'address': '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
- 'name': 'Send Account 3',
+ code: '0x',
+ balance: '0x30c9d71831c76efe',
+ nonce: '0x1c',
+ address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
+ name: 'Send Account 3',
},
{
- 'code': '0x',
- 'balance': '0x0',
- 'nonce': '0x0',
- 'address': '0xd85a4b6a394794842887b8284293d69163007bbb',
- 'name': 'Send Account 4',
+ code: '0x',
+ balance: '0x0',
+ nonce: '0x0',
+ address: '0xd85a4b6a394794842887b8284293d69163007bbb',
+ name: 'Send Account 4',
},
{
- 'address': '0x06195827297c7a80a443b6894d3bdb8824b43896',
- 'name': 'Address Book Account 1',
+ address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
+ name: 'Address Book Account 1',
},
]
)
@@ -500,26 +520,26 @@ describe('send selectors', () => {
assert.deepEqual(
getUnapprovedTxs(mockState),
{
- '4768706228115573': {
- 'id': 4768706228115573,
- 'time': 1487363153561,
- 'status': 'unapproved',
- 'gasMultiplier': 1,
- 'metamaskNetworkId': '3',
- 'txParams': {
- 'from': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
- 'to': '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
- 'value': '0xde0b6b3a7640000',
- 'metamaskId': 4768706228115573,
- 'metamaskNetworkId': '3',
- 'gas': '0x5209',
+ 4768706228115573: {
+ id: 4768706228115573,
+ time: 1487363153561,
+ status: 'unapproved',
+ gasMultiplier: 1,
+ metamaskNetworkId: '3',
+ txParams: {
+ from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
+ to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
+ value: '0xde0b6b3a7640000',
+ metamaskId: 4768706228115573,
+ metamaskNetworkId: '3',
+ gas: '0x5209',
},
- 'gasLimitSpecified': false,
- 'estimatedGas': '0x5209',
- 'txFee': '17e0186e60800',
- 'txValue': 'de0b6b3a7640000',
- 'maxCost': 'de234b52e4a0800',
- 'gasPrice': '4a817c800',
+ gasLimitSpecified: false,
+ estimatedGas: '0x5209',
+ txFee: '17e0186e60800',
+ txValue: 'de0b6b3a7640000',
+ maxCost: 'de234b52e4a0800',
+ gasPrice: '4a817c800',
},
}
)
@@ -559,14 +579,131 @@ describe('send selectors', () => {
})
})
- // TODO
- // describe('transactionsSelector()', () => {
- // it('should', () => {
- // assert.deepEqual(
- // transactionsSelector(mockState),
+ describe('transactionsSelector()', () => {
+ it('should return the selected addresses selected token transactions', () => {
+ assert.deepEqual(
+ 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',
+ },
+ },
+ ]
+ )
+ })
+ })
})