aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-footer/tests
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-06-20 23:48:23 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-07-16 23:28:32 +0800
commitb3d78ed8a1fbea059344b04416fb21bdb1b73f86 (patch)
tree6a2d8f6dda690961331c9bcbf5e2c6bf7102bced /ui/app/components/send_/send-footer/tests
parentf31e87dcd5cec09e81c741e311efc3793c9d9b98 (diff)
downloadtangerine-wallet-browser-b3d78ed8a1fbea059344b04416fb21bdb1b73f86.tar.gz
tangerine-wallet-browser-b3d78ed8a1fbea059344b04416fb21bdb1b73f86.tar.zst
tangerine-wallet-browser-b3d78ed8a1fbea059344b04416fb21bdb1b73f86.zip
Remove send_ directory, revert to just having send
Revert accidentally changed constants. Require defaults in ens-input, gas-fee-display and confirm screens.
Diffstat (limited to 'ui/app/components/send_/send-footer/tests')
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-component.test.js230
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-container.test.js191
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-selectors.test.js24
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-utils.test.js210
4 files changed, 0 insertions, 655 deletions
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-component.test.js b/ui/app/components/send_/send-footer/tests/send-footer-component.test.js
deleted file mode 100644
index 4b2cd327d..000000000
--- a/ui/app/components/send_/send-footer/tests/send-footer-component.test.js
+++ /dev/null
@@ -1,230 +0,0 @@
-import React from 'react'
-import assert from 'assert'
-import { shallow } from 'enzyme'
-import sinon from 'sinon'
-import { CONFIRM_TRANSACTION_ROUTE, DEFAULT_ROUTE } from '../../../../routes'
-import SendFooter from '../send-footer.component.js'
-
-import PageContainerFooter from '../../../page-container/page-container-footer'
-
-const propsMethodSpies = {
- addToAddressBookIfNew: sinon.spy(),
- clearSend: sinon.spy(),
- sign: sinon.spy(),
- update: sinon.spy(),
-}
-const historySpies = {
- push: sinon.spy(),
-}
-const MOCK_EVENT = { preventDefault: () => {} }
-
-sinon.spy(SendFooter.prototype, 'onCancel')
-sinon.spy(SendFooter.prototype, 'onSubmit')
-
-describe('SendFooter Component', function () {
- let wrapper
-
- beforeEach(() => {
- wrapper = shallow(<SendFooter
- addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
- amount={'mockAmount'}
- clearSend={propsMethodSpies.clearSend}
- disabled={true}
- editingTransactionId={'mockEditingTransactionId'}
- errors={{}}
- from={ { address: 'mockAddress', balance: 'mockBalance' } }
- gasLimit={'mockGasLimit'}
- gasPrice={'mockGasPrice'}
- gasTotal={'mockGasTotal'}
- history={historySpies}
- inError={false}
- selectedToken={{ mockProp: 'mockSelectedTokenProp' }}
- sign={propsMethodSpies.sign}
- to={'mockTo'}
- toAccounts={['mockAccount']}
- tokenBalance={'mockTokenBalance'}
- unapprovedTxs={['mockTx']}
- update={propsMethodSpies.update}
- />, { context: { t: str => str } })
- })
-
- afterEach(() => {
- propsMethodSpies.clearSend.resetHistory()
- propsMethodSpies.addToAddressBookIfNew.resetHistory()
- propsMethodSpies.clearSend.resetHistory()
- propsMethodSpies.sign.resetHistory()
- propsMethodSpies.update.resetHistory()
- historySpies.push.resetHistory()
- SendFooter.prototype.onCancel.resetHistory()
- SendFooter.prototype.onSubmit.resetHistory()
- })
-
- describe('onCancel', () => {
- it('should call clearSend', () => {
- assert.equal(propsMethodSpies.clearSend.callCount, 0)
- wrapper.instance().onCancel()
- assert.equal(propsMethodSpies.clearSend.callCount, 1)
- })
-
- it('should call history.push', () => {
- assert.equal(historySpies.push.callCount, 0)
- wrapper.instance().onCancel()
- assert.equal(historySpies.push.callCount, 1)
- assert.equal(historySpies.push.getCall(0).args[0], DEFAULT_ROUTE)
- })
- })
-
-
- describe('formShouldBeDisabled()', () => {
- const config = {
- 'should return true if inError is truthy': {
- inError: true,
- expectedResult: true,
- },
- 'should return true if gasTotal is falsy': {
- inError: false,
- gasTotal: false,
- expectedResult: true,
- },
- 'should return true if to is truthy': {
- to: '0xsomevalidAddress',
- inError: false,
- gasTotal: false,
- expectedResult: true,
- },
- 'should return true if selectedToken is truthy and tokenBalance is falsy': {
- selectedToken: true,
- tokenBalance: null,
- expectedResult: true,
- },
- 'should return false if inError is false and all other params are truthy': {
- inError: false,
- gasTotal: '0x123',
- selectedToken: true,
- tokenBalance: 123,
- expectedResult: false,
- },
- }
- Object.entries(config).map(([description, obj]) => {
- it(description, () => {
- wrapper.setProps(obj)
- assert.equal(wrapper.instance().formShouldBeDisabled(), obj.expectedResult)
- })
- })
- })
-
- describe('onSubmit', () => {
- it('should call addToAddressBookIfNew with the correct params', () => {
- wrapper.instance().onSubmit(MOCK_EVENT)
- assert(propsMethodSpies.addToAddressBookIfNew.calledOnce)
- assert.deepEqual(
- propsMethodSpies.addToAddressBookIfNew.getCall(0).args,
- ['mockTo', ['mockAccount']]
- )
- })
-
- it('should call props.update if editingTransactionId is truthy', () => {
- wrapper.instance().onSubmit(MOCK_EVENT)
- assert(propsMethodSpies.update.calledOnce)
- assert.deepEqual(
- propsMethodSpies.update.getCall(0).args[0],
- {
- amount: 'mockAmount',
- editingTransactionId: 'mockEditingTransactionId',
- from: 'mockAddress',
- gas: 'mockGasLimit',
- gasPrice: 'mockGasPrice',
- selectedToken: { mockProp: 'mockSelectedTokenProp' },
- to: 'mockTo',
- unapprovedTxs: ['mockTx'],
- }
- )
- })
-
- it('should not call props.sign if editingTransactionId is truthy', () => {
- assert.equal(propsMethodSpies.sign.callCount, 0)
- })
-
- it('should call props.sign if editingTransactionId is falsy', () => {
- wrapper.setProps({ editingTransactionId: null })
- wrapper.instance().onSubmit(MOCK_EVENT)
- assert(propsMethodSpies.sign.calledOnce)
- assert.deepEqual(
- propsMethodSpies.sign.getCall(0).args[0],
- {
- amount: 'mockAmount',
- from: 'mockAddress',
- gas: 'mockGasLimit',
- gasPrice: 'mockGasPrice',
- selectedToken: { mockProp: 'mockSelectedTokenProp' },
- to: 'mockTo',
- }
- )
- })
-
- it('should not call props.update if editingTransactionId is falsy', () => {
- assert.equal(propsMethodSpies.update.callCount, 0)
- })
-
- it('should call history.push', done => {
- Promise.resolve(wrapper.instance().onSubmit(MOCK_EVENT))
- .then(() => {
- assert.equal(historySpies.push.callCount, 1)
- assert.equal(historySpies.push.getCall(0).args[0], CONFIRM_TRANSACTION_ROUTE)
- done()
- })
- })
- })
-
- describe('render', () => {
- beforeEach(() => {
- sinon.stub(SendFooter.prototype, 'formShouldBeDisabled').returns('formShouldBeDisabledReturn')
- wrapper = shallow(<SendFooter
- addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
- amount={'mockAmount'}
- clearSend={propsMethodSpies.clearSend}
- disabled={true}
- editingTransactionId={'mockEditingTransactionId'}
- errors={{}}
- from={ { address: 'mockAddress', balance: 'mockBalance' } }
- gasLimit={'mockGasLimit'}
- gasPrice={'mockGasPrice'}
- gasTotal={'mockGasTotal'}
- history={historySpies}
- inError={false}
- selectedToken={{ mockProp: 'mockSelectedTokenProp' }}
- sign={propsMethodSpies.sign}
- to={'mockTo'}
- toAccounts={['mockAccount']}
- tokenBalance={'mockTokenBalance'}
- unapprovedTxs={['mockTx']}
- update={propsMethodSpies.update}
- />, { context: { t: str => str } })
- })
-
- afterEach(() => {
- SendFooter.prototype.formShouldBeDisabled.restore()
- })
-
- it('should render a PageContainerFooter component', () => {
- assert.equal(wrapper.find(PageContainerFooter).length, 1)
- })
-
- it('should pass the correct props to PageContainerFooter', () => {
- const {
- onCancel,
- onSubmit,
- disabled,
- } = wrapper.find(PageContainerFooter).props()
- assert.equal(disabled, 'formShouldBeDisabledReturn')
-
- assert.equal(SendFooter.prototype.onSubmit.callCount, 0)
- onSubmit(MOCK_EVENT)
- assert.equal(SendFooter.prototype.onSubmit.callCount, 1)
-
- assert.equal(SendFooter.prototype.onCancel.callCount, 0)
- onCancel()
- assert.equal(SendFooter.prototype.onCancel.callCount, 1)
- })
- })
-})
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-container.test.js b/ui/app/components/send_/send-footer/tests/send-footer-container.test.js
deleted file mode 100644
index 39d6a7686..000000000
--- a/ui/app/components/send_/send-footer/tests/send-footer-container.test.js
+++ /dev/null
@@ -1,191 +0,0 @@
-import assert from 'assert'
-import proxyquire from 'proxyquire'
-import sinon from 'sinon'
-
-let mapStateToProps
-let mapDispatchToProps
-
-const actionSpies = {
- addToAddressBook: sinon.spy(),
- clearSend: sinon.spy(),
- signTokenTx: sinon.spy(),
- signTx: sinon.spy(),
- updateTransaction: sinon.spy(),
-}
-const utilsStubs = {
- addressIsNew: sinon.stub().returns(true),
- constructTxParams: sinon.stub().returns('mockConstructedTxParams'),
- constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
-}
-
-proxyquire('../send-footer.container.js', {
- 'react-redux': {
- connect: (ms, md) => {
- mapStateToProps = ms
- mapDispatchToProps = md
- return () => ({})
- },
- },
- '../../../actions': actionSpies,
- '../send.selectors': {
- getGasLimit: (s) => `mockGasLimit:${s}`,
- getGasPrice: (s) => `mockGasPrice:${s}`,
- getGasTotal: (s) => `mockGasTotal:${s}`,
- getSelectedToken: (s) => `mockSelectedToken:${s}`,
- getSendAmount: (s) => `mockAmount:${s}`,
- getSendEditingTransactionId: (s) => `mockEditingTransactionId:${s}`,
- getSendFromObject: (s) => `mockFromObject:${s}`,
- getSendTo: (s) => `mockTo:${s}`,
- getSendToAccounts: (s) => `mockToAccounts:${s}`,
- getTokenBalance: (s) => `mockTokenBalance:${s}`,
- getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
- },
- './send-footer.selectors': { isSendFormInError: (s) => `mockInError:${s}` },
- './send-footer.utils': utilsStubs,
-})
-
-describe('send-footer container', () => {
-
- describe('mapStateToProps()', () => {
-
- it('should map the correct properties to props', () => {
- assert.deepEqual(mapStateToProps('mockState'), {
- amount: 'mockAmount:mockState',
- selectedToken: 'mockSelectedToken:mockState',
- editingTransactionId: 'mockEditingTransactionId:mockState',
- from: 'mockFromObject:mockState',
- gasLimit: 'mockGasLimit:mockState',
- gasPrice: 'mockGasPrice:mockState',
- gasTotal: 'mockGasTotal:mockState',
- inError: 'mockInError:mockState',
- to: 'mockTo:mockState',
- toAccounts: 'mockToAccounts:mockState',
- tokenBalance: 'mockTokenBalance:mockState',
- unapprovedTxs: 'mockUnapprovedTxs:mockState',
- })
- })
-
- })
-
- describe('mapDispatchToProps()', () => {
- let dispatchSpy
- let mapDispatchToPropsObject
-
- beforeEach(() => {
- dispatchSpy = sinon.spy()
- mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
- })
-
- describe('clearSend()', () => {
- it('should dispatch an action', () => {
- mapDispatchToPropsObject.clearSend()
- assert(dispatchSpy.calledOnce)
- assert(actionSpies.clearSend.calledOnce)
- })
- })
-
- describe('sign()', () => {
- it('should dispatch a signTokenTx action if selectedToken is defined', () => {
- mapDispatchToPropsObject.sign({
- selectedToken: {
- address: '0xabc',
- },
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- })
- assert(dispatchSpy.calledOnce)
- assert.deepEqual(
- utilsStubs.constructTxParams.getCall(0).args[0],
- {
- selectedToken: {
- address: '0xabc',
- },
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- }
- )
- assert.deepEqual(
- actionSpies.signTokenTx.getCall(0).args,
- [ '0xabc', 'mockTo', 'mockAmount', 'mockConstructedTxParams' ]
- )
- })
-
- it('should dispatch a sign action if selectedToken is not defined', () => {
- utilsStubs.constructTxParams.resetHistory()
- mapDispatchToPropsObject.sign({
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- })
- assert(dispatchSpy.calledOnce)
- assert.deepEqual(
- utilsStubs.constructTxParams.getCall(0).args[0],
- {
- selectedToken: undefined,
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- }
- )
- assert.deepEqual(
- actionSpies.signTx.getCall(0).args,
- [ 'mockConstructedTxParams' ]
- )
- })
- })
-
- describe('update()', () => {
- it('should dispatch an updateTransaction action', () => {
- mapDispatchToPropsObject.update({
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- editingTransactionId: 'mockEditingTransactionId',
- selectedToken: 'mockSelectedToken',
- unapprovedTxs: 'mockUnapprovedTxs',
- })
- assert(dispatchSpy.calledOnce)
- assert.deepEqual(
- utilsStubs.constructUpdatedTx.getCall(0).args[0],
- {
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- editingTransactionId: 'mockEditingTransactionId',
- selectedToken: 'mockSelectedToken',
- unapprovedTxs: 'mockUnapprovedTxs',
- }
- )
- assert.equal(actionSpies.updateTransaction.getCall(0).args[0], 'mockConstructedUpdatedTxParams')
- })
- })
-
- describe('addToAddressBookIfNew()', () => {
- it('should dispatch an action', () => {
- mapDispatchToPropsObject.addToAddressBookIfNew('mockNewAddress', 'mockToAccounts', 'mockNickname')
- assert(dispatchSpy.calledOnce)
- assert.equal(utilsStubs.addressIsNew.getCall(0).args[0], 'mockToAccounts')
- assert.deepEqual(
- actionSpies.addToAddressBook.getCall(0).args,
- [ '0xmockNewAddress', 'mockNickname' ]
- )
- })
- })
-
- })
-
-})
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-selectors.test.js b/ui/app/components/send_/send-footer/tests/send-footer-selectors.test.js
deleted file mode 100644
index 8de032f57..000000000
--- a/ui/app/components/send_/send-footer/tests/send-footer-selectors.test.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import assert from 'assert'
-import proxyquire from 'proxyquire'
-
-const {
- isSendFormInError,
-} = proxyquire('../send-footer.selectors', {
- '../send.selectors': {
- getSendErrors: (mockState) => mockState.errors,
- },
-})
-
-describe('send-footer selectors', () => {
-
- describe('getTitleKey()', () => {
- it('should return true if any of the values of the object returned by getSendErrors are truthy', () => {
- assert.equal(isSendFormInError({ errors: { a: 'abc', b: false} }), true)
- })
-
- it('should return false if all of the values of the object returned by getSendErrors are falsy', () => {
- assert.equal(isSendFormInError({ errors: { a: false, b: null} }), false)
- })
- })
-
-})
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js b/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js
deleted file mode 100644
index 2d3135995..000000000
--- a/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js
+++ /dev/null
@@ -1,210 +0,0 @@
-import assert from 'assert'
-import proxyquire from 'proxyquire'
-import sinon from 'sinon'
-const { TOKEN_TRANSFER_FUNCTION_SIGNATURE } = require('../../send.constants')
-
-const stubs = {
- rawEncode: sinon.stub().callsFake((arr1, arr2) => {
- return [ ...arr1, ...arr2 ]
- }),
-}
-
-const sendUtils = proxyquire('../send-footer.utils.js', {
- 'ethereumjs-abi': {
- rawEncode: stubs.rawEncode,
- },
-})
-const {
- addressIsNew,
- constructTxParams,
- constructUpdatedTx,
- addHexPrefixToObjectValues,
-} = sendUtils
-
-describe('send-footer utils', () => {
-
- describe('addHexPrefixToObjectValues()', () => {
- it('should return a new object with the same properties with a 0x prefix', () => {
- assert.deepEqual(
- addHexPrefixToObjectValues({
- prop1: '0x123',
- prop2: '456',
- prop3: 'x',
- }),
- {
- prop1: '0x123',
- prop2: '0x456',
- prop3: '0xx',
- }
- )
- })
- })
-
- describe('addressIsNew()', () => {
- it('should return false if the address exists in toAccounts', () => {
- assert.equal(
- addressIsNew([
- { address: '0xabc' },
- { address: '0xdef' },
- { address: '0xghi' },
- ], '0xdef'),
- false
- )
- })
-
- it('should return true if the address does not exists in toAccounts', () => {
- assert.equal(
- addressIsNew([
- { address: '0xabc' },
- { address: '0xdef' },
- { address: '0xghi' },
- ], '0xxyz'),
- true
- )
- })
- })
-
- describe('constructTxParams()', () => {
- it('should return a new txParams object with value and to properties if there is no selectedToken', () => {
- assert.deepEqual(
- constructTxParams({
- selectedToken: false,
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- }),
- {
- to: '0xmockTo',
- value: '0xmockAmount',
- from: '0xmockFrom',
- gas: '0xmockGas',
- gasPrice: '0xmockGasPrice',
- }
- )
- })
-
- it('should return a new txParams object without a to property and a 0 value if there is a selectedToken', () => {
- assert.deepEqual(
- constructTxParams({
- selectedToken: true,
- to: 'mockTo',
- amount: 'mockAmount',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- }),
- {
- value: '0x0',
- from: '0xmockFrom',
- gas: '0xmockGas',
- gasPrice: '0xmockGasPrice',
- }
- )
- })
- })
-
- describe('constructUpdatedTx()', () => {
- it('should return a new object with an updated txParams', () => {
- const result = constructUpdatedTx({
- amount: 'mockAmount',
- editingTransactionId: '0x456',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- selectedToken: false,
- to: 'mockTo',
- unapprovedTxs: {
- '0x123': {},
- '0x456': {
- unapprovedTxParam: 'someOtherParam',
- txParams: {
- data: 'someData',
- },
- },
- },
- })
-
- assert.deepEqual(result, {
- unapprovedTxParam: 'someOtherParam',
- txParams: {
- from: '0xmockFrom',
- gas: '0xmockGas',
- gasPrice: '0xmockGasPrice',
- value: '0xmockAmount',
- to: '0xmockTo',
- data: '0xsomeData',
- },
- })
- })
-
- it('should not have data property if there is non in the original tx', () => {
- const result = constructUpdatedTx({
- amount: 'mockAmount',
- editingTransactionId: '0x456',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- selectedToken: false,
- to: 'mockTo',
- unapprovedTxs: {
- '0x123': {},
- '0x456': {
- unapprovedTxParam: 'someOtherParam',
- txParams: {
- from: 'oldFrom',
- gas: 'oldGas',
- gasPrice: 'oldGasPrice',
- },
- },
- },
- })
-
- assert.deepEqual(result, {
- unapprovedTxParam: 'someOtherParam',
- txParams: {
- from: '0xmockFrom',
- gas: '0xmockGas',
- gasPrice: '0xmockGasPrice',
- value: '0xmockAmount',
- to: '0xmockTo',
- },
- })
- })
-
- it('should have token property values if selectedToken is truthy', () => {
- const result = constructUpdatedTx({
- amount: 'mockAmount',
- editingTransactionId: '0x456',
- from: 'mockFrom',
- gas: 'mockGas',
- gasPrice: 'mockGasPrice',
- selectedToken: {
- address: 'mockTokenAddress',
- },
- to: 'mockTo',
- unapprovedTxs: {
- '0x123': {},
- '0x456': {
- unapprovedTxParam: 'someOtherParam',
- txParams: {},
- },
- },
- })
-
- assert.deepEqual(result, {
- unapprovedTxParam: 'someOtherParam',
- txParams: {
- from: '0xmockFrom',
- gas: '0xmockGas',
- gasPrice: '0xmockGasPrice',
- value: '0x0',
- to: '0xmockTokenAddress',
- data: `${TOKEN_TRANSFER_FUNCTION_SIGNATURE}ss56Tont`,
- },
- })
- })
- })
-
-})