aitrean cf9887f21f Outstanding tasks to Productionize Tx (#1194)
* Verify and complete all branching saga logic tests for transaction stack.

* Write reducer tests for refactored transaction stack.

* Add selector tests. Some files still need to be debugged.

* Add snapshot test for fields, additional seelector testing.

* Remove fields snapshots.

* Remove ABIs from the TestState json

* Use redux state instead of raw json in selector testing.

* Fix merge issues.

* Remove log

* Fix state values.

* Change test value to wei.

* Last touchup.

* Fix buffer shape, change Wei typo, use reasonable wei values.

* Last touch up.
2018-03-08 12:03:45 -06:00

110 lines
2.9 KiB
TypeScript

import { TypeKeys } from 'actions/transaction/constants';
import { getDecimalFromEtherUnit } from 'libs/units';
import { State, meta } from 'reducers/transaction/meta';
import * as txActions from 'actions/transaction';
describe('meta reducer', () => {
const INITIAL_STATE: State = {
unit: '',
previousUnit: '',
decimal: getDecimalFromEtherUnit('ether'),
tokenValue: { raw: '', value: null },
tokenTo: { raw: '', value: null },
from: null
};
const testPayload = { raw: 'test', value: null };
it('should handle UNIT_META_SET', () => {
const setUnitMetaAction: txActions.SetUnitMetaAction = {
type: TypeKeys.UNIT_META_SET,
payload: 'test'
};
expect(meta(INITIAL_STATE, setUnitMetaAction));
});
it('should handle TOKEN_VALUE_META_SET', () => {
expect(meta(INITIAL_STATE, txActions.setTokenValue(testPayload))).toEqual({
...INITIAL_STATE,
tokenValue: testPayload
});
});
it('should handle TOKEN_TO_META_SET', () => {
expect(meta(INITIAL_STATE, txActions.setTokenTo(testPayload))).toEqual({
...INITIAL_STATE,
tokenTo: testPayload
});
});
it('should handle GET_FROM_SUCCEEDED', () => {
expect(meta(INITIAL_STATE, txActions.getFromSucceeded('test'))).toEqual({
...INITIAL_STATE,
from: 'test'
});
});
it('should handle TOKEN_TO_ETHER_SWAP', () => {
const swapAction: txActions.SwapTokenToEtherAction = {
type: TypeKeys.TOKEN_TO_ETHER_SWAP,
payload: {
to: testPayload,
value: testPayload,
decimal: 1
}
};
expect(meta(INITIAL_STATE, swapAction)).toEqual({
...INITIAL_STATE,
decimal: swapAction.payload.decimal
});
});
it('should handle ETHER_TO_TOKEN_SWAP', () => {
const swapAction: txActions.SwapEtherToTokenAction = {
type: TypeKeys.ETHER_TO_TOKEN_SWAP,
payload: {
to: testPayload,
data: testPayload,
tokenTo: testPayload,
tokenValue: testPayload,
decimal: 1
}
};
expect(meta(INITIAL_STATE, swapAction)).toEqual({
...INITIAL_STATE,
decimal: swapAction.payload.decimal,
tokenTo: testPayload,
tokenValue: testPayload
});
});
it('should handle TOKEN_TO_TOKEN_SWAP', () => {
const swapAction: txActions.SwapTokenToTokenAction = {
type: TypeKeys.TOKEN_TO_TOKEN_SWAP,
payload: {
to: testPayload,
data: testPayload,
tokenValue: testPayload,
decimal: 1
}
};
expect(meta(INITIAL_STATE, swapAction)).toEqual({
...INITIAL_STATE,
decimal: swapAction.payload.decimal,
tokenValue: testPayload
});
});
it('should reset', () => {
const resetAction: txActions.ResetAction = {
type: TypeKeys.RESET,
payload: { include: {}, exclude: {} }
};
const modifiedState: State = {
...INITIAL_STATE,
unit: 'modified'
};
expect(meta(modifiedState, resetAction)).toEqual(INITIAL_STATE);
});
});