From 8415bd1e9b52ffe08a5faf0b3292b3e083088aa5 Mon Sep 17 00:00:00 2001 From: joakin Date: Mon, 12 Dec 2016 18:21:15 +0100 Subject: [PATCH] Create the settings reducer Right now only with visibility state on it. Change-Id: Idbe99aca652eb04357ba85f22ba413dcd38cd54b --- resources/ext.popups/reducers.js | 57 ++++++------------------- tests/qunit/ext.popups/reducers.test.js | 28 +++++++----- 2 files changed, 31 insertions(+), 54 deletions(-) diff --git a/resources/ext.popups/reducers.js b/resources/ext.popups/reducers.js index 080cd2411..f45096380 100644 --- a/resources/ext.popups/reducers.js +++ b/resources/ext.popups/reducers.js @@ -1,4 +1,4 @@ -( function ( mw, $ ) { +( function ( mw ) { // Sugar for the mw.popups.reducers.eventLogging reducer. var counts = mw.popups.counts; @@ -214,61 +214,30 @@ }; /** - * Reducer for actions that modify the state of the view + * Reducer for actions that modify the state of the settings * - * @param {Object} state before action - * @param {Object} action Redux action that modified state. - * Must have `type` property. + * @param {Object} state + * @param {Object} action * @return {Object} state after action */ - mw.popups.reducers.renderer = function ( state, action ) { + mw.popups.reducers.settings = function ( state, action ) { if ( state === undefined ) { state = { - isAnimating: false, - isInteractive: false, - showSettings: false + shouldShow: false }; } switch ( action.type ) { - case mw.popups.actionTypes.PREVIEW_ANIMATING: - return $.extend( {}, state, { - isAnimating: true, - isInteractive: false, - showSettings: false + case mw.popups.actionTypes.SETTINGS_SHOW: + return nextState( state, { + shouldShow: true } ); - case mw.popups.actionTypes.PREVIEW_INTERACTIVE: - return $.extend( OO.copy( state ), { - isAnimating: false, - isInteractive: true, - showSettings: false - } ); - case mw.popups.actionTypes.PREVIEW_CLICK: - return $.extend( OO.copy( state ), { - isAnimating: false, - isInteractive: false, - showSettings: false - } ); - case mw.popups.actionTypes.COG_CLICK: - return $.extend( OO.copy( state ), { - isAnimating: true, - isInteractive: false, - showSettings: true - } ); - case mw.popups.actionTypes.SETTINGS_DIALOG_INTERACTIVE: - return $.extend( OO.copy( state ), { - isAnimating: false, - isInteractive: true, - showSettings: true - } ); - case mw.popups.actionTypes.SETTINGS_DIALOG_CLOSED: - return $.extend( OO.copy( state ), { - isAnimating: false, - isInteractive: false, - showSettings: false + case mw.popups.actionTypes.SETTINGS_HIDE: + return nextState( state, { + shouldShow: false } ); default: return state; } }; -}( mediaWiki, jQuery ) ); +}( mediaWiki ) ); diff --git a/tests/qunit/ext.popups/reducers.test.js b/tests/qunit/ext.popups/reducers.test.js index 507df6ae9..98b1e234d 100644 --- a/tests/qunit/ext.popups/reducers.test.js +++ b/tests/qunit/ext.popups/reducers.test.js @@ -27,10 +27,8 @@ event: undefined, interaction: undefined }, - renderer: { - isAnimating: false, - isInteractive: false, - showSettings: false + settings: { + shouldShow: false } }, 'It should initialize the state by default' @@ -179,17 +177,27 @@ ); } ); - QUnit.test( '#renderer', function ( assert ) { + QUnit.test( '#settings: SETTINGS_SHOW', function ( assert ) { assert.expect( 1 ); assert.deepEqual( - mw.popups.reducers.renderer( {}, { type: 'PREVIEW_ANIMATING' } ), + mw.popups.reducers.settings( {}, { type: 'SETTINGS_SHOW' } ), { - isAnimating: true, - isInteractive: false, - showSettings: false + shouldShow: true }, - 'It should set isAnimating to true on the PREVIEW_ANIMATING action' + 'It should mark the settings dialog as ready to be shown' + ); + } ); + + QUnit.test( '#settings: SETTINGS_HIDE', function ( assert ) { + assert.expect( 1 ); + + assert.deepEqual( + mw.popups.reducers.settings( {}, { type: 'SETTINGS_HIDE' } ), + { + shouldShow: false + }, + 'It should mark the settings dialog as ready to be closed' ); } );