Add reducer cases for all actions

These may change as actions are implemented. Also fixes a typo in the
QUnit test for reducers.

Change-Id: I2218760f273c77c5d396177c99108a57de7162d6
This commit is contained in:
Jeff Hobson 2016-11-16 11:16:43 -05:00
parent ca84de7c9d
commit f9cc341105
2 changed files with 83 additions and 9 deletions

View file

@ -26,7 +26,6 @@
switch ( action.type ) {
case mw.popups.actionTypes.BOOT:
// FIXME: $.extend doesn't copy properties whose values are null or
// undefined. If we were to do the following:
//
@ -38,6 +37,43 @@
sessionToken: action.sessionToken,
pageToken: action.pageToken
} );
case mw.popups.actionTypes.LINK_DWELL:
return $.extend( OO.copy( state ), {
activeLink: action.activeLink,
interactionStarted: action.interactionStarted,
isDelayingFetch: true,
linkInteractionToken: action.linkInteractionToken
} );
case mw.popups.actionTypes.LINK_ABANDON:
// Should the action handle dispatching a FETCH_FAILED
// if a new fetch has begun? Or should the reducer?
return $.extend( OO.copy( state ), {
previousActiveLink: state.activeLink,
activeLink: undefined,
interactionStarted: undefined,
isDelayingFetc: false,
linkInteractionToken: undefined
} );
case mw.popups.actionTypes.LINK_CLICK:
return $.extend( OO.copy( state ), {
isDelayingFetch: false
} );
case mw.popups.actionTypes.FETCH_START:
return $.extend( OO.copy( state ), {
isDelayingFetch: false,
isFetching: true,
fetchResponse: undefined
} );
case mw.popups.actionTypes.FETCH_END:
return $.extend( OO.copy( state ), {
isFetching: false,
fetchResponse: action.response
} );
case mw.popups.actionTypes.FETCH_FAILED:
return $.extend( OO.copy( state ), {
isFetching: false,
fetchResponse: action.response // To catch error data if it exists
} );
default:
return state;
}
@ -54,7 +90,7 @@
mw.popups.reducers.renderer = function ( state, action ) {
if ( state === undefined ) {
state = {
isAanimating: false,
isAnimating: false,
isInteractive: false,
showSettings: false
};
@ -63,7 +99,39 @@
switch ( action.type ) {
case mw.popups.actionTypes.PREVIEW_ANIMATING:
return $.extend( {}, state, {
isAnimating: true
isAnimating: true,
isInteractive: false,
showSettings: false
} );
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
} );
default:
return state;

View file

@ -22,7 +22,7 @@
isFetching: false
},
renderer: {
isAanimating: false,
isAnimating: false,
isInteractive: false,
showSettings: false
}
@ -31,7 +31,7 @@
);
} );
QUnit.test( '#model', 1, function ( assert ) {
QUnit.test( '#preview', function ( assert ) {
var state = mw.popups.reducers.preview( undefined, { type: '@@INIT' } ),
action = {
type: 'BOOT',
@ -40,6 +40,8 @@
pageToken: '9876543210'
};
assert.expect( 1 );
assert.deepEqual(
mw.popups.reducers.preview( state, action ),
{
@ -52,7 +54,8 @@
interactionStarted: undefined,
isDelayingFetch: false,
isFetching: false
}
},
'It should set enabled and the session tokens on the BOOT action'
);
} );
@ -60,10 +63,13 @@
assert.expect( 1 );
assert.deepEqual(
// FIXME: There may be more to the action object when this action is implemented
mw.popups.reducers.renderer( {}, { type: 'PREVIEW_ANIMATING' } ),
{ isAnimating: true },
'It should set isAnimating to true when the preview begins rendering.'
{
isAnimating: true,
isInteractive: false,
showSettings: false
},
'It should set isAnimating to true on the PREVIEW_ANIMATING action'
);
} );
}( mediaWiki ) );