Merge "Create the settings reducer" into mpga

This commit is contained in:
jenkins-bot 2016-12-13 11:03:47 +00:00 committed by Gerrit Code Review
commit cacd6ee04c
2 changed files with 31 additions and 54 deletions

View file

@ -1,4 +1,4 @@
( function ( mw, $ ) {
( function ( mw ) {
// Sugar for the mw.popups.reducers.eventLogging reducer.
var counts = mw.popups.counts;
@ -235,61 +235,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 ) );

View file

@ -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'
);
} );