diff --git a/src/reducers/mode.js b/src/reducers/mode.js index e07b0cda008ccfe70658157e18b6f453df28020b..5fca13b5c56a70a2d75cd3c4e19eb73808229c0b 100644 --- a/src/reducers/mode.js +++ b/src/reducers/mode.js @@ -12,16 +12,14 @@ const reducer = function (state, action) { if (typeof state === 'undefined') state = initialState; switch (action.type) { case SET_FULL_SCREEN: - return { - isFullScreen: action.isFullScreen, - isPlayerOnly: state.isPlayerOnly - }; + return Object.assign({}, state, { + isFullScreen: action.isFullScreen + }); case SET_PLAYER: - return { - isFullScreen: state.isFullScreen, + return Object.assign({}, state, { isPlayerOnly: action.isPlayerOnly, hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly - }; + }); default: return state; } diff --git a/test/unit/reducers/mode-reducer.test.js b/test/unit/reducers/mode-reducer.test.js new file mode 100644 index 0000000000000000000000000000000000000000..641398f2d5c618b617df44efd46f3f2f87e1fe47 --- /dev/null +++ b/test/unit/reducers/mode-reducer.test.js @@ -0,0 +1,53 @@ +/* eslint-env jest */ +import modeReducer from '../../../src/reducers/mode'; + +const SET_FULL_SCREEN = 'scratch-gui/mode/SET_FULL_SCREEN'; +const SET_PLAYER = 'scratch-gui/mode/SET_PLAYER'; + +test('initialState', () => { + let defaultState; + /* modeReducer(state, action) */ + expect(modeReducer(defaultState, {type: 'anything'})).toBeDefined(); +}); + +test('set full screen mode', () => { + const previousState = { + showBranding: false, + isFullScreen: false, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + const action = { + type: SET_FULL_SCREEN, + isFullScreen: true + }; + const newState = { + showBranding: false, + isFullScreen: true, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + /* modeReducer(state, action) */ + expect(modeReducer(previousState, action)).toEqual(newState); +}); + +test('set player mode', () => { + const previousState = { + showBranding: false, + isFullScreen: false, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + const action = { + type: SET_PLAYER, + isPlayerOnly: true + }; + const newState = { + showBranding: false, + isFullScreen: false, + isPlayerOnly: true, + hasEverEnteredEditor: true + }; + /* modeReducer(state, action) */ + expect(modeReducer(previousState, action)).toEqual(newState); +});