test: add wallet-summary reducer tests

This commit is contained in:
George Lima 2018-12-10 14:32:44 -03:00
parent c1bfd6da09
commit 51893c2571
2 changed files with 91 additions and 3 deletions

View File

@ -2,7 +2,14 @@
import configureStore from 'redux-mock-store';
import { LOAD_WALLET_SUMMARY, loadWalletSummary } from '../../app/redux/modules/wallet';
import {
LOAD_WALLET_SUMMARY,
LOAD_WALLET_SUMMARY_SUCCESS,
LOAD_WALLET_SUMMARY_ERROR,
loadWalletSummary,
loadWalletSummarySuccess,
loadWalletSummaryError,
} from '../../app/redux/modules/wallet';
const store = configureStore()();
@ -18,4 +25,36 @@ describe('WalletSummary Actions', () => {
}),
);
});
test('should create an action to load wallet summary', () => {
const payload = {
total: 5000,
transparent: 5000,
shielded: 5000,
};
store.dispatch(loadWalletSummarySuccess(payload));
expect(store.getActions()[0]).toEqual(
expect.objectContaining({
type: LOAD_WALLET_SUMMARY_SUCCESS,
payload,
}),
);
});
test('should create an action to load wallet summary with error', () => {
const payload = {
error: 'Something went wrong!',
};
store.dispatch(loadWalletSummaryError(payload));
expect(store.getActions()[0]).toEqual(
expect.objectContaining({
type: LOAD_WALLET_SUMMARY_ERROR,
payload,
}),
);
});
});

View File

@ -1,9 +1,20 @@
// @flow
import walletSummaryReducer, { LOAD_WALLET_SUMMARY } from '../../app/redux/modules/wallet';
import walletSummaryReducer, {
LOAD_WALLET_SUMMARY,
LOAD_WALLET_SUMMARY_SUCCESS,
LOAD_WALLET_SUMMARY_ERROR,
} from '../../app/redux/modules/wallet';
describe('WalletSummary Reducer', () => {
test('should return the valid initial state', () => {
const initialState = [];
const initialState = {
total: 0,
shielded: 0,
transparent: 0,
error: null,
isLoading: false,
dollarValue: 0,
};
const action = {
type: 'UNKNOWN_ACTION',
payload: {},
@ -28,4 +39,42 @@ describe('WalletSummary Reducer', () => {
expect(walletSummaryReducer(undefined, action)).toEqual(expectedState);
});
test('should load the wallet summary with success', () => {
const action = {
type: LOAD_WALLET_SUMMARY_SUCCESS,
payload: {
total: 1000,
transparent: 1000,
shielded: 1000,
},
};
const expectedState = {
...action.payload,
error: null,
isLoading: false,
dollarValue: 0,
};
expect(walletSummaryReducer(undefined, action)).toEqual(expectedState);
});
test('should load the wallet summary with error', () => {
const action = {
type: LOAD_WALLET_SUMMARY_ERROR,
payload: {
error: 'Something went wrong',
},
};
const expectedState = {
total: 0,
shielded: 0,
transparent: 0,
error: action.payload.error,
isLoading: false,
dollarValue: 0,
};
expect(walletSummaryReducer(undefined, action)).toEqual(expectedState);
});
});