Skip to content

Commit

Permalink
Merge pull request #3851 from LiskHQ/3797-unit-test-coverage-for-redu…
Browse files Browse the repository at this point in the history
…x-reducers

Unit test coverage for redux reducers - Closes #3797
  • Loading branch information
reyraa authored Oct 12, 2021
2 parents 8c3a4a4 + 48b1b9c commit 93d3fe0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
7 changes: 2 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ module.exports = {
'src/actions/settings.js',
'src/actions/transactions.js',
'src/actions/network/lsk.js',
'src/store/middlewares/network.js',
'src/store/middlewares/account.js',
'src/store/index.js',
'src/store/reducers/settings.js',
'src/store/reducers/bookmarks.js',
'src/store/reducers/filters.js', // To be removed in #2175
'src/store/reducers/network.js',
'src/store/middlewares/network.js',
'src/store/middlewares/account.js',
'src/components/screens/',
'src/components/shared/errorBoundary/index.js',
'src/components/shared/registerMultiStep/index.js',
Expand Down
16 changes: 13 additions & 3 deletions src/store/reducers/bookmarks.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
bookmarkAdded,
bookmarkUpdated,
bookmarkRemoved,
bookmarkAdded, bookmarkUpdated, bookmarkRemoved,
} from '@actions';
import { actionTypes } from '@constants';
import bookmarks from './bookmarks';
Expand Down Expand Up @@ -104,4 +102,16 @@ describe('Reducer: bookmarks(state, action)', () => {
expect(changedState.LSK[0]).toEqual(account);
expect(changedState.LSK[1]).toEqual(undefined);
});

it('should return validated bookmarks if action.type = actionType.bookmarksRetrieved', () => {
const action = {
type: actionTypes.bookmarksRetrieved,
data: { LSK: [account, account2], BTC: [] },
};

let state;

const changedState = bookmarks(state, action);
expect(changedState).toEqual(action.data);
});
});
30 changes: 22 additions & 8 deletions src/store/reducers/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ import { actionTypes } from '@constants';
import network from './network';

describe('Reducer: network(state, action)', () => {
it.skip('should return state object with passed network setup if action is networkSet', () => {
it('should return state object with passed network setup if action is networkSet', () => {
const state = {
networks: {
BTC: {
},
BTC: {},
},
};
const action = {
type: actionTypes.networkSet,
type: actionTypes.networkConfigSet,
data: {
name: 'Custom Node',
token: 'LSK',
network: {
nodeUrl: 'http://localhost:4000',
},
network: state.network,
},
};

Expand All @@ -31,7 +28,7 @@ describe('Reducer: network(state, action)', () => {
expect(changedState).toEqual(newState);
});

it.skip('should return state object with updated status of network if action is networkStatusUpdated', () => {
it('should return state object with updated status of network if action is networkStatusUpdated', () => {
let state;
const online = true;
const action = {
Expand All @@ -46,4 +43,21 @@ describe('Reducer: network(state, action)', () => {
const changedState = network(state, action);
expect(changedState).toEqual(newState);
});

it('should return state object with updated last BTC set', () => {
let state;
const lastBtcUpdate = 0;
const action = {
type: actionTypes.lastBtcUpdateSet,
data: { lastBtcUpdate },
};

const newState = {
status: {},
networks: {},
lastBtcUpdate: action.data,
};
const changedState = network(state, action);
expect(changedState).toEqual(newState);
});
});
11 changes: 11 additions & 0 deletions src/store/reducers/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ describe('Reducer: settings(state, action)', () => {
const FinalStep = settings(changedState, action);
expect(FinalStep).toEqual(initializeState);
});

it('should return retrieved settings if action.type = actionTypes.settingsRetrieved', () => {
let state;
const action = {
type: actionTypes.settingsRetrieved,
data: { },
};

const changedState = settings(state, action);
expect(changedState).toEqual(action.data);
});
});

0 comments on commit 93d3fe0

Please sign in to comment.