aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-from-row
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-05 23:11:53 +0800
committerDan <danjm.com@gmail.com>2018-05-05 23:58:14 +0800
commit7c490098548522c16be1b1e84bce37f5bf87f1f4 (patch)
tree207cabcc9c8a07c411ae293894895f32905986be /ui/app/components/send_/send-content/send-from-row
parente869d09c79b0ba276cb6a82da1f01b2d4bfefce7 (diff)
downloadtangerine-wallet-browser-7c490098548522c16be1b1e84bce37f5bf87f1f4.tar.gz
tangerine-wallet-browser-7c490098548522c16be1b1e84bce37f5bf87f1f4.tar.zst
tangerine-wallet-browser-7c490098548522c16be1b1e84bce37f5bf87f1f4.zip
Unit tests for containers, utils and selectors in send_/
Diffstat (limited to 'ui/app/components/send_/send-content/send-from-row')
-rw-r--r--ui/app/components/send_/send-content/send-from-row/send-from-row.container.js4
-rw-r--r--ui/app/components/send_/send-content/send-from-row/send-from-row.utils.js12
-rw-r--r--ui/app/components/send_/send-content/send-from-row/tests/send-from-row-container.test.js110
-rw-r--r--ui/app/components/send_/send-content/send-from-row/tests/send-from-row-selectors.test.js20
4 files changed, 132 insertions, 14 deletions
diff --git a/ui/app/components/send_/send-content/send-from-row/send-from-row.container.js b/ui/app/components/send_/send-content/send-from-row/send-from-row.container.js
index 9e366445d..377aead0a 100644
--- a/ui/app/components/send_/send-content/send-from-row/send-from-row.container.js
+++ b/ui/app/components/send_/send-content/send-from-row/send-from-row.container.js
@@ -8,7 +8,7 @@ import {
import {
getFromDropdownOpen,
} from './send-from-row.selectors.js'
-import { calcTokenUpdateAmount } from './send-from-row.utils.js'
+import { calcTokenBalance } from '../../send.utils.js'
import {
updateSendFrom,
setSendTokenBalance,
@@ -39,7 +39,7 @@ function mapDispatchToProps (dispatch) {
setSendTokenBalance: (usersToken, selectedToken) => {
if (!usersToken) return
- const tokenBalance = calcTokenUpdateAmount(selectedToken, selectedToken)
+ const tokenBalance = calcTokenBalance(usersToken, selectedToken)
dispatch(setSendTokenBalance(tokenBalance))
},
}
diff --git a/ui/app/components/send_/send-content/send-from-row/send-from-row.utils.js b/ui/app/components/send_/send-content/send-from-row/send-from-row.utils.js
deleted file mode 100644
index 0aaaef793..000000000
--- a/ui/app/components/send_/send-content/send-from-row/send-from-row.utils.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const {
- calcTokenAmount,
-} = require('../../../../token-util')
-
-function calcTokenUpdateAmount (usersToken, selectedToken) {
- const { decimals } = selectedToken || {}
- return calcTokenAmount(usersToken.balance.toString(), decimals)
-}
-
-module.exports = {
- calcTokenUpdateAmount,
-}
diff --git a/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-container.test.js b/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-container.test.js
index e69de29bb..70ab963ab 100644
--- a/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-container.test.js
+++ b/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-container.test.js
@@ -0,0 +1,110 @@
+import assert from 'assert'
+import proxyquire from 'proxyquire'
+import sinon from 'sinon'
+
+let mapStateToProps
+let mapDispatchToProps
+
+const actionSpies = {
+ updateSendFrom: sinon.spy(),
+ setSendTokenBalance: sinon.spy(),
+}
+const duckActionSpies = {
+ closeFromDropdown: sinon.spy(),
+ openFromDropdown: sinon.spy(),
+}
+
+proxyquire('../send-from-row.container.js', {
+ 'react-redux': {
+ connect: (ms, md) => {
+ mapStateToProps = ms
+ mapDispatchToProps = md
+ return () => ({})
+ },
+ },
+ '../../send.selectors.js': {
+ accountsWithSendEtherInfoSelector: (s) => `mockFromAccounts:${s}`,
+ getConversionRate: (s) => `mockConversionRate:${s}`,
+ getSelectedTokenContract: (s) => `mockTokenContract:${s}`,
+ getSendFromObject: (s) => `mockFrom:${s}`,
+ },
+ './send-from-row.selectors.js': { getFromDropdownOpen: (s) => `mockFromDropdownOpen:${s}` },
+ '../../send.utils.js': { calcTokenBalance: (a, b) => a + b },
+ '../../../../actions': actionSpies,
+ '../../../../ducks/send': duckActionSpies,
+})
+
+describe('send-from-row container', () => {
+
+ describe('mapStateToProps()', () => {
+
+ it('should map the correct properties to props', () => {
+ assert.deepEqual(mapStateToProps('mockState'), {
+ conversionRate: 'mockConversionRate:mockState',
+ from: 'mockFrom:mockState',
+ fromAccounts: 'mockFromAccounts:mockState',
+ fromDropdownOpen: 'mockFromDropdownOpen:mockState',
+ tokenContract: 'mockTokenContract:mockState',
+ })
+ })
+
+ })
+
+ describe('mapDispatchToProps()', () => {
+ let dispatchSpy
+ let mapDispatchToPropsObject
+
+ beforeEach(() => {
+ dispatchSpy = sinon.spy()
+ mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
+ })
+
+ describe('closeFromDropdown()', () => {
+ it('should dispatch a closeFromDropdown action', () => {
+ mapDispatchToPropsObject.closeFromDropdown()
+ assert(dispatchSpy.calledOnce)
+ assert(duckActionSpies.closeFromDropdown.calledOnce)
+ assert.equal(
+ duckActionSpies.closeFromDropdown.getCall(0).args[0],
+ undefined
+ )
+ })
+ })
+
+ describe('openFromDropdown()', () => {
+ it('should dispatch a openFromDropdown action', () => {
+ mapDispatchToPropsObject.openFromDropdown()
+ assert(dispatchSpy.calledOnce)
+ assert(duckActionSpies.openFromDropdown.calledOnce)
+ assert.equal(
+ duckActionSpies.openFromDropdown.getCall(0).args[0],
+ undefined
+ )
+ })
+ })
+
+ describe('updateSendFrom()', () => {
+ it('should dispatch an updateSendFrom action', () => {
+ mapDispatchToPropsObject.updateSendFrom('mockFrom')
+ assert(dispatchSpy.calledOnce)
+ assert.equal(
+ actionSpies.updateSendFrom.getCall(0).args[0],
+ 'mockFrom'
+ )
+ })
+ })
+
+ describe('setSendTokenBalance()', () => {
+ it('should dispatch an setSendTokenBalance action', () => {
+ mapDispatchToPropsObject.setSendTokenBalance('mockUsersToken', 'mockSelectedToken')
+ assert(dispatchSpy.calledOnce)
+ assert.equal(
+ actionSpies.setSendTokenBalance.getCall(0).args[0],
+ 'mockUsersTokenmockSelectedToken'
+ )
+ })
+ })
+
+ })
+
+})
diff --git a/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-selectors.test.js b/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-selectors.test.js
index e69de29bb..ecb57bbc3 100644
--- a/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-selectors.test.js
+++ b/ui/app/components/send_/send-content/send-from-row/tests/send-from-row-selectors.test.js
@@ -0,0 +1,20 @@
+import assert from 'assert'
+import {
+ getFromDropdownOpen,
+} from '../send-from-row.selectors.js'
+
+describe('send-from-row selectors', () => {
+
+ describe('getFromDropdownOpen()', () => {
+ it('should get send.fromDropdownOpen', () => {
+ const state = {
+ send: {
+ fromDropdownOpen: null,
+ },
+ }
+
+ assert.equal(getFromDropdownOpen(state), null)
+ })
+ })
+
+})