From 4474b4bc8cfcfbb13d65fb582ecd329cac2bbf3a Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Mon, 7 Oct 2019 16:20:29 -0400 Subject: [PATCH] add navigation reducer test --- test/unit/redux/navigation.test.js | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/unit/redux/navigation.test.js b/test/unit/redux/navigation.test.js index 277b2d574..56ed10582 100644 --- a/test/unit/redux/navigation.test.js +++ b/test/unit/redux/navigation.test.js @@ -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('/'); + }); });