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,
|
2016-11-28 12:00:07 +00:00
|
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: 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,
|
2016-11-28 12:00:07 +00:00
|
|
|
linkInteractionToken: action.linkInteractionToken,
|
|
|
|
shouldShow: false
|
2016-11-21 11:08:06 +00:00
|
|
|
},
|
2016-11-28 12:00:07 +00:00
|
|
|
'It should set active link and event as well as interaction info and hide the preview.'
|
2016-11-25 12:42:02 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-11-28 12:00:07 +00:00
|
|
|
QUnit.test( '#preview: LINK_ABANDON_END', function ( assert ) {
|
2016-11-25 12:42:02 +00:00
|
|
|
var action = {
|
2016-11-28 12:00:07 +00:00
|
|
|
type: 'LINK_ABANDON_END',
|
|
|
|
el: this.el
|
|
|
|
},
|
|
|
|
state = {
|
|
|
|
activeLink: this.el
|
|
|
|
};
|
2016-11-25 12:42:02 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
2016-11-28 12:00:07 +00:00
|
|
|
mw.popups.reducers.preview( state, action ),
|
2016-11-25 12:42:02 +00:00
|
|
|
{
|
|
|
|
activeLink: undefined,
|
|
|
|
activeEvent: undefined,
|
|
|
|
interactionStarted: undefined,
|
|
|
|
linkInteractionToken: undefined,
|
|
|
|
fetchResponse: undefined,
|
|
|
|
shouldShow: false
|
|
|
|
},
|
|
|
|
'It should hide the preview and reset the interaction info.'
|
|
|
|
);
|
2016-11-28 12:00:07 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activeLink: this.el,
|
|
|
|
isUserDwelling: true
|
|
|
|
};
|
|
|
|
|
2016-12-01 09:58:49 +00:00
|
|
|
assert.equal(
|
2016-11-28 12:00:07 +00:00
|
|
|
mw.popups.reducers.preview( state, action ),
|
|
|
|
state,
|
|
|
|
'It should NOOP if the user is dwelling on the preview.'
|
|
|
|
);
|
2016-11-25 12:42:02 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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
|
|
|
} );
|
|
|
|
|
2016-11-28 12:00:07 +00:00
|
|
|
QUnit.test( '#preview: PREVIEW_DWELL', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'PREVIEW_DWELL'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( {}, action ),
|
|
|
|
{
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should mark the preview as being dwelled on.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#preview: PREVIEW_ABANDON_START', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'PREVIEW_ABANDON_START'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( {}, action ),
|
|
|
|
{
|
|
|
|
isUserDwelling: false
|
|
|
|
},
|
|
|
|
'It should mark the preview having been abandoned.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
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-28 12:00:07 +00:00
|
|
|
|
2016-11-21 11:08:06 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|
2016-11-10 18:02:29 +00:00
|
|
|
|