Skip to content

Commit

Permalink
Add tests for settings redux module
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-username committed Mar 28, 2018
1 parent 2d79e71 commit 38b660f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/redux/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const initialState = {
passcodeHash: null,
};

const requirePasscode = (state = initialState.requirePasscode, action) => {
export const requirePasscode = (
state = initialState.requirePasscode,
action
) => {
switch (action.type) {
case TOGGLE_PASSCODE_REQUIREMENT:
return !state;
Expand All @@ -30,7 +33,7 @@ const requirePasscode = (state = initialState.requirePasscode, action) => {
}
};

const passcodeHash = (state = initialState.passcodeHash, action) => {
export const passcodeHash = (state = initialState.passcodeHash, action) => {
switch (action.type) {
case SET_PASSCODE:
return action.passcodeHash;
Expand Down
51 changes: 51 additions & 0 deletions src/redux/modules/settings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
requirePasscode as requirePasscodeReducer,
passcodeHash as passcodeHashReducer,
togglePasscodeRequirement,
resetPasscodeSettings,
setPasscode,
} from './settings';

describe('settings modules test', () => {
describe('requirePasscode reducer test', () => {
it('should return the initial state', () => {
expect(requirePasscodeReducer(undefined, {})).toEqual(false);
});

it('should set the requirement to false if previously true', () => {
expect(requirePasscodeReducer(true, togglePasscodeRequirement())).toEqual(
false
);
});

it('should set the requirement to true if previously false', () => {
expect(
requirePasscodeReducer(false, togglePasscodeRequirement())
).toEqual(true);
});

it('should reset the requirement correctly (reset to initial state)', () => {
expect(requirePasscodeReducer(true, resetPasscodeSettings())).toEqual(
false
);
});
});

describe('passcodeHash reducer test', () => {
it('should return the initial state', () => {
expect(passcodeHashReducer(undefined, {})).toEqual(null);
});

it('should set the hash correctly', () => {
expect(
passcodeHashReducer(undefined, setPasscode('HASH HASH BABY'))
).toEqual('HASH HASH BABY');
});

it('should reset passcode hash correctly (reset to initial state)', () => {
expect(
passcodeHashReducer('HASH HASH BABY', resetPasscodeSettings())
).toEqual(null);
});
});
});

0 comments on commit 38b660f

Please sign in to comment.