2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import * as selectors from '../selectors';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-05-05 16:05:16 +02:00
|
|
|
describe('Selectors', function () {
|
|
|
|
describe('#getSelectedAddress', function () {
|
|
|
|
it('returns undefined if selectedAddress is undefined', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
selectors.getSelectedAddress({ metamask: {} }),
|
|
|
|
undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('returns selectedAddress', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
selectors.getSelectedAddress({ metamask: { selectedAddress } }),
|
|
|
|
selectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('returns selected identity', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(selectors.getSelectedIdentity(mockState), {
|
2020-11-03 00:41:28 +01:00
|
|
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
|
|
|
name: 'Test Account',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('returns selected account', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const account = selectors.getSelectedAccount(mockState);
|
|
|
|
assert.strictEqual(account.balance, '0x0');
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
account.address,
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
2020-05-29 00:08:11 +02:00
|
|
|
describe('#getTokenExchangeRates', function () {
|
|
|
|
it('returns token exchange rates', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const tokenExchangeRates = selectors.getTokenExchangeRates(mockState);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(tokenExchangeRates, {
|
2020-05-29 00:08:11 +02:00
|
|
|
'0x108cf70c7d384c552f42c07c41c0e1e46d77ea0d': 0.00039345803819379796,
|
|
|
|
'0xd8f6a2ffb0fc5952d16c9768b71cfd35b6399aa5': 0.00008189274407698049,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
describe('#getAddressBook', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return the address book', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(selectors.getAddressBook(mockState), [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
|
|
|
address: '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
|
|
|
|
chainId: '0x4',
|
|
|
|
isEns: false,
|
|
|
|
memo: '',
|
|
|
|
name: 'Address Book Account 1',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('returns accounts with balance, address, and name from identity and accounts in state', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const accountsWithSendEther = selectors.accountsWithSendEtherInfoSelector(
|
|
|
|
mockState,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(accountsWithSendEther.length, 2);
|
|
|
|
assert.strictEqual(accountsWithSendEther[0].balance, '0x0');
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
accountsWithSendEther[0].address,
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(accountsWithSendEther[0].name, 'Test Account');
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('returns selected account with balance, address, and name from accountsWithSendEtherInfoSelector', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const currentAccountwithSendEther = selectors.getCurrentAccountWithSendEtherInfo(
|
|
|
|
mockState,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(currentAccountwithSendEther.balance, '0x0');
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
currentAccountwithSendEther.address,
|
|
|
|
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(currentAccountwithSendEther.name, 'Test Account');
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('#getGasIsLoading', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const gasIsLoading = selectors.getGasIsLoading(mockState);
|
|
|
|
assert.strictEqual(gasIsLoading, false);
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('#getCurrentCurrency', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const currentCurrency = selectors.getCurrentCurrency(mockState);
|
|
|
|
assert.strictEqual(currentCurrency, 'usd');
|
|
|
|
});
|
2020-05-05 16:05:16 +02:00
|
|
|
|
|
|
|
it('#getTotalUnapprovedCount', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const totalUnapprovedCount = selectors.getTotalUnapprovedCount(mockState);
|
|
|
|
assert.strictEqual(totalUnapprovedCount, 1);
|
|
|
|
});
|
|
|
|
});
|