2016-11-21 11:08:06 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-11-10 18:02:29 +00:00
|
|
|
|
2016-11-25 12:42:02 +00:00
|
|
|
QUnit.module( 'ext.popups/reducers', {
|
|
|
|
setup: function () {
|
|
|
|
this.el = $( '<a>' );
|
|
|
|
}
|
|
|
|
} );
|
2016-11-10 18:02:29 +00:00
|
|
|
|
|
|
|
QUnit.test( '#rootReducer', function ( assert ) {
|
|
|
|
var state = mw.popups.reducers.rootReducer( undefined, { type: '@@INIT' } );
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
preview: {
|
2016-11-14 19:37:11 +00:00
|
|
|
enabled: undefined,
|
|
|
|
sessionToken: undefined,
|
|
|
|
pageToken: undefined,
|
|
|
|
linkInteractionToken: undefined,
|
2016-11-10 18:02:29 +00:00
|
|
|
activeLink: undefined,
|
2016-11-21 11:08:06 +00:00
|
|
|
activeEvent: undefined,
|
2016-11-25 12:42:02 +00:00
|
|
|
interactionStarted: undefined,
|
|
|
|
shouldShow: false
|
2016-11-10 18:02:29 +00:00
|
|
|
},
|
|
|
|
renderer: {
|
2016-11-16 16:16:43 +00:00
|
|
|
isAnimating: false,
|
2016-11-10 18:02:29 +00:00
|
|
|
isInteractive: false,
|
|
|
|
showSettings: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'It should initialize the state by default'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-11-25 12:42:02 +00:00
|
|
|
QUnit.test( '#preview: BOOT', function ( assert ) {
|
|
|
|
var action = {
|
2016-11-21 11:08:06 +00:00
|
|
|
type: 'BOOT',
|
|
|
|
isUserInCondition: true,
|
|
|
|
sessionToken: '0123456789',
|
|
|
|
pageToken: '9876543210'
|
|
|
|
};
|
2016-11-16 16:16:43 +00:00
|
|
|
|
2016-11-25 12:42:02 +00:00
|
|
|
assert.expect( 1 );
|
|
|
|
|
2016-11-14 19:37:11 +00:00
|
|
|
assert.deepEqual(
|
2016-11-25 12:42:02 +00:00
|
|
|
mw.popups.reducers.preview( {}, action ),
|
2016-11-14 19:37:11 +00:00
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
sessionToken: '0123456789',
|
2016-11-25 10:39:03 +00:00
|
|
|
pageToken: '9876543210'
|
2016-11-16 16:16:43 +00:00
|
|
|
},
|
2016-11-25 12:42:02 +00:00
|
|
|
'It should set enabled and the session tokens.'
|
2016-11-10 18:02:29 +00:00
|
|
|
);
|
2016-11-25 12:42:02 +00:00
|
|
|
} );
|
2016-11-21 11:08:06 +00:00
|
|
|
|
2016-11-25 12:42:02 +00:00
|
|
|
QUnit.test( '#preview: LINK_DWELL', function ( assert ) {
|
|
|
|
var action = {
|
2016-11-21 11:08:06 +00:00
|
|
|
type: 'LINK_DWELL',
|
2016-11-25 12:42:02 +00:00
|
|
|
el: this.el,
|
2016-11-21 11:08:06 +00:00
|
|
|
event: {},
|
|
|
|
interactionStarted: mw.now(),
|
|
|
|
linkInteractionToken: '0123456789'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2016-11-25 12:42:02 +00:00
|
|
|
mw.popups.reducers.preview( {}, action ),
|
2016-11-21 11:08:06 +00:00
|
|
|
{
|
|
|
|
activeLink: action.el,
|
|
|
|
activeEvent: action.event,
|
|
|
|
interactionStarted: action.interactionStarted,
|
|
|
|
linkInteractionToken: action.linkInteractionToken
|
|
|
|
},
|
2016-11-25 12:42:02 +00:00
|
|
|
'It should set active link and event as well as interaction info.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#preview: LINK_ABANDON', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'LINK_ABANDON',
|
|
|
|
el: this.el
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( {}, action ),
|
|
|
|
{
|
|
|
|
activeLink: undefined,
|
|
|
|
activeEvent: undefined,
|
|
|
|
interactionStarted: undefined,
|
|
|
|
linkInteractionToken: undefined,
|
|
|
|
fetchResponse: undefined,
|
|
|
|
shouldShow: false
|
|
|
|
},
|
|
|
|
'It should hide the preview and reset the interaction info.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#preview: FETCH_END', function ( assert ) {
|
|
|
|
var state = {
|
|
|
|
activeLink: this.el
|
|
|
|
},
|
|
|
|
action = {
|
|
|
|
type: 'FETCH_END',
|
|
|
|
el: this.el,
|
|
|
|
result: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 2 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( state, action ),
|
|
|
|
{
|
|
|
|
activeLink: state.activeLink, // Previous state.
|
|
|
|
|
|
|
|
fetchResponse: action.result,
|
|
|
|
shouldShow: true
|
|
|
|
},
|
|
|
|
'It should store the result and signal that a preview should be rendered.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activeLink: $( '<a>' )
|
|
|
|
};
|
|
|
|
action = {
|
|
|
|
type: 'FETCH_END',
|
|
|
|
el: this.el,
|
|
|
|
result: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( state, action ),
|
|
|
|
state,
|
|
|
|
'It should NOOP if the user has interacted with another link since the request was dispatched via the gateway.'
|
2016-11-21 11:08:06 +00:00
|
|
|
);
|
2016-11-10 18:02:29 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#renderer', function ( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.renderer( {}, { type: 'PREVIEW_ANIMATING' } ),
|
2016-11-16 16:16:43 +00:00
|
|
|
{
|
|
|
|
isAnimating: true,
|
|
|
|
isInteractive: false,
|
|
|
|
showSettings: false
|
|
|
|
},
|
|
|
|
'It should set isAnimating to true on the PREVIEW_ANIMATING action'
|
2016-11-10 18:02:29 +00:00
|
|
|
);
|
|
|
|
} );
|
2016-11-21 11:08:06 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|
2016-11-10 18:02:29 +00:00
|
|
|
|