From ced81e550350490efe31b37e325b6b8240978a99 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Mon, 25 Feb 2019 15:05:01 +0100 Subject: [PATCH] Format utils tests refactored --- .../__snapshots__/formatUtils.test.js.snap | 45 -------------- src/utils/__tests__/formatUtils.test.js | 61 ++++++++----------- 2 files changed, 26 insertions(+), 80 deletions(-) delete mode 100644 src/utils/__tests__/__snapshots__/formatUtils.test.js.snap diff --git a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap deleted file mode 100644 index 448a338a..00000000 --- a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`format utils btckb2satoshib 1`] = `0`; - -exports[`format utils btckb2satoshib 2`] = `100000`; - -exports[`format utils btckb2satoshib 3`] = `200000`; - -exports[`format utils btckb2satoshib 4`] = `10000000`; - -exports[`format utils btckb2satoshib 5`] = `99900000`; - -exports[`format utils formatAmount 1`] = `"0 btc"`; - -exports[`format utils formatAmount 2`] = `"10 mBTC"`; - -exports[`format utils formatAmount 3`] = `"0.000005 mBTC"`; - -exports[`format utils formatAmount 4`] = `"1e-8 eth"`; - -exports[`format utils formatAmount 5`] = `"0.00099999 tau"`; - -exports[`format utils formatTime 1`] = `"No time estimate"`; - -exports[`format utils formatTime 2`] = `"1 minutes"`; - -exports[`format utils formatTime 3`] = `"2 minutes"`; - -exports[`format utils formatTime 4`] = `"1 hour 40 minutes"`; - -exports[`format utils formatTime 5`] = `"16 hours 39 minutes"`; - -exports[`format utils formatTime 6`] = `"45 minutes"`; - -exports[`format utils hexToString 1`] = `"test"`; - -exports[`format utils hexToString 2`] = `"0001"`; - -exports[`format utils hexToString 3`] = `"test99999"`; - -exports[`format utils stringToHex 1`] = `"0074006500730074"`; - -exports[`format utils stringToHex 2`] = `"0030003000300031"`; - -exports[`format utils stringToHex 3`] = `"007400650073007400390039003900390039"`; diff --git a/src/utils/__tests__/formatUtils.test.js b/src/utils/__tests__/formatUtils.test.js index eb1d026d..2f9071d5 100644 --- a/src/utils/__tests__/formatUtils.test.js +++ b/src/utils/__tests__/formatUtils.test.js @@ -1,49 +1,40 @@ -import * as formatUtils from '../formatUtils'; +import * as utils from '../formatUtils'; describe('format utils', () => { it('formatAmount', () => { - const input = [ - { amount: 0, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, - { amount: 1000000, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, - { amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, - { amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } }, - { amount: 99999, coinInfo: { isBitcoin: false, shortcut: 'tau' } }, - ]; - - input.forEach((entry) => { - expect(formatUtils.formatAmount(entry.amount, entry.coinInfo, entry.coinInfo.currencyUnits)).toMatchSnapshot(); - }); + expect(utils.formatAmount(0, { isBitcoin: true }, 'mbtc')).toMatchSnapshot('0 btc'); + expect(utils.formatAmount(1000000, { isBitcoin: true }, 'mbtc')).toMatchSnapshot('10 mBTC'); + expect(utils.formatAmount(0.5, { isBitcoin: true }, 'mbtc')).toMatchSnapshot('0.000005 mBTC'); + expect(utils.formatAmount(1, { isBitcoin: false, shortcut: 'eth' }, null)).toMatchSnapshot('1e-8 eth'); + expect(utils.formatAmount(99999, { isBitcoin: false, shortcut: 'tau' }, null)).toMatchSnapshot('0.00099999 tau'); }); - it('formatTime', () => { - const input = [0, 1, 2, 100, 999, 45]; - - input.forEach((entry) => { - expect(formatUtils.formatTime(entry)).toMatchSnapshot(); - }); + it('format time', () => { + expect(utils.formatTime(0)).toBe('No time estimate'); + expect(utils.formatTime(1)).toBe('1 minutes'); // TODO: should be minute + expect(utils.formatTime(2)).toBe('2 minutes'); + expect(utils.formatTime(45)).toBe('45 minutes'); + expect(utils.formatTime(100)).toBe('1 hour 40 minutes'); + expect(utils.formatTime(999)).toBe('16 hours 39 minutes'); }); it('btckb2satoshib', () => { - const input = [0, 1, 2, 100, 999]; - - input.forEach((entry) => { - expect(formatUtils.btckb2satoshib(entry)).toMatchSnapshot(); - }); + 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('stringToHex', () => { - const input = ['test', '0001', 'test99999']; - - input.forEach((entry) => { - expect(formatUtils.stringToHex(entry)).toMatchSnapshot(); - }); + it('string to hex', () => { + expect(utils.stringToHex('test')).toBe('0074006500730074'); + expect(utils.stringToHex('0001')).toBe('0030003000300031'); + expect(utils.stringToHex('test99999')).toBe('007400650073007400390039003900390039'); }); - it('hexToString', () => { - const input = ['0074006500730074', '0030003000300031', '007400650073007400390039003900390039']; - - input.forEach((entry) => { - expect(formatUtils.hexToString(entry)).toMatchSnapshot(); - }); + it('hex to string', () => { + expect(utils.hexToString('0074006500730074')).toBe('test'); + expect(utils.hexToString('0030003000300031')).toBe('0001'); + expect(utils.hexToString('007400650073007400390039003900390039')).toBe('test99999'); }); });