2017-07-28 17:32:46 +00:00
|
|
|
import statsv from '../../../src/reducers/statsv';
|
2018-07-13 15:12:49 +00:00
|
|
|
import actionTypes from '../../../src/actionTypes';
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/reducers#eventLogging', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2017-03-07 00:27:38 +00:00
|
|
|
this.initialState = statsv( undefined, {
|
|
|
|
type: '@@INIT'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.deepEqual( this.initialState, {}, 'The initial state is empty.' );
|
2017-03-07 00:27:38 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'FETCH_START', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.FETCH_START,
|
2017-03-07 00:27:38 +00:00
|
|
|
timestamp: 123
|
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( this.initialState, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
fetchStartedAt: 123
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The fetch start time is preserved.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'FETCH_END', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const startedAt = 200;
|
|
|
|
const endedAt = 500;
|
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.FETCH_END,
|
2017-04-25 12:12:36 +00:00
|
|
|
timestamp: endedAt
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( { fetchStartedAt: startedAt }, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
fetchStartedAt: startedAt,
|
|
|
|
action: 'timing.PagePreviewsApiResponse',
|
2017-03-26 19:33:07 +00:00
|
|
|
data: endedAt - startedAt
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The start, action, and data are preserved.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'FETCH_FAILED', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.FETCH_FAILED
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( {}, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
action: 'counter.PagePreviewsApiFailure',
|
|
|
|
data: 1
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The action and data are preserved.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'LINK_DWELL', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const timestamp = 100;
|
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.LINK_DWELL,
|
2018-03-14 19:44:22 +00:00
|
|
|
timestamp
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( {}, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
linkDwellStartedAt: timestamp
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The link dwell start time is preserved.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'PREVIEW_SHOW', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const startedAt = 100;
|
|
|
|
const endedAt = 300;
|
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.PREVIEW_SHOW,
|
2017-03-07 00:27:38 +00:00
|
|
|
timestamp: endedAt
|
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( { linkDwellStartedAt: startedAt }, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
linkDwellStartedAt: startedAt,
|
|
|
|
action: 'timing.PagePreviewsPreviewShow',
|
|
|
|
data: endedAt - startedAt
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The link dwell start time, action, and data are preserved.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'STATSV_LOGGED', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const action = {
|
2018-07-13 15:12:49 +00:00
|
|
|
type: actionTypes.STATSV_LOGGED
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
2018-03-19 19:39:41 +00:00
|
|
|
const state = statsv( { data: 123 }, action );
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
action: null,
|
|
|
|
data: null
|
2018-05-08 19:48:17 +00:00
|
|
|
},
|
|
|
|
'The action and data empty.'
|
2017-03-07 00:27:38 +00:00
|
|
|
);
|
|
|
|
} );
|