From b70886a99b466366e84d24271adbb890aebf6460 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Mon, 5 Nov 2018 13:31:46 -0330 Subject: Fixes for components that break e2e gas customization tests, plus unit test updates. --- ui/app/ducks/tests/gas-duck.test.js | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'ui/app/ducks') diff --git a/ui/app/ducks/tests/gas-duck.test.js b/ui/app/ducks/tests/gas-duck.test.js index 96c00383b..009758cde 100644 --- a/ui/app/ducks/tests/gas-duck.test.js +++ b/ui/app/ducks/tests/gas-duck.test.js @@ -1,7 +1,16 @@ import assert from 'assert' import sinon from 'sinon' +import proxyquire from 'proxyquire' -import GasReducer, { + +const GasDuck = proxyquire('../gas.duck.js', { + '../../lib/local-storage-helpers': { + loadLocalStorageData: sinon.spy(), + saveLocalStorageData: sinon.spy(), + }, +}) + +const { basicGasEstimatesLoadingStarted, basicGasEstimatesLoadingFinished, setBasicGasEstimateData, @@ -16,7 +25,8 @@ import GasReducer, { setPricesAndTimeEstimates, fetchGasEstimates, setApiEstimatesLastRetrieved, -} from '../gas.duck.js' +} = GasDuck +const GasReducer = GasDuck.default describe('Gas Duck', () => { let tempFetch @@ -312,6 +322,11 @@ describe('Gas Duck', () => { describe('fetchGasEstimates', () => { const mockDistpatch = sinon.spy() + + beforeEach(() => { + mockDistpatch.resetHistory() + }) + it('should call fetch with the expected params', async () => { global.fetch.resetHistory() await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign( @@ -377,6 +392,46 @@ describe('Gas Duck', () => { [{ type: GAS_ESTIMATE_LOADING_FINISHED }] ) }) + + it('should not call fetch if the estimates were retrieved < 75000 ms ago', async () => { + global.fetch.resetHistory() + await fetchGasEstimates(5)(mockDistpatch, () => ({ gas: Object.assign( + {}, + initState, + { + priceAndTimeEstimatesLastRetrieved: Date.now(), + priceAndTimeEstimates: [{ + expectedTime: '10', + expectedWait: 2, + gasprice: 50, + }], + } + ) })) + assert.deepEqual( + mockDistpatch.getCall(0).args, + [{ type: GAS_ESTIMATE_LOADING_STARTED} ] + ) + assert.equal(global.fetch.callCount, 0) + + assert.deepEqual( + mockDistpatch.getCall(1).args, + [{ + type: SET_PRICE_AND_TIME_ESTIMATES, + value: [ + { + expectedTime: '10', + expectedWait: 2, + gasprice: 50, + }, + ], + + }] + ) + assert.deepEqual( + mockDistpatch.getCall(2).args, + [{ type: GAS_ESTIMATE_LOADING_FINISHED }] + ) + }) }) describe('gasEstimatesLoadingStarted', () => { -- cgit