mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
add navigation reducer test
This commit is contained in:
parent
baa4e0e2c3
commit
4474b4bc8c
1 changed files with 34 additions and 1 deletions
|
@ -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('/');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue