2016-11-21 11:08:06 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-11-10 18:02:29 +00:00
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.module( 'ext.popups/reducers#preview', {
|
2016-11-25 12:42:02 +00:00
|
|
|
setup: function () {
|
|
|
|
this.el = $( '<a>' );
|
|
|
|
}
|
|
|
|
} );
|
2016-11-10 18:02:29 +00:00
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
|
|
var state = mw.popups.reducers.preview( undefined, { type: '@@INIT' } );
|
2016-11-10 18:02:29 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
2016-12-13 10:25:17 +00:00
|
|
|
enabled: undefined,
|
|
|
|
activeLink: undefined,
|
|
|
|
activeEvent: undefined,
|
2017-01-08 13:34:51 +00:00
|
|
|
activeToken: '',
|
2016-12-13 10:25:17 +00:00
|
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: false
|
|
|
|
}
|
2016-11-10 18:02:29 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( 'BOOT', function ( assert ) {
|
2016-11-25 12:42:02 +00:00
|
|
|
var action = {
|
2016-11-21 11:08:06 +00:00
|
|
|
type: 'BOOT',
|
2016-12-14 14:24:21 +00:00
|
|
|
isEnabled: true
|
2016-11-21 11:08:06 +00:00
|
|
|
};
|
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
|
|
|
{
|
2016-11-30 13:40:08 +00:00
|
|
|
enabled: true
|
2016-11-16 16:16:43 +00:00
|
|
|
},
|
2016-11-30 13:40:08 +00:00
|
|
|
'It should set whether or not previews are enabled.'
|
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-12-13 18:04:03 +00:00
|
|
|
QUnit.test( 'SETTINGS_CHANGE', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'SETTINGS_CHANGE',
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( {}, action ),
|
|
|
|
{
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
'It should set whether or not previews are enabled when settings change.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-01-10 23:23:40 +00:00
|
|
|
QUnit.test( 'LINK_DWELL initializes the state for a new link', function ( assert ) {
|
2016-11-25 12:42:02 +00:00
|
|
|
var action = {
|
2016-11-21 11:08:06 +00:00
|
|
|
type: 'LINK_DWELL',
|
2016-11-25 12:42:02 +00:00
|
|
|
el: this.el,
|
2017-01-08 13:34:51 +00:00
|
|
|
event: {},
|
|
|
|
token: '1234567890'
|
2016-11-21 11:08:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
2017-01-08 13:34:51 +00:00
|
|
|
activeToken: action.token,
|
2017-01-09 19:08:46 +00:00
|
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: true
|
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
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-01-10 23:23:40 +00:00
|
|
|
QUnit.test( 'LINK_DWELL on an active link only updates dwell state', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'LINK_DWELL',
|
|
|
|
el: this.el,
|
|
|
|
event: {},
|
|
|
|
token: '1234567890'
|
|
|
|
},
|
|
|
|
state = {
|
|
|
|
activeLink: this.el,
|
|
|
|
isUserDwelling: false
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( state, action ),
|
|
|
|
{
|
|
|
|
activeLink: this.el,
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should only set isUserDwelling to true'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( '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,
|
|
|
|
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
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( 'FETCH_END', function ( assert ) {
|
2016-11-25 12:42:02 +00:00
|
|
|
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-12-13 10:25:17 +00:00
|
|
|
QUnit.test( 'PREVIEW_DWELL', function ( assert ) {
|
2016-11-28 12:00:07 +00:00
|
|
|
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.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( 'PREVIEW_ABANDON_START', function ( assert ) {
|
2017-01-09 19:08:46 +00:00
|
|
|
var actions = [ 'PREVIEW_ABANDON_START', 'LINK_ABANDON_START' ];
|
2016-11-28 12:00:07 +00:00
|
|
|
|
2017-01-09 19:08:46 +00:00
|
|
|
$.each( actions, function ( i, testCase ) {
|
|
|
|
var action = {
|
|
|
|
type: testCase
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.preview( {}, action ),
|
|
|
|
{
|
|
|
|
isUserDwelling: false
|
|
|
|
},
|
|
|
|
testCase + ' should mark the preview having been abandoned.'
|
|
|
|
);
|
|
|
|
} );
|
2016-11-28 12:00:07 +00:00
|
|
|
} );
|
|
|
|
|
2016-11-21 11:08:06 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|