You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
545 lines
19 KiB
545 lines
19 KiB
4 years ago
|
import assert from 'assert';
|
||
|
import React from 'react';
|
||
|
import proxyquire from 'proxyquire';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import timeout from '../../../lib/test-timeout';
|
||
4 years ago
|
|
||
4 years ago
|
import {
|
||
|
RINKEBY_CHAIN_ID,
|
||
|
ROPSTEN_CHAIN_ID,
|
||
4 years ago
|
} from '../../../../shared/constants/network';
|
||
|
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.container';
|
||
|
import SendFooter from './send-footer/send-footer.container';
|
||
7 years ago
|
|
||
5 years ago
|
describe('Send Component', function () {
|
||
4 years ago
|
let wrapper;
|
||
6 years ago
|
|
||
5 years ago
|
const mockBasicGasEstimates = {
|
||
|
blockTime: 'mockBlockTime',
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
const propsMethodSpies = {
|
||
|
updateAndSetGasLimit: sinon.spy(),
|
||
|
updateSendErrors: sinon.spy(),
|
||
|
updateSendTokenBalance: sinon.spy(),
|
||
|
resetSendState: sinon.spy(),
|
||
4 years ago
|
fetchBasicGasEstimates: sinon
|
||
|
.stub()
|
||
|
.returns(Promise.resolve(mockBasicGasEstimates)),
|
||
5 years ago
|
fetchGasEstimates: sinon.spy(),
|
||
|
updateToNicknameIfNecessary: sinon.spy(),
|
||
4 years ago
|
};
|
||
5 years ago
|
const utilsMethodStubs = {
|
||
|
getAmountErrorObject: sinon.stub().returns({ amount: 'mockAmountError' }),
|
||
|
getGasFeeErrorObject: sinon.stub().returns({ gasFee: 'mockGasFeeError' }),
|
||
4 years ago
|
doesAmountErrorRequireUpdate: sinon
|
||
|
.stub()
|
||
|
.callsFake((obj) => obj.balance !== obj.prevBalance),
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
const SendTransactionScreen = proxyquire('./send.component.js', {
|
||
5 years ago
|
'./send.utils': utilsMethodStubs,
|
||
4 years ago
|
}).default;
|
||
7 years ago
|
|
||
5 years ago
|
before(function () {
|
||
4 years ago
|
sinon.spy(SendTransactionScreen.prototype, 'componentDidMount');
|
||
|
sinon.spy(SendTransactionScreen.prototype, 'updateGas');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
beforeEach(function () {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<SendTransactionScreen
|
||
|
amount="mockAmount"
|
||
|
blockGasLimit="mockBlockGasLimit"
|
||
|
conversionRate={10}
|
||
|
editingTransactionId="mockEditingTransactionId"
|
||
|
fetchBasicGasEstimates={propsMethodSpies.fetchBasicGasEstimates}
|
||
|
fetchGasEstimates={propsMethodSpies.fetchGasEstimates}
|
||
4 years ago
|
from={{ address: 'mockAddress', balance: 'mockBalance' }}
|
||
5 years ago
|
gasLimit="mockGasLimit"
|
||
|
gasPrice="mockGasPrice"
|
||
|
gasTotal="mockGasTotal"
|
||
5 years ago
|
history={{ mockProp: 'history-abc' }}
|
||
4 years ago
|
chainId={ROPSTEN_CHAIN_ID}
|
||
5 years ago
|
primaryCurrency="mockPrimaryCurrency"
|
||
|
selectedAddress="mockSelectedAddress"
|
||
5 years ago
|
sendToken={{ address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }}
|
||
5 years ago
|
showHexData
|
||
|
tokenBalance="mockTokenBalance"
|
||
|
tokenContract={{ method: 'mockTokenMethod' }}
|
||
|
updateAndSetGasLimit={propsMethodSpies.updateAndSetGasLimit}
|
||
4 years ago
|
qrCodeDetected={() => undefined}
|
||
|
scanQrCode={() => undefined}
|
||
|
updateSendEnsResolution={() => undefined}
|
||
|
updateSendEnsResolutionError={() => undefined}
|
||
5 years ago
|
updateSendErrors={propsMethodSpies.updateSendErrors}
|
||
4 years ago
|
updateSendTo={() => undefined}
|
||
5 years ago
|
updateSendTokenBalance={propsMethodSpies.updateSendTokenBalance}
|
||
|
resetSendState={propsMethodSpies.resetSendState}
|
||
4 years ago
|
updateToNicknameIfNecessary={
|
||
|
propsMethodSpies.updateToNicknameIfNecessary
|
||
|
}
|
||
|
/>,
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
afterEach(function () {
|
||
4 years ago
|
SendTransactionScreen.prototype.componentDidMount.resetHistory();
|
||
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
utilsMethodStubs.doesAmountErrorRequireUpdate.resetHistory();
|
||
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
||
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
||
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory();
|
||
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
||
|
propsMethodSpies.updateSendErrors.resetHistory();
|
||
|
propsMethodSpies.updateSendTokenBalance.resetHistory();
|
||
|
propsMethodSpies.updateToNicknameIfNecessary.resetHistory();
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
after(function () {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should call componentDidMount', function () {
|
||
4 years ago
|
assert(SendTransactionScreen.prototype.componentDidMount.calledOnce);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('componentDidMount', function () {
|
||
|
it('should call props.fetchBasicGasAndTimeEstimates', function () {
|
||
4 years ago
|
propsMethodSpies.fetchBasicGasEstimates.resetHistory();
|
||
|
assert.strictEqual(propsMethodSpies.fetchBasicGasEstimates.callCount, 0);
|
||
|
wrapper.instance().componentDidMount();
|
||
|
assert.strictEqual(propsMethodSpies.fetchBasicGasEstimates.callCount, 1);
|
||
|
});
|
||
6 years ago
|
|
||
5 years ago
|
it('should call this.updateGas', async function () {
|
||
4 years ago
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
propsMethodSpies.updateSendErrors.resetHistory();
|
||
|
assert.strictEqual(
|
||
|
SendTransactionScreen.prototype.updateGas.callCount,
|
||
|
0,
|
||
|
);
|
||
|
wrapper.instance().componentDidMount();
|
||
|
await timeout(250);
|
||
|
assert.strictEqual(
|
||
|
SendTransactionScreen.prototype.updateGas.callCount,
|
||
|
1,
|
||
|
);
|
||
|
});
|
||
|
});
|
||
6 years ago
|
|
||
5 years ago
|
describe('componentWillUnmount', function () {
|
||
|
it('should call this.props.resetSendState', function () {
|
||
4 years ago
|
propsMethodSpies.resetSendState.resetHistory();
|
||
|
assert.strictEqual(propsMethodSpies.resetSendState.callCount, 0);
|
||
|
wrapper.instance().componentWillUnmount();
|
||
|
assert.strictEqual(propsMethodSpies.resetSendState.callCount, 1);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('componentDidUpdate', function () {
|
||
|
it('should call doesAmountErrorRequireUpdate with the expected params', function () {
|
||
4 years ago
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: '',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert(utilsMethodStubs.doesAmountErrorRequireUpdate.calledTwice);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
utilsMethodStubs.doesAmountErrorRequireUpdate.getCall(0).args[0],
|
||
|
{
|
||
|
balance: 'mockBalance',
|
||
|
gasTotal: 'mockGasTotal',
|
||
|
prevBalance: '',
|
||
|
prevGasTotal: undefined,
|
||
|
prevTokenBalance: undefined,
|
||
4 years ago
|
sendToken: {
|
||
|
address: 'mockTokenAddress',
|
||
|
decimals: 18,
|
||
|
symbol: 'TST',
|
||
|
},
|
||
7 years ago
|
tokenBalance: 'mockTokenBalance',
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should not call getAmountErrorObject if doesAmountErrorRequireUpdate returns false', function () {
|
||
4 years ago
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'mockBalance',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(utilsMethodStubs.getAmountErrorObject.callCount, 0);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call getAmountErrorObject if doesAmountErrorRequireUpdate returns true', function () {
|
||
4 years ago
|
utilsMethodStubs.getAmountErrorObject.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(utilsMethodStubs.getAmountErrorObject.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
utilsMethodStubs.getAmountErrorObject.getCall(0).args[0],
|
||
|
{
|
||
|
amount: 'mockAmount',
|
||
|
balance: 'mockBalance',
|
||
|
conversionRate: 10,
|
||
|
gasTotal: 'mockGasTotal',
|
||
|
primaryCurrency: 'mockPrimaryCurrency',
|
||
4 years ago
|
sendToken: {
|
||
|
address: 'mockTokenAddress',
|
||
|
decimals: 18,
|
||
|
symbol: 'TST',
|
||
|
},
|
||
7 years ago
|
tokenBalance: 'mockTokenBalance',
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns true and sendToken is truthy', function () {
|
||
4 years ago
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
utilsMethodStubs.getGasFeeErrorObject.getCall(0).args[0],
|
||
|
{
|
||
|
balance: 'mockBalance',
|
||
|
conversionRate: 10,
|
||
|
gasTotal: 'mockGasTotal',
|
||
|
primaryCurrency: 'mockPrimaryCurrency',
|
||
4 years ago
|
sendToken: {
|
||
|
address: 'mockTokenAddress',
|
||
|
decimals: 18,
|
||
|
symbol: 'TST',
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should not call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns false', function () {
|
||
4 years ago
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: { address: 'mockAddress', balance: 'mockBalance' },
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 0);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should not call getGasFeeErrorObject if doesAmountErrorRequireUpdate returns true but sendToken is falsy', function () {
|
||
4 years ago
|
utilsMethodStubs.getGasFeeErrorObject.resetHistory();
|
||
|
wrapper.setProps({ sendToken: null });
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(utilsMethodStubs.getGasFeeErrorObject.callCount, 0);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call updateSendErrors with the expected params if sendToken is falsy', function () {
|
||
4 years ago
|
propsMethodSpies.updateSendErrors.resetHistory();
|
||
|
wrapper.setProps({ sendToken: null });
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(propsMethodSpies.updateSendErrors.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
propsMethodSpies.updateSendErrors.getCall(0).args[0],
|
||
|
{
|
||
|
amount: 'mockAmountError',
|
||
|
gasFee: null,
|
||
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call updateSendErrors with the expected params if sendToken is truthy', function () {
|
||
4 years ago
|
propsMethodSpies.updateSendErrors.resetHistory();
|
||
4 years ago
|
wrapper.setProps({
|
||
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' },
|
||
4 years ago
|
});
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(propsMethodSpies.updateSendErrors.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
propsMethodSpies.updateSendErrors.getCall(0).args[0],
|
||
|
{
|
||
|
amount: 'mockAmountError',
|
||
|
gasFee: 'mockGasFeeError',
|
||
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should not call updateSendTokenBalance or this.updateGas if network === prevNetwork', function () {
|
||
4 years ago
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
propsMethodSpies.updateSendTokenBalance.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
chainId: ROPSTEN_CHAIN_ID,
|
||
5 years ago
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 0);
|
||
|
assert.strictEqual(
|
||
|
SendTransactionScreen.prototype.updateGas.callCount,
|
||
|
0,
|
||
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should not call updateSendTokenBalance or this.updateGas if network === loading', function () {
|
||
4 years ago
|
wrapper.setProps({ chainId: undefined });
|
||
4 years ago
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
propsMethodSpies.updateSendTokenBalance.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
chainId: ROPSTEN_CHAIN_ID,
|
||
5 years ago
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 0);
|
||
|
assert.strictEqual(
|
||
|
SendTransactionScreen.prototype.updateGas.callCount,
|
||
|
0,
|
||
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call updateSendTokenBalance and this.updateGas with the correct params', function () {
|
||
4 years ago
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
propsMethodSpies.updateSendTokenBalance.resetHistory();
|
||
7 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balanceChanged',
|
||
|
},
|
||
4 years ago
|
chainId: RINKEBY_CHAIN_ID,
|
||
5 years ago
|
sendToken: { address: 'mockTokenAddress', decimals: 18, symbol: 'TST' }, // Make sure not to hit updateGas when changing asset
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(propsMethodSpies.updateSendTokenBalance.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
propsMethodSpies.updateSendTokenBalance.getCall(0).args[0],
|
||
|
{
|
||
4 years ago
|
sendToken: {
|
||
|
address: 'mockTokenAddress',
|
||
|
decimals: 18,
|
||
|
symbol: 'TST',
|
||
|
}, // Make sure not to hit updateGas when changing asset
|
||
5 years ago
|
tokenContract: { method: 'mockTokenMethod' },
|
||
7 years ago
|
address: 'mockAddress',
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
assert.strictEqual(
|
||
|
SendTransactionScreen.prototype.updateGas.callCount,
|
||
|
1,
|
||
|
);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
SendTransactionScreen.prototype.updateGas.getCall(0).args,
|
||
4 years ago
|
[],
|
||
4 years ago
|
);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should call updateGas when sendToken.address is changed', function () {
|
||
4 years ago
|
SendTransactionScreen.prototype.updateGas.resetHistory();
|
||
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
||
5 years ago
|
wrapper.instance().componentDidUpdate({
|
||
|
from: {
|
||
|
balance: 'balancedChanged',
|
||
|
},
|
||
4 years ago
|
chainId: ROPSTEN_CHAIN_ID, // Make sure not to hit updateGas when changing network
|
||
5 years ago
|
sendToken: { address: 'newSelectedToken' },
|
||
4 years ago
|
});
|
||
4 years ago
|
assert.strictEqual(
|
||
|
propsMethodSpies.updateToNicknameIfNecessary.callCount,
|
||
|
0,
|
||
4 years ago
|
); // Network did not change
|
||
|
assert.strictEqual(propsMethodSpies.updateAndSetGasLimit.callCount, 1);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('updateGas', function () {
|
||
|
it('should call updateAndSetGasLimit with the correct params if no to prop is passed', function () {
|
||
4 years ago
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
||
|
wrapper.instance().updateGas();
|
||
|
assert.strictEqual(propsMethodSpies.updateAndSetGasLimit.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
6 years ago
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0],
|
||
7 years ago
|
{
|
||
7 years ago
|
blockGasLimit: 'mockBlockGasLimit',
|
||
7 years ago
|
editingTransactionId: 'mockEditingTransactionId',
|
||
|
gasLimit: 'mockGasLimit',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
selectedAddress: 'mockSelectedAddress',
|
||
4 years ago
|
sendToken: {
|
||
|
address: 'mockTokenAddress',
|
||
|
decimals: 18,
|
||
|
symbol: 'TST',
|
||
|
},
|
||
7 years ago
|
to: '',
|
||
7 years ago
|
value: 'mockAmount',
|
||
6 years ago
|
data: undefined,
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call updateAndSetGasLimit with the correct params if a to prop is passed', function () {
|
||
4 years ago
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
||
|
wrapper.setProps({ to: 'someAddress' });
|
||
|
wrapper.instance().updateGas();
|
||
4 years ago
|
assert.strictEqual(
|
||
6 years ago
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
||
7 years ago
|
'someaddress',
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call updateAndSetGasLimit with to set to lowercase if passed', function () {
|
||
4 years ago
|
propsMethodSpies.updateAndSetGasLimit.resetHistory();
|
||
|
wrapper.instance().updateGas({ to: '0xABC' });
|
||
4 years ago
|
assert.strictEqual(
|
||
4 years ago
|
propsMethodSpies.updateAndSetGasLimit.getCall(0).args[0].to,
|
||
|
'0xabc',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('render', function () {
|
||
|
it('should render a page-container class', function () {
|
||
4 years ago
|
assert.strictEqual(wrapper.find('.page-container').length, 1);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should render SendHeader and AddRecipient', function () {
|
||
4 years ago
|
assert.strictEqual(wrapper.find(SendHeader).length, 1);
|
||
|
assert.strictEqual(wrapper.find(AddRecipient).length, 1);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should pass the history prop to SendHeader and SendFooter', function () {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(wrapper.find(SendHeader).length, 1);
|
||
|
assert.strictEqual(wrapper.find(SendContent).length, 1);
|
||
|
assert.strictEqual(wrapper.find(SendFooter).length, 1);
|
||
4 years ago
|
assert.deepStrictEqual(wrapper.find(SendFooter).props(), {
|
||
4 years ago
|
history: { mockProp: 'history-abc' },
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
5 years ago
|
it('should pass showHexData to SendContent', function () {
|
||
5 years ago
|
wrapper.setProps({
|
||
|
to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(wrapper.find(SendContent).props().showHexData, true);
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
describe('validate when input change', function () {
|
||
4 years ago
|
let clock;
|
||
5 years ago
|
|
||
5 years ago
|
beforeEach(function () {
|
||
4 years ago
|
clock = sinon.useFakeTimers();
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
afterEach(function () {
|
||
4 years ago
|
clock.restore();
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should validate when input changes', function () {
|
||
4 years ago
|
const instance = wrapper.instance();
|
||
4 years ago
|
instance.onRecipientInputChange(
|
||
|
'0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
|
||
|
toError: null,
|
||
|
toWarning: null,
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should validate when input changes and has error', function () {
|
||
4 years ago
|
const instance = wrapper.instance();
|
||
4 years ago
|
instance.onRecipientInputChange(
|
||
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
clock.tick(1001);
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
|
toError: 'invalidAddressRecipient',
|
||
|
toWarning: null,
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should validate when input changes and has error on a bad network', function () {
|
||
4 years ago
|
wrapper.setProps({ chainId: 'bad' });
|
||
4 years ago
|
const instance = wrapper.instance();
|
||
4 years ago
|
instance.onRecipientInputChange(
|
||
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
clock.tick(1001);
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
|
toError: 'invalidAddressRecipientNotEthNetwork',
|
||
|
toWarning: null,
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should synchronously validate when input changes to ""', function () {
|
||
4 years ago
|
wrapper.setProps({ chainId: 'bad' });
|
||
4 years ago
|
const instance = wrapper.instance();
|
||
4 years ago
|
instance.onRecipientInputChange(
|
||
|
'0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
clock.tick(1001);
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '0x80F061544cC398520615B5d3e7a3BedD70cd4510',
|
||
|
toError: 'invalidAddressRecipientNotEthNetwork',
|
||
|
toWarning: null,
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
instance.onRecipientInputChange('');
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '',
|
||
|
toError: '',
|
||
|
toWarning: '',
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should warn when send to a known token contract address', function () {
|
||
4 years ago
|
wrapper.setProps({ address: '0x888', decimals: 18, symbol: '888' });
|
||
|
const instance = wrapper.instance();
|
||
4 years ago
|
instance.onRecipientInputChange(
|
||
|
'0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
clock.tick(1001);
|
||
4 years ago
|
assert.deepStrictEqual(instance.state, {
|
||
4 years ago
|
internalSearch: false,
|
||
5 years ago
|
query: '0x13cb85823f78Cff38f0B0E90D3e975b8CB3AAd64',
|
||
|
toError: null,
|
||
|
toWarning: 'knownAddressRecipient',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|