aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/pages/send/tests/send-component.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/pages/send/tests/send-component.test.js')
-rw-r--r--ui/app/pages/send/tests/send-component.test.js102
1 files changed, 98 insertions, 4 deletions
diff --git a/ui/app/pages/send/tests/send-component.test.js b/ui/app/pages/send/tests/send-component.test.js
index 81955cc1d..5b7cafed5 100644
--- a/ui/app/pages/send/tests/send-component.test.js
+++ b/ui/app/pages/send/tests/send-component.test.js
@@ -5,8 +5,9 @@ import { shallow } from 'enzyme'
import sinon from 'sinon'
import timeout from '../../../../lib/test-timeout'
+import AddRecipient from '../send-content/add-recipient/add-recipient.container'
import SendHeader from '../send-header/send-header.container'
-import SendContent from '../send-content/send-content.component'
+import SendContent from '../send-content/send-content.container'
import SendFooter from '../send-footer/send-footer.container'
const mockBasicGasEstimates = {
@@ -20,6 +21,7 @@ const propsMethodSpies = {
resetSendState: sinon.spy(),
fetchBasicGasEstimates: sinon.stub().returns(Promise.resolve(mockBasicGasEstimates)),
fetchGasEstimates: sinon.spy(),
+ updateToNicknameIfNecessary: sinon.spy(),
}
const utilsMethodStubs = {
getAmountErrorObject: sinon.stub().returns({ amount: 'mockAmountError' }),
@@ -63,6 +65,7 @@ describe('Send Component', function () {
updateSendErrors={propsMethodSpies.updateSendErrors}
updateSendTokenBalance={propsMethodSpies.updateSendTokenBalance}
resetSendState={propsMethodSpies.resetSendState}
+ updateToNicknameIfNecessary={propsMethodSpies.updateToNicknameIfNecessary}
/>)
})
@@ -332,13 +335,18 @@ describe('Send Component', function () {
assert.equal(wrapper.find('.page-container').length, 1)
})
- it('should render SendHeader, SendContent and SendFooter', () => {
+ it('should render SendHeader and AddRecipient', () => {
assert.equal(wrapper.find(SendHeader).length, 1)
- assert.equal(wrapper.find(SendContent).length, 1)
- assert.equal(wrapper.find(SendFooter).length, 1)
+ assert.equal(wrapper.find(AddRecipient).length, 1)
})
it('should pass the history prop to SendHeader and SendFooter', () => {
+ wrapper.setProps({
+ to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
+ })
+ assert.equal(wrapper.find(SendHeader).length, 1)
+ assert.equal(wrapper.find(SendContent).length, 1)
+ assert.equal(wrapper.find(SendFooter).length, 1)
assert.deepEqual(
wrapper.find(SendFooter).props(),
{
@@ -348,7 +356,93 @@ describe('Send Component', function () {
})
it('should pass showHexData to SendContent', () => {
+ wrapper.setProps({
+ to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
+ })
assert.equal(wrapper.find(SendContent).props().showHexData, true)
})
})
+
+ describe('validate when input change', () => {
+ let clock
+
+ beforeEach(() => {
+ clock = sinon.useFakeTimers()
+ })
+
+ afterEach(() => {
+ clock.restore()
+ })
+
+ it('should validate when input changes', () => {
+ const instance = wrapper.instance()
+ instance.onRecipientInputChange('0x80F061544cC398520615B5d3e7A3BedD70cd4510')
+
+ assert.deepEqual(instance.state, {
+ query: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
+ toError: null,
+ toWarning: null,
+ })
+ })
+
+ it('should validate when input changes and has error', () => {
+ const instance = wrapper.instance()
+ instance.onRecipientInputChange('0x80F061544cC398520615B5d3e7a3BedD70cd4510')
+
+ clock.tick(1001)
+ assert.deepEqual(instance.state, {
+ query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
+ toError: 'invalidAddressRecipient',
+ toWarning: null,
+ })
+ })
+
+ it('should validate when input changes and has error', () => {
+ wrapper.setProps({ network: 'bad' })
+ const instance = wrapper.instance()
+ instance.onRecipientInputChange('0x80F061544cC398520615B5d3e7a3BedD70cd4510')
+
+ clock.tick(1001)
+ assert.deepEqual(instance.state, {
+ query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
+ toError: 'invalidAddressRecipientNotEthNetwork',
+ toWarning: null,
+ })
+ })
+
+ it('should synchronously validate when input changes to ""', () => {
+ wrapper.setProps({ network: 'bad' })
+ const instance = wrapper.instance()
+ instance.onRecipientInputChange('0x80F061544cC398520615B5d3e7a3BedD70cd4510')
+
+ clock.tick(1001)
+ assert.deepEqual(instance.state, {
+ query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
+ toError: 'invalidAddressRecipientNotEthNetwork',
+ toWarning: null,
+ })
+
+ instance.onRecipientInputChange('')
+ assert.deepEqual(instance.state, {
+ query: '',
+ toError: '',
+ toWarning: '',
+ })
+ })
+
+ it('should warn when send to a known token contract address', () => {
+ wrapper.setProps({
+ selectedToken: '0x888',
+ })
+ const instance = wrapper.instance()
+ instance.onRecipientInputChange('0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64')
+
+ clock.tick(1001)
+ assert.deepEqual(instance.state, {
+ query: '0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
+ toError: null,
+ toWarning: 'knownAddressRecipient',
+ })
+ })
+ })
})