2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-07-16 18:06:32 +02:00
|
|
|
import GasReducer, { setCustomGasPrice, setCustomGasLimit } from './gas.duck';
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
import {
|
|
|
|
SET_CUSTOM_GAS_PRICE,
|
|
|
|
SET_CUSTOM_GAS_LIMIT,
|
|
|
|
} from './gas-action-constants';
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Gas Duck', () => {
|
|
|
|
let tempDateNow;
|
|
|
|
beforeEach(() => {
|
|
|
|
tempDateNow = global.Date.now;
|
2019-07-04 21:18:12 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
global.Date.now = () => 2000000;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
sinon.restore();
|
|
|
|
|
|
|
|
global.Date.now = tempDateNow;
|
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
|
|
|
const mockState = {
|
2020-02-06 17:38:14 +01:00
|
|
|
mockProp: 123,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-09 21:25:54 +02:00
|
|
|
const initState = {
|
|
|
|
customData: {
|
2018-09-13 10:47:05 +02:00
|
|
|
price: null,
|
2018-12-12 15:54:03 +01:00
|
|
|
limit: null,
|
2018-09-09 21:25:54 +02:00
|
|
|
},
|
2021-02-19 03:48:23 +01:00
|
|
|
};
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('GasReducer()', () => {
|
|
|
|
it('should initialize state', () => {
|
|
|
|
expect(GasReducer(undefined, {})).toStrictEqual(initState);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return state unchanged if it does not match a dispatched actions type', () => {
|
|
|
|
expect(
|
2018-09-09 21:25:54 +02:00
|
|
|
GasReducer(mockState, {
|
|
|
|
type: 'someOtherAction',
|
|
|
|
value: 'someValue',
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(mockState);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should set customData.price when receiving a SET_CUSTOM_GAS_PRICE action', () => {
|
|
|
|
expect(
|
2018-09-09 21:25:54 +02:00
|
|
|
GasReducer(mockState, {
|
|
|
|
type: SET_CUSTOM_GAS_PRICE,
|
|
|
|
value: 4321,
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({ customData: { price: 4321 }, ...mockState });
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should set customData.limit when receiving a SET_CUSTOM_GAS_LIMIT action', () => {
|
|
|
|
expect(
|
2018-09-09 21:25:54 +02:00
|
|
|
GasReducer(mockState, {
|
|
|
|
type: SET_CUSTOM_GAS_LIMIT,
|
|
|
|
value: 9876,
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({ customData: { limit: 9876 }, ...mockState });
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('setCustomGasPrice', () => {
|
|
|
|
it('should create the correct action', () => {
|
|
|
|
expect(setCustomGasPrice('mockCustomGasPrice')).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
type: SET_CUSTOM_GAS_PRICE,
|
|
|
|
value: 'mockCustomGasPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-09 21:25:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('setCustomGasLimit', () => {
|
|
|
|
it('should create the correct action', () => {
|
|
|
|
expect(setCustomGasLimit('mockCustomGasLimit')).toStrictEqual({
|
2020-11-03 00:41:28 +01:00
|
|
|
type: SET_CUSTOM_GAS_LIMIT,
|
|
|
|
value: 'mockCustomGasLimit',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|