diff --git a/resources/ext.popups/reducers.js b/resources/ext.popups/reducers.js index bb9993dab..093ab98f6 100644 --- a/resources/ext.popups/reducers.js +++ b/resources/ext.popups/reducers.js @@ -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; diff --git a/tests/qunit/ext.popups/reducers.test.js b/tests/qunit/ext.popups/reducers.test.js index 31416ee0d..f5e0e714b 100644 --- a/tests/qunit/ext.popups/reducers.test.js +++ b/tests/qunit/ext.popups/reducers.test.js @@ -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 ) );