2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
|
2020-03-06 22:34:56 +01:00
|
|
|
import {
|
2018-05-22 17:16:53 +02:00
|
|
|
getBlockGasLimit,
|
2018-05-05 17:11:53 +02:00
|
|
|
getConversionRate,
|
2018-10-26 10:26:43 +02:00
|
|
|
getNativeCurrency,
|
2018-05-05 17:11:53 +02:00
|
|
|
getGasLimit,
|
|
|
|
getGasPrice,
|
|
|
|
getGasTotal,
|
|
|
|
getPrimaryCurrency,
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken,
|
|
|
|
getSendTokenContract,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendAmount,
|
2020-05-04 17:22:34 +02:00
|
|
|
sendAmountIsInError,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendEditingTransactionId,
|
|
|
|
getSendErrors,
|
|
|
|
getSendFrom,
|
|
|
|
getSendFromBalance,
|
|
|
|
getSendFromObject,
|
2018-08-16 09:43:13 +02:00
|
|
|
getSendHexDataFeatureFlagState,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendMaxModeState,
|
|
|
|
getSendTo,
|
|
|
|
getSendToAccounts,
|
|
|
|
getTokenBalance,
|
|
|
|
getUnapprovedTxs,
|
2020-05-04 17:22:34 +02:00
|
|
|
gasFeeIsInError,
|
|
|
|
getGasLoadingError,
|
|
|
|
getGasButtonGroupShown,
|
|
|
|
getTitleKey,
|
|
|
|
isSendFormInError,
|
2021-03-16 22:00:08 +01:00
|
|
|
} from './send';
|
2021-02-04 19:15:23 +01:00
|
|
|
import mockState from './send-selectors-test-data';
|
2021-03-16 22:00:08 +01:00
|
|
|
import {
|
|
|
|
accountsWithSendEtherInfoSelector,
|
|
|
|
getCurrentAccountWithSendEtherInfo,
|
|
|
|
} from '.';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send selectors', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const tempGlobalEth = { ...global.eth };
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2018-05-14 14:13:55 +02:00
|
|
|
global.eth = {
|
|
|
|
contract: sinon.stub().returns({
|
2020-08-19 18:27:05 +02:00
|
|
|
at: (address) => `mockAt:${address}`,
|
2018-05-14 14:57:36 +02:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
});
|
2018-05-14 14:13:55 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
global.eth = tempGlobalEth;
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('accountsWithSendEtherInfoSelector()', () => {
|
|
|
|
it('should return an array of account objects with name info from identities', () => {
|
|
|
|
expect(accountsWithSendEtherInfoSelector(mockState)).toStrictEqual([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
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: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getBlockGasLimit', () => {
|
|
|
|
it('should return the current block gas limit', () => {
|
|
|
|
expect(getBlockGasLimit(mockState)).toStrictEqual('0x4c1878');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-22 17:16:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getConversionRate()', () => {
|
|
|
|
it('should return the eth conversion rate', () => {
|
|
|
|
expect(getConversionRate(mockState)).toStrictEqual(1200.88200327);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getCurrentAccountWithSendEtherInfo()', () => {
|
|
|
|
it('should return the currently selected account with identity info', () => {
|
|
|
|
expect(getCurrentAccountWithSendEtherInfo(mockState)).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getNativeCurrency()', () => {
|
|
|
|
it('should return the ticker symbol of the selected network', () => {
|
|
|
|
expect(getNativeCurrency(mockState)).toStrictEqual('ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-10-26 10:26:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getGasLimit()', () => {
|
|
|
|
it('should return the send.gasLimit', () => {
|
|
|
|
expect(getGasLimit(mockState)).toStrictEqual('0xFFFF');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getGasPrice()', () => {
|
|
|
|
it('should return the send.gasPrice', () => {
|
|
|
|
expect(getGasPrice(mockState)).toStrictEqual('0xaa');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getGasTotal()', () => {
|
|
|
|
it('should return the send.gasTotal', () => {
|
|
|
|
expect(getGasTotal(mockState)).toStrictEqual('a9ff56');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getPrimaryCurrency()', () => {
|
|
|
|
it('should return the symbol of the send token', () => {
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
getPrimaryCurrency({
|
|
|
|
metamask: { send: { token: { symbol: 'DEF' } } },
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('DEF');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendToken()', () => {
|
|
|
|
it('should return the current send token if set', () => {
|
|
|
|
expect(
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken({
|
|
|
|
metamask: {
|
|
|
|
send: {
|
|
|
|
token: {
|
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendTokenContract()', () => {
|
|
|
|
it('should return the contract at the send token address', () => {
|
|
|
|
expect(
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendTokenContract({
|
|
|
|
metamask: {
|
|
|
|
send: {
|
|
|
|
token: {
|
|
|
|
address: '0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
decimals: 4,
|
|
|
|
symbol: 'DEF',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('mockAt:0x8d6b81208414189a58339873ab429b6c47ab92d3');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return null if send token is not set', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const modifiedMetamaskState = { ...mockState.metamask, send: {} };
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-08-19 18:27:05 +02:00
|
|
|
getSendTokenContract({ ...mockState, metamask: modifiedMetamaskState }),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toBeNull();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendAmount()', () => {
|
|
|
|
it('should return the send.amount', () => {
|
|
|
|
expect(getSendAmount(mockState)).toStrictEqual('0x080');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendEditingTransactionId()', () => {
|
|
|
|
it('should return the send.editingTransactionId', () => {
|
|
|
|
expect(getSendEditingTransactionId(mockState)).toStrictEqual(97531);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendErrors()', () => {
|
|
|
|
it('should return the send.errors', () => {
|
|
|
|
expect(getSendErrors(mockState)).toStrictEqual({ someError: null });
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-08-16 09:43:13 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendHexDataFeatureFlagState()', () => {
|
|
|
|
it('should return the sendHexData feature flag state', () => {
|
|
|
|
expect(getSendHexDataFeatureFlagState(mockState)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendFrom()', () => {
|
|
|
|
it('should return the send.from', () => {
|
|
|
|
expect(getSendFrom(mockState)).toStrictEqual(
|
2020-03-11 19:40:35 +01:00
|
|
|
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendFromBalance()', () => {
|
|
|
|
it('should get the send.from balance if it exists', () => {
|
|
|
|
expect(getSendFromBalance(mockState)).toStrictEqual('0x37452b1315889f80');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should get the selected account balance if the send.from does not exist', () => {
|
2018-05-05 17:11:53 +02:00
|
|
|
const editedMockState = {
|
2020-08-19 18:27:05 +02:00
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
2018-05-05 17:11:53 +02:00
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getSendFromBalance(editedMockState)).toStrictEqual('0x0');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendFromObject()', () => {
|
|
|
|
it('should return send.from if it exists', () => {
|
|
|
|
expect(getSendFromObject(mockState)).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
balance: '0x37452b1315889f80',
|
|
|
|
code: '0x',
|
|
|
|
nonce: '0xa',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the current account if send.from does not exist', () => {
|
2018-05-05 17:11:53 +02:00
|
|
|
const editedMockState = {
|
2020-08-19 18:27:05 +02:00
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
2018-05-05 17:11:53 +02:00
|
|
|
send: {
|
|
|
|
from: null,
|
|
|
|
},
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getSendFromObject(editedMockState)).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendMaxModeState()', () => {
|
|
|
|
it('should return send.maxModeOn', () => {
|
|
|
|
expect(getSendMaxModeState(mockState)).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendTo()', () => {
|
|
|
|
it('should return send.to', () => {
|
|
|
|
expect(getSendTo(mockState)).toStrictEqual('0x987fedabc');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getSendToAccounts()', () => {
|
|
|
|
it('should return an array including all the users accounts and the address book', () => {
|
|
|
|
expect(getSendToAccounts(mockState)).toStrictEqual([
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
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: '0x30c9d71831c76efe',
|
|
|
|
nonce: '0x1c',
|
|
|
|
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
|
|
|
|
name: 'Send Account 3',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: '0x',
|
|
|
|
balance: '0x0',
|
|
|
|
nonce: '0x0',
|
|
|
|
address: '0xd85a4b6a394794842887b8284293d69163007bbb',
|
|
|
|
name: 'Send Account 4',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
|
|
|
|
name: 'Address Book Account 1',
|
|
|
|
chainId: '0x3',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getTokenBalance()', () => {
|
|
|
|
it('should', () => {
|
|
|
|
expect(getTokenBalance(mockState)).toStrictEqual(3434);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getUnapprovedTxs()', () => {
|
|
|
|
it('should return the unapproved txs', () => {
|
|
|
|
expect(getUnapprovedTxs(mockState)).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
4768706228115573: {
|
|
|
|
id: 4768706228115573,
|
|
|
|
time: 1487363153561,
|
2020-11-07 08:38:12 +01:00
|
|
|
status: TRANSACTION_STATUSES.UNAPPROVED,
|
2020-11-03 00:41:28 +01:00
|
|
|
gasMultiplier: 1,
|
|
|
|
metamaskNetworkId: '3',
|
|
|
|
txParams: {
|
|
|
|
from: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
|
|
|
to: '0x18a3462427bcc9133bb46e88bcbe39cd7ef0e761',
|
|
|
|
value: '0xde0b6b3a7640000',
|
|
|
|
metamaskId: 4768706228115573,
|
2018-05-14 14:13:55 +02:00
|
|
|
metamaskNetworkId: '3',
|
2020-11-03 00:41:28 +01:00
|
|
|
gas: '0x5209',
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
txFee: '17e0186e60800',
|
|
|
|
txValue: 'de0b6b3a7640000',
|
|
|
|
maxCost: 'de234b52e4a0800',
|
|
|
|
gasPrice: '4a817c800',
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send-amount-row selectors', () => {
|
|
|
|
describe('sendAmountIsInError()', () => {
|
|
|
|
it('should return true if send.errors.amount is truthy', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
amount: 'abc',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(sendAmountIsInError(state)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false if send.errors.amount is falsy', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
amount: null,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(sendAmountIsInError(state)).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send-gas-row selectors', () => {
|
|
|
|
describe('getGasLoadingError()', () => {
|
|
|
|
it('should return send.errors.gasLoading', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasLoading: 'abc',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getGasLoadingError(state)).toStrictEqual('abc');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('gasFeeIsInError()', () => {
|
|
|
|
it('should return true if send.errors.gasFee is truthy', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: 'def',
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(gasFeeIsInError(state)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false send.errors.gasFee is falsely', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
gasFee: null,
|
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(gasFeeIsInError(state)).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getGasButtonGroupShown()', () => {
|
|
|
|
it('should return send.gasButtonGroupShown', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const state = {
|
|
|
|
send: {
|
|
|
|
gasButtonGroupShown: 'foobar',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(getGasButtonGroupShown(state)).toStrictEqual('foobar');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send-header selectors', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const getMetamaskSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
metamask: {
|
|
|
|
send: { ...send },
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('getTitleKey()', () => {
|
|
|
|
it('should return the correct key when "to" is empty', () => {
|
|
|
|
expect(getTitleKey(getMetamaskSendMockState({}))).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'addRecipient',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is truthy', () => {
|
|
|
|
expect(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: true,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('edit');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is truthy', () => {
|
|
|
|
expect(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: false,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: {},
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('sendTokens');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the correct key when getSendEditingTransactionId is falsy and getSendToken is falsy', () => {
|
|
|
|
expect(
|
2020-05-04 17:22:34 +02:00
|
|
|
getTitleKey(
|
|
|
|
getMetamaskSendMockState({
|
|
|
|
to: true,
|
|
|
|
editingTransactionId: false,
|
2020-05-29 19:46:10 +02:00
|
|
|
token: null,
|
2020-07-14 17:20:41 +02:00
|
|
|
}),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('send');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send-footer selectors', () => {
|
2020-05-04 17:22:34 +02:00
|
|
|
const getSendMockState = (send) => {
|
|
|
|
return {
|
|
|
|
send: { ...send },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('isSendFormInError()', () => {
|
|
|
|
it('should return true if any of the values of the object returned by getSendErrors are truthy', () => {
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [true],
|
|
|
|
}),
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-04 17:22:34 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false if all of the values of the object returned by getSendErrors are falsy', () => {
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [],
|
|
|
|
}),
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(false);
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
isSendFormInError(
|
|
|
|
getSendMockState({
|
|
|
|
errors: [false],
|
|
|
|
}),
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|