Skip to content

Commit

Permalink
Add tests for listings redux module
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-username committed Mar 28, 2018
1 parent 5628847 commit 2d79e71
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/redux/modules/listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const initialState = {
entries: {},
};

const entries = (state = initialState.entries, action) => {
export const entries = (state = initialState.entries, action) => {
switch (action.type) {
case ADD_ENTRY:
return {
Expand Down
87 changes: 87 additions & 0 deletions src/redux/modules/listings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
entries as entriesReducer,
addEntry,
modifyEntry,
deleteEntry,
} from './listings';

describe('listings modules test', () => {
describe('entries reducer test', () => {
it('should return the initial state', () => {
expect(entriesReducer(undefined, {})).toEqual({});
});

it('should add an entry correctly', () => {
expect(
entriesReducer(
{
init: {
code: '1234',
name: 'revan',
},
},
addEntry('id', 'malak', '1412')
)
).toEqual({
init: {
code: '1234',
name: 'revan',
},
id: {
code: '1412',
name: 'malak',
},
});
});

it('should modify (the code) an entry correctly', () => {
expect(
entriesReducer(
{
init: {
code: '1234',
name: 'revan',
},
id: {
code: '1412',
name: 'malak',
},
},
modifyEntry('init', '9999')
)
).toEqual({
init: {
code: '9999',
name: 'revan',
},
id: {
code: '1412',
name: 'malak',
},
});
});

it('should delete an entry correctly', () => {
expect(
entriesReducer(
{
init: {
code: '1234',
name: 'revan',
},
id: {
code: '1412',
name: 'malak',
},
},
deleteEntry('init')
)
).toEqual({
id: {
code: '1412',
name: 'malak',
},
});
});
});
});

0 comments on commit 2d79e71

Please sign in to comment.