mediawiki-extensions-Popups/tests/qunit/ext.popups/reducers.test.js
Jeff Hobson 2215560866 Add reducers
Reducers as a whole are a WIP, but this implements a baseline from which
to add more.

Changes:
 * Create ext.popups.reducers to house all reducers
 * Create reducers for preview and renderer state manipulation
 * Create rootReducer by combining preview and renderer reducers
 * Add QUnit tests for reducers
 * Move action types into ext.popups.actionTypes
 * Extract rootReducer from boot.js

Change-Id: I8a2296c6846cd4b0552a485e671af1d974944195
2016-11-11 19:55:04 +00:00

61 lines
1.3 KiB
JavaScript

( function ( mw ) {
QUnit.module( 'ext.popups/reducers' );
QUnit.test( '#rootReducer', function ( assert ) {
var state = mw.popups.reducers.rootReducer( undefined, { type: '@@INIT' } );
assert.expect( 1 );
assert.deepEqual(
state,
{
preview: {
enabled: false,
activeLink: undefined,
previousActiveLink: undefined,
interactionStarted: undefined,
isDelayingFetch: false,
isFetching: false,
linkInteractionToken: undefined
},
renderer: {
isAanimating: false,
isInteractive: false,
showSettings: false
}
},
'It should initialize the state by default'
);
} );
QUnit.test( '#model', function ( assert ) {
var state = mw.popups.reducers.preview(
{},
{
type: 'BOOT',
isUserInCondition: true
}
);
assert.expect( 1 );
assert.ok(
state.enabled,
'It should set enabled to true when the user is in the enabled condition.'
);
} );
QUnit.test( '#renderer', function ( assert ) {
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.'
);
} );
}( mediaWiki ) );