add navigation reducer test

This commit is contained in:
Ben Wheeler 2019-10-07 16:20:29 -04:00
parent baa4e0e2c3
commit 4474b4bc8c

View file

@ -7,11 +7,20 @@ const {
setLoginOpen,
setRegistrationOpen,
setSearchTerm,
toggleLoginOpen
toggleLoginOpen,
handleRegistrationRequested
} = require('../../../src/redux/navigation');
describe('unit test lib/validate.js', () => {
beforeEach(() => {
// override existing window.location definition, to make it testable
Object.defineProperty(global.window, 'location', {
value: '/',
writable: true
});
});
test('initialState', () => {
let defaultState;
/* navigationReducer(state, action) */
@ -238,4 +247,28 @@ describe('unit test lib/validate.js', () => {
const resultState = navigationReducer(initialState, action);
expect(resultState.loginOpen).toBe(false);
});
test('handleRegistrationRequested with useScratch3Registration true navigates user to /join, ' +
'and does NOT open scratch 2 registration', () => {
const initialState = {
registrationOpen: false,
useScratch3Registration: true
};
const action = handleRegistrationRequested();
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(false);
expect(global.window.location).toEqual('/join');
});
test('handleRegistrationRequested with useScratch3Registration false does NOT navigate user away, ' +
'DOES open scratch 2 registration', () => {
const initialState = {
registrationOpen: false,
useScratch3Registration: false
};
const action = handleRegistrationRequested();
const resultState = navigationReducer(initialState, action);
expect(resultState.registrationOpen).toBe(true);
expect(global.window.location).toEqual('/');
});
});