1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00
metamask-extension/ui/ducks/gas/gas-duck.test.js

85 lines
2.0 KiB
JavaScript
Raw Normal View History

import sinon from 'sinon';
2018-09-09 21:25:54 +02:00
import GasReducer, { setCustomGasPrice, setCustomGasLimit } from './gas.duck';
2018-09-09 21:25:54 +02:00
import {
SET_CUSTOM_GAS_PRICE,
SET_CUSTOM_GAS_LIMIT,
} from './gas-action-constants';
describe('Gas Duck', () => {
let tempDateNow;
beforeEach(() => {
tempDateNow = global.Date.now;
global.Date.now = () => 2000000;
});
afterEach(() => {
sinon.restore();
global.Date.now = tempDateNow;
});
2018-09-09 21:25:54 +02:00
const mockState = {
mockProp: 123,
};
2018-09-09 21:25:54 +02:00
const initState = {
customData: {
price: null,
limit: null,
2018-09-09 21:25:54 +02:00
},
};
describe('GasReducer()', () => {
it('should initialize state', () => {
expect(GasReducer(undefined, {})).toStrictEqual(initState);
});
2018-09-09 21:25:54 +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',
}),
).toStrictEqual(mockState);
});
2018-09-09 21:25:54 +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,
}),
).toStrictEqual({ customData: { price: 4321 }, ...mockState });
});
2018-09-09 21:25:54 +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,
}),
).toStrictEqual({ customData: { limit: 9876 }, ...mockState });
});
});
2018-09-09 21:25:54 +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',
});
});
});
2018-09-09 21:25:54 +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',
});
});
});
});