mirror of https://github.com/trezor/trezor-wallet
commit
9875154acd
@ -1,55 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 1`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 2`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 3`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 4`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 5`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 6`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 7`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 8`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 9`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoud be the same - returns false 10`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 1`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 2`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 3`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 4`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 5`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 6`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 7`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 8`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 9`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 10`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 11`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 12`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 13`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 14`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges shoul NOT be the same - returns true 15`] = `true`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges test filter 1`] = `false`;
|
|
||||||
|
|
||||||
exports[`reducers utils observeChanges test filter 2`] = `true`;
|
|
@ -1,148 +1,135 @@
|
|||||||
import * as reducerUtils from '../index';
|
import * as utils from '../index';
|
||||||
|
|
||||||
describe('reducers utils', () => {
|
describe('reducers utils', () => {
|
||||||
it('observeChanges shoud be the same - returns false', () => {
|
it('observer changes should BE THE SAME - return false', () => {
|
||||||
const data = [
|
expect(utils.observeChanges(
|
||||||
// example of same data (false)
|
{},
|
||||||
{
|
{},
|
||||||
previous: {},
|
)).toBe(false);
|
||||||
current: {},
|
|
||||||
},
|
expect(utils.observeChanges(
|
||||||
{
|
[],
|
||||||
previous: 1,
|
[],
|
||||||
current: 1,
|
)).toBe(false);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: [],
|
[1, 1, 1],
|
||||||
current: [],
|
[1, 1, 1],
|
||||||
},
|
)).toBe(false);
|
||||||
{
|
|
||||||
previous: [1, 1, 1],
|
expect(utils.observeChanges(
|
||||||
current: [1, 1, 1],
|
'a',
|
||||||
},
|
'a',
|
||||||
{
|
)).toBe(false);
|
||||||
previous: 'a',
|
|
||||||
current: 'a',
|
expect(utils.observeChanges(
|
||||||
},
|
{ one: 1 },
|
||||||
{
|
{ one: 1 },
|
||||||
previous: { one: 1 },
|
)).toBe(false);
|
||||||
current: { one: 1 },
|
|
||||||
},
|
expect(utils.observeChanges(
|
||||||
{
|
{ one: { two: 1 } },
|
||||||
previous: { one: { two: 1 } },
|
{ one: { two: 1 } },
|
||||||
current: { one: { two: 1 } },
|
)).toBe(false);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: { one: { two: [1, 2, 3] } },
|
{ one: { two: [1, 2, 3] } },
|
||||||
current: { one: { two: [1, 2, 3] } },
|
{ one: { two: [1, 2, 3] } },
|
||||||
},
|
)).toBe(false);
|
||||||
{
|
|
||||||
previous: { one: { two: [1, { three: 1 }, 3] } },
|
expect(utils.observeChanges(
|
||||||
current: { one: { two: [1, { three: 1 }, 3] } },
|
{ one: { two: [1, { three: 1 }, 3] } },
|
||||||
},
|
{ one: { two: [1, { three: 1 }, 3] } },
|
||||||
{
|
)).toBe(false);
|
||||||
previous: { one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
|
||||||
current: { one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
expect(utils.observeChanges(
|
||||||
},
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
||||||
];
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
||||||
|
)).toBe(false);
|
||||||
data.forEach((item) => {
|
|
||||||
expect(reducerUtils.observeChanges(
|
|
||||||
item.previous, item.current,
|
|
||||||
)).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('observeChanges shoul NOT be the same - returns true', () => {
|
it('observer should NOT be the same - return true', () => {
|
||||||
const data = [
|
expect(utils.observeChanges(
|
||||||
// example of different data (true)
|
null,
|
||||||
{
|
{},
|
||||||
previous: null,
|
)).toBe(true);
|
||||||
current: {},
|
|
||||||
},
|
expect(utils.observeChanges(
|
||||||
{
|
{ one: 1 },
|
||||||
previous: { one: 1 },
|
{},
|
||||||
current: {},
|
)).toBe(true);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: { one: 1, three: 3 },
|
{ one: 1, three: 3 }, { one: 1, two: 2 },
|
||||||
current: { one: 1, two: 2 },
|
)).toBe(true);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: [{}, {}],
|
[{}, {}],
|
||||||
current: [],
|
[],
|
||||||
},
|
)).toBe(true);
|
||||||
{
|
|
||||||
previous: [1, 1, 1],
|
expect(utils.observeChanges(
|
||||||
current: [1, 1],
|
[1, 1, 1],
|
||||||
},
|
[1, 1],
|
||||||
{
|
)).toBe(true);
|
||||||
previous: 'a',
|
|
||||||
current: 'b',
|
expect(utils.observeChanges(
|
||||||
},
|
'a',
|
||||||
{
|
'b',
|
||||||
previous: ['a'],
|
)).toBe(true);
|
||||||
current: ['b'],
|
|
||||||
},
|
expect(utils.observeChanges(
|
||||||
{
|
['a'],
|
||||||
previous: 1,
|
['b'],
|
||||||
current: '1',
|
)).toBe(true);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: { one: 1 },
|
1,
|
||||||
current: { one: 2 },
|
'1',
|
||||||
},
|
)).toBe(true);
|
||||||
{
|
|
||||||
previous: { one: { two: 1 } },
|
expect(utils.observeChanges(
|
||||||
current: { one: { two: 2 } },
|
{ one: 1 },
|
||||||
},
|
{ one: 2 },
|
||||||
{
|
)).toBe(true);
|
||||||
previous: { one: { two: 1 } },
|
|
||||||
current: { one: { two: 2 } },
|
expect(utils.observeChanges(
|
||||||
},
|
{ one: { two: 1 } },
|
||||||
{
|
{ one: { two: 2 } },
|
||||||
previous: { one: { two: [1, 2, 3] } },
|
)).toBe(true);
|
||||||
current: { one: { two: [1, 1, 3] } },
|
|
||||||
},
|
expect(utils.observeChanges(
|
||||||
{
|
{ one: { two: [1, 2, 3] } },
|
||||||
previous: { one: { two: [1, { three: 1 }, 3] } },
|
{ one: { two: [1, 1, 3] } },
|
||||||
current: { one: { two: [1, { three: 2 }, 3] } },
|
)).toBe(true);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: { one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
{ one: { two: [1, { three: 1 }, 3] } },
|
||||||
current: { one: { two: [1, { three: 1 }, { four: 3, five: { six: 1 } }] } },
|
{ one: { two: [1, { three: 2 }, 3] } },
|
||||||
},
|
)).toBe(true);
|
||||||
{
|
|
||||||
previous: { one: { two: [1, { three: 1 }, { four: 3, five: { sixxx: 3 } }] } },
|
expect(utils.observeChanges(
|
||||||
current: { one: { two: [1, { three: 1 }, { four: 3, five: { six: 1 } }] } },
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { six: 3 } }] } },
|
||||||
},
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { six: 1 } }] } },
|
||||||
];
|
)).toBe(true);
|
||||||
|
|
||||||
data.forEach((item) => {
|
expect(utils.observeChanges(
|
||||||
expect(reducerUtils.observeChanges(
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { sixxx: 3 } }] } },
|
||||||
item.previous, item.current,
|
{ one: { two: [1, { three: 1 }, { four: 3, five: { six: 1 } }] } },
|
||||||
)).toMatchSnapshot();
|
)).toBe(true);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('observeChanges test filter', () => {
|
it('observeChanges test filter', () => {
|
||||||
const data = [
|
expect(utils.observeChanges(
|
||||||
{
|
{ one: { two: 2, three: 3 } },
|
||||||
previous: { one: { two: 2, three: 3 } },
|
{ one: { two: 2, three: 4 } },
|
||||||
current: { one: { two: 2, three: 4 } },
|
{ one: ['two'] },
|
||||||
filter: { one: ['two'] },
|
)).toBe(false);
|
||||||
},
|
|
||||||
{
|
expect(utils.observeChanges(
|
||||||
previous: { one: { two: 2, three: 3 } },
|
{ one: { two: 2, three: 3 } },
|
||||||
current: { one: { two: 1, three: 3 } },
|
{ one: { two: 1, three: 3 } },
|
||||||
filter: { one: ['two'] },
|
{ one: ['two'] },
|
||||||
},
|
)).toBe(true);
|
||||||
];
|
|
||||||
|
|
||||||
data.forEach((item) => {
|
|
||||||
expect(reducerUtils.observeChanges(
|
|
||||||
item.previous, item.current, item.filter,
|
|
||||||
)).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
import * as utils from '../cryptoUriParser';
|
||||||
|
|
||||||
|
describe('crypto uri parser', () => {
|
||||||
|
it('parseUri', () => {
|
||||||
|
expect(utils.parseUri('http://www.trezor.io')).toEqual({ address: '//www.trezor.io' }); // TODO: Error in function
|
||||||
|
expect(utils.parseUri('www.trezor.io')).toEqual({ address: 'www.trezor.io' });
|
||||||
|
expect(utils.parseUri('www.trezor.io/TT')).toEqual({ address: 'www.trezor.io/TT' });
|
||||||
|
expect(utils.parseUri('www.trezor.io/TT?param1=aha')).toEqual({ address: 'www.trezor.io/TT', param1: 'aha' });
|
||||||
|
expect(utils.parseUri('www.trezor.io/TT?param1=aha¶m2=hah')).toEqual({ address: 'www.trezor.io/TT', param1: 'aha', param2: 'hah' });
|
||||||
|
});
|
||||||
|
});
|
@ -1,41 +1,24 @@
|
|||||||
import * as utils from '../formatUtils';
|
import * as utils from '../formatUtils';
|
||||||
|
|
||||||
describe('format utils', () => {
|
describe('format utils', () => {
|
||||||
// TODO: check this weird function
|
it('to decimal amount', () => {
|
||||||
it('formatAmount', () => {
|
expect(utils.toDecimalAmount(0, 1)).toBe('0');
|
||||||
expect(utils.formatAmount(0, { isBitcoin: false, shortcut: 'mbtc' }, 'mbtc')).toBe('0 mbtc');
|
expect(utils.toDecimalAmount(1, 1)).toBe('0.1');
|
||||||
expect(utils.formatAmount(1000000, { isBitcoin: true }, 'mbtc')).toBe('10 mBTC');
|
expect(utils.toDecimalAmount(1000, 1)).toBe('100');
|
||||||
expect(utils.formatAmount(0.5, { isBitcoin: true }, 'mbtc')).toBe('0.000005 mBTC');
|
expect(utils.toDecimalAmount(1000, 2)).toBe('10');
|
||||||
expect(utils.formatAmount(1, { isBitcoin: false, shortcut: 'eth' }, null)).toBe('1e-8 eth');
|
expect(utils.toDecimalAmount(1000, 3)).toBe('1');
|
||||||
expect(utils.formatAmount(99999, { isBitcoin: false, shortcut: 'tau' }, null)).toBe('0.00099999 tau');
|
expect(utils.toDecimalAmount('1', 'a')).toBe('NaN');
|
||||||
|
expect(utils.toDecimalAmount('a', 'a')).toBe('0');
|
||||||
|
expect(utils.toDecimalAmount('a', '1')).toBe('0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('format time', () => {
|
it('from decimal amount', () => {
|
||||||
expect(utils.formatTime(0)).toBe('No time estimate');
|
expect(utils.fromDecimalAmount(0, 1)).toBe('0');
|
||||||
expect(utils.formatTime(1)).toBe('1 minutes'); // TODO: should be minute
|
expect(utils.fromDecimalAmount(10, 1)).toBe('100');
|
||||||
expect(utils.formatTime(2)).toBe('2 minutes');
|
expect(utils.fromDecimalAmount(10, 2)).toBe('1000');
|
||||||
expect(utils.formatTime(45)).toBe('45 minutes');
|
expect(utils.fromDecimalAmount(10, 3)).toBe('10000');
|
||||||
expect(utils.formatTime(100)).toBe('1 hour 40 minutes');
|
expect(utils.fromDecimalAmount('1', 'a')).toBe('NaN');
|
||||||
expect(utils.formatTime(999)).toBe('16 hours 39 minutes');
|
expect(utils.fromDecimalAmount('a', 'a')).toBe('0');
|
||||||
});
|
expect(utils.fromDecimalAmount('a', '1')).toBe('0');
|
||||||
|
|
||||||
it('btckb2satoshib', () => {
|
|
||||||
expect(utils.btckb2satoshib(0)).toBe(0);
|
|
||||||
expect(utils.btckb2satoshib(1)).toBe(100000);
|
|
||||||
expect(utils.btckb2satoshib(2)).toBe(200000);
|
|
||||||
expect(utils.btckb2satoshib(100)).toBe(10000000);
|
|
||||||
expect(utils.btckb2satoshib(999)).toBe(99900000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('string to hex', () => {
|
|
||||||
expect(utils.stringToHex('test')).toBe('0074006500730074');
|
|
||||||
expect(utils.stringToHex('0001')).toBe('0030003000300031');
|
|
||||||
expect(utils.stringToHex('test99999')).toBe('007400650073007400390039003900390039');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('hex to string', () => {
|
|
||||||
expect(utils.hexToString('0074006500730074')).toBe('test');
|
|
||||||
expect(utils.hexToString('0030003000300031')).toBe('0001');
|
|
||||||
expect(utils.hexToString('007400650073007400390039003900390039')).toBe('test99999');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
import * as utils from 'utils/notification';
|
import * as utils from 'utils/notification';
|
||||||
|
import colors from 'config/colors';
|
||||||
|
import icons from 'config/icons';
|
||||||
|
|
||||||
describe('notification utils', () => {
|
describe('notification utils', () => {
|
||||||
it('get colors from status', () => {
|
it('get primary color from status', () => {
|
||||||
expect(utils.getPrimaryColor('info')).toBe('#1E7FF0');
|
expect(utils.getPrimaryColor('info')).toBe(colors.INFO_PRIMARY);
|
||||||
expect(utils.getPrimaryColor('warning')).toBe('#EB8A00');
|
expect(utils.getPrimaryColor('warning')).toBe(colors.WARNING_PRIMARY);
|
||||||
expect(utils.getPrimaryColor('error')).toBe('#ED1212');
|
expect(utils.getPrimaryColor('error')).toBe(colors.ERROR_PRIMARY);
|
||||||
expect(utils.getPrimaryColor('success')).toBe('#01B757');
|
expect(utils.getPrimaryColor('success')).toBe(colors.SUCCESS_PRIMARY);
|
||||||
expect(utils.getPrimaryColor('kdsjflds')).toBe(null);
|
expect(utils.getPrimaryColor('kdsjflds')).toBe(null);
|
||||||
expect(utils.getPrimaryColor('')).toBe(null);
|
expect(utils.getPrimaryColor('')).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get secondary color from status', () => {
|
||||||
|
expect(utils.getSecondaryColor('info')).toBe(colors.INFO_SECONDARY);
|
||||||
|
expect(utils.getSecondaryColor('warning')).toBe(colors.WARNING_SECONDARY);
|
||||||
|
expect(utils.getSecondaryColor('error')).toBe(colors.ERROR_SECONDARY);
|
||||||
|
expect(utils.getSecondaryColor('success')).toBe(colors.SUCCESS_SECONDARY);
|
||||||
|
expect(utils.getSecondaryColor('kdsjflds')).toBe(null);
|
||||||
|
expect(utils.getSecondaryColor('')).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get icon according to status', () => {
|
||||||
|
expect(utils.getIcon('info')).toEqual(icons.INFO);
|
||||||
|
expect(utils.getIcon('error')).toEqual(icons.ERROR);
|
||||||
|
expect(utils.getIcon('success')).toEqual(icons.SUCCESS);
|
||||||
|
expect(utils.getIcon('warning')).toEqual(icons.WARNING);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in new issue