From bf09d9c3d0b6b8a51e4af5c217a78f4305ac989c Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Sun, 3 Feb 2019 11:55:32 -0600 Subject: [PATCH 1/4] retain showBranding after SET_FULL_SCREEN --- src/reducers/mode.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/reducers/mode.js b/src/reducers/mode.js index e07b0cda0..cb29e763a 100644 --- a/src/reducers/mode.js +++ b/src/reducers/mode.js @@ -2,26 +2,24 @@ const SET_FULL_SCREEN = 'scratch-gui/mode/SET_FULL_SCREEN'; const SET_PLAYER = 'scratch-gui/mode/SET_PLAYER'; const initialState = { + isAdmin: true, showBranding: false, isFullScreen: false, isPlayerOnly: false, hasEverEnteredEditor: true }; -const reducer = function (state, action) { - if (typeof state === 'undefined') state = initialState; +const reducer = function (state = initialState, action) { 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; } From 4db64ca56025464de09b58930cad91ba675b5bcc Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Sun, 3 Feb 2019 12:12:56 -0600 Subject: [PATCH 2/4] add mode reducer unit tests --- test/unit/reducers/mode-reducer.test.js | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/unit/reducers/mode-reducer.test.js diff --git a/test/unit/reducers/mode-reducer.test.js b/test/unit/reducers/mode-reducer.test.js new file mode 100644 index 000000000..8b57f8a35 --- /dev/null +++ b/test/unit/reducers/mode-reducer.test.js @@ -0,0 +1,57 @@ +/* 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 = { + isAdmin: true, + showBranding: false, + isFullScreen: false, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + const action = { + type: SET_FULL_SCREEN, + isFullScreen: true + }; + const newState = { + isAdmin: true, + showBranding: false, + isFullScreen: true, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + /* modeReducer(state, action) */ + expect(modeReducer(previousState, action)).toEqual(newState); +}); + +test('set player mode', () => { + const previousState = { + isAdmin: true, + showBranding: false, + isFullScreen: false, + isPlayerOnly: false, + hasEverEnteredEditor: true + }; + const action = { + type: SET_PLAYER, + isPlayerOnly: true + }; + const newState = { + isAdmin: true, + showBranding: false, + isFullScreen: false, + isPlayerOnly: true, + hasEverEnteredEditor: true + }; + /* modeReducer(state, action) */ + expect(modeReducer(previousState, action)).toEqual(newState); +}); From 4dc2501e5cab70adb706882dccb3de44019ea24b Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Sun, 3 Feb 2019 15:16:45 -0600 Subject: [PATCH 3/4] add empty object to abject assign --- src/reducers/mode.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/reducers/mode.js b/src/reducers/mode.js index cb29e763a..4c9d9f808 100644 --- a/src/reducers/mode.js +++ b/src/reducers/mode.js @@ -9,14 +9,15 @@ const initialState = { hasEverEnteredEditor: true }; -const reducer = function (state = initialState, action) { +const reducer = function (state, action) { + if (typeof state === 'undefined') state = initialState; switch (action.type) { case SET_FULL_SCREEN: - return Object.assign(state, { + return Object.assign({}, state, { isFullScreen: action.isFullScreen }); case SET_PLAYER: - return Object.assign(state, { + return Object.assign({}, state, { isPlayerOnly: action.isPlayerOnly, hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly }); From 7494482c9e8dd8a9186e22df3cac5dfd04fd03e8 Mon Sep 17 00:00:00 2001 From: Luke Schlangen Date: Mon, 4 Feb 2019 11:24:42 -0600 Subject: [PATCH 4/4] remove isAdmin from mode reducer --- src/reducers/mode.js | 1 - test/unit/reducers/mode-reducer.test.js | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/reducers/mode.js b/src/reducers/mode.js index 4c9d9f808..5fca13b5c 100644 --- a/src/reducers/mode.js +++ b/src/reducers/mode.js @@ -2,7 +2,6 @@ const SET_FULL_SCREEN = 'scratch-gui/mode/SET_FULL_SCREEN'; const SET_PLAYER = 'scratch-gui/mode/SET_PLAYER'; const initialState = { - isAdmin: true, showBranding: false, isFullScreen: false, isPlayerOnly: false, diff --git a/test/unit/reducers/mode-reducer.test.js b/test/unit/reducers/mode-reducer.test.js index 8b57f8a35..641398f2d 100644 --- a/test/unit/reducers/mode-reducer.test.js +++ b/test/unit/reducers/mode-reducer.test.js @@ -12,7 +12,6 @@ test('initialState', () => { test('set full screen mode', () => { const previousState = { - isAdmin: true, showBranding: false, isFullScreen: false, isPlayerOnly: false, @@ -23,7 +22,6 @@ test('set full screen mode', () => { isFullScreen: true }; const newState = { - isAdmin: true, showBranding: false, isFullScreen: true, isPlayerOnly: false, @@ -35,7 +33,6 @@ test('set full screen mode', () => { test('set player mode', () => { const previousState = { - isAdmin: true, showBranding: false, isFullScreen: false, isPlayerOnly: false, @@ -46,7 +43,6 @@ test('set player mode', () => { isPlayerOnly: true }; const newState = { - isAdmin: true, showBranding: false, isFullScreen: false, isPlayerOnly: true,