2017-07-28 17:32:46 +00:00
|
|
|
import preview from '../../../src/reducers/preview';
|
2018-01-11 15:44:26 +00:00
|
|
|
import actionTypes from '../../../src/actionTypes';
|
2017-02-15 15:00:16 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/reducers#preview', {
|
2017-04-25 15:10:11 +00:00
|
|
|
beforeEach: function () {
|
2017-02-15 15:00:16 +00:00
|
|
|
this.el = 'active link';
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
|
|
var state = preview( undefined, { type: '@@INIT' } );
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
enabled: undefined,
|
|
|
|
activeLink: undefined,
|
|
|
|
activeEvent: undefined,
|
|
|
|
activeToken: '',
|
|
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'BOOT', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'BOOT',
|
|
|
|
isEnabled: true
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( {}, action ),
|
|
|
|
{
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
'It should set whether or not previews are enabled.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'SETTINGS_CHANGE', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'SETTINGS_CHANGE',
|
|
|
|
enabled: true
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( {}, action ),
|
|
|
|
{
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
'It should set whether or not previews are enabled when settings change.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'LINK_DWELL initializes the state for a new link', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'LINK_DWELL',
|
|
|
|
el: this.el,
|
|
|
|
event: {},
|
|
|
|
token: '1234567890'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( {}, action ),
|
|
|
|
{
|
|
|
|
activeLink: action.el,
|
|
|
|
activeEvent: action.event,
|
|
|
|
activeToken: action.token,
|
|
|
|
shouldShow: false,
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should set active link and event as well as interaction info and hide the preview.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
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(
|
|
|
|
preview( state, action ),
|
|
|
|
{
|
|
|
|
activeLink: this.el,
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should only set isUserDwelling to true'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'ABANDON_END', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'ABANDON_END',
|
|
|
|
token: 'bananas'
|
|
|
|
},
|
|
|
|
state = {
|
|
|
|
activeToken: 'bananas',
|
|
|
|
isUserDwelling: false
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( state, action ),
|
|
|
|
{
|
|
|
|
activeLink: undefined,
|
|
|
|
activeToken: undefined,
|
|
|
|
activeEvent: undefined,
|
|
|
|
fetchResponse: undefined,
|
|
|
|
isUserDwelling: false,
|
|
|
|
shouldShow: false
|
|
|
|
},
|
|
|
|
'ABANDON_END should hide the preview and reset the interaction info.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activeToken: 'apples',
|
|
|
|
isUserDwelling: true
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
preview( state, action ),
|
|
|
|
state,
|
|
|
|
'ABANDON_END should NOOP if the current interaction has changed.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activeToken: 'bananas',
|
|
|
|
isUserDwelling: true
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
preview( state, action ),
|
|
|
|
state,
|
|
|
|
'ABANDON_END should NOOP if the user is dwelling on the preview.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-03-26 18:19:24 +00:00
|
|
|
QUnit.test( 'FETCH_COMPLETE', function ( assert ) {
|
2017-04-07 12:40:55 +00:00
|
|
|
var token = '1234567890',
|
|
|
|
state = {
|
2017-04-21 10:59:38 +00:00
|
|
|
activeToken: token,
|
|
|
|
isUserDwelling: true
|
2017-02-15 15:00:16 +00:00
|
|
|
},
|
|
|
|
action = {
|
2017-03-26 18:19:24 +00:00
|
|
|
type: 'FETCH_COMPLETE',
|
2017-04-07 12:40:55 +00:00
|
|
|
token: token,
|
2017-02-15 15:00:16 +00:00
|
|
|
result: {}
|
|
|
|
};
|
|
|
|
|
2017-04-21 10:59:38 +00:00
|
|
|
assert.expect( 3 );
|
2017-02-15 15:00:16 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( state, action ),
|
|
|
|
{
|
2017-04-21 10:59:38 +00:00
|
|
|
// Previous state.
|
|
|
|
activeToken: state.activeToken,
|
|
|
|
isUserDwelling: true,
|
2017-02-15 15:00:16 +00:00
|
|
|
|
|
|
|
fetchResponse: action.result,
|
|
|
|
shouldShow: true
|
|
|
|
},
|
|
|
|
'It should store the result and signal that a preview should be rendered.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2017-04-21 10:59:38 +00:00
|
|
|
state = preview( state, {
|
|
|
|
type: 'ABANDON_START',
|
|
|
|
token: token
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( state, action ),
|
|
|
|
{
|
|
|
|
activeToken: token,
|
|
|
|
isUserDwelling: false, // Set when ABANDON_START is reduced.
|
|
|
|
|
|
|
|
fetchResponse: action.result,
|
|
|
|
shouldShow: false
|
|
|
|
},
|
|
|
|
'It shouldn\'t signal that a preview should be rendered if the user has abandoned the link since the gateway request was made.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2017-02-15 15:00:16 +00:00
|
|
|
action = {
|
2017-03-26 18:19:24 +00:00
|
|
|
type: 'FETCH_COMPLETE',
|
2017-04-07 12:40:55 +00:00
|
|
|
token: 'banana',
|
2017-02-15 15:00:16 +00:00
|
|
|
result: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( state, action ),
|
|
|
|
state,
|
2017-04-21 10:59:38 +00:00
|
|
|
'It should NOOP if the user has interacted with another link since the gateway request was made.'
|
2017-02-15 15:00:16 +00:00
|
|
|
);
|
2017-04-21 10:59:38 +00:00
|
|
|
|
2017-02-15 15:00:16 +00:00
|
|
|
} );
|
|
|
|
|
2018-01-11 15:44:26 +00:00
|
|
|
QUnit.test( actionTypes.FETCH_FAILED, function ( assert ) {
|
|
|
|
var token = '1234567890',
|
|
|
|
state = {
|
|
|
|
activeToken: token,
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
action = {
|
|
|
|
type: actionTypes.FETCH_FAILED,
|
|
|
|
token: token
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( state, action ),
|
|
|
|
{
|
|
|
|
// Previous state.
|
|
|
|
activeToken: state.activeToken,
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should store the result and not transition states.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-02-15 15:00:16 +00:00
|
|
|
QUnit.test( 'PREVIEW_DWELL', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'PREVIEW_DWELL'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( {}, action ),
|
|
|
|
{
|
|
|
|
isUserDwelling: true
|
|
|
|
},
|
|
|
|
'It should mark the preview as being dwelled on.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'ABANDON_START', function ( assert ) {
|
|
|
|
var action = {
|
|
|
|
type: 'ABANDON_START'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
preview( {}, action ),
|
|
|
|
{
|
|
|
|
isUserDwelling: false
|
|
|
|
},
|
|
|
|
'ABANDON_START should mark the preview having been abandoned.'
|
|
|
|
);
|
|
|
|
} );
|