2017-07-28 17:32:46 +00:00
|
|
|
import statsv from '../../../src/reducers/statsv';
|
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 ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
assert.deepEqual( this.initialState, {} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'FETCH_START', function ( assert ) {
|
2018-03-15 16:30:11 +00:00
|
|
|
let action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
action = {
|
|
|
|
type: 'FETCH_START',
|
|
|
|
timestamp: 123
|
|
|
|
};
|
|
|
|
state = statsv( this.initialState, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
fetchStartedAt: 123
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'FETCH_END', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let startedAt, endedAt, action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
startedAt = 200;
|
|
|
|
endedAt = 500;
|
|
|
|
action = {
|
2017-03-26 19:33:07 +00:00
|
|
|
type: 'FETCH_END',
|
2017-04-25 12:12:36 +00:00
|
|
|
timestamp: endedAt
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
|
|
|
state = statsv( { fetchStartedAt: startedAt }, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
fetchStartedAt: startedAt,
|
|
|
|
action: 'timing.PagePreviewsApiResponse',
|
2017-03-26 19:33:07 +00:00
|
|
|
data: endedAt - startedAt
|
2017-03-07 00:27:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'FETCH_FAILED', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
action = {
|
|
|
|
type: 'FETCH_FAILED'
|
|
|
|
};
|
|
|
|
state = statsv( {}, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
action: 'counter.PagePreviewsApiFailure',
|
|
|
|
data: 1
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'LINK_DWELL', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let timestamp, action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
timestamp = 100;
|
|
|
|
action = {
|
|
|
|
type: 'LINK_DWELL',
|
2018-03-14 19:44:22 +00:00
|
|
|
timestamp
|
2017-03-07 00:27:38 +00:00
|
|
|
};
|
|
|
|
state = statsv( {}, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
linkDwellStartedAt: timestamp
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'PREVIEW_SHOW', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let startedAt, endedAt, action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
startedAt = 100;
|
|
|
|
endedAt = 300;
|
|
|
|
action = {
|
|
|
|
type: 'PREVIEW_SHOW',
|
|
|
|
timestamp: endedAt
|
|
|
|
};
|
|
|
|
state = statsv( { linkDwellStartedAt: startedAt }, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
linkDwellStartedAt: startedAt,
|
|
|
|
action: 'timing.PagePreviewsPreviewShow',
|
|
|
|
data: endedAt - startedAt
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'STATSV_LOGGED', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let action, state;
|
2017-03-07 00:27:38 +00:00
|
|
|
|
|
|
|
assert.expect( 1 );
|
|
|
|
|
|
|
|
action = {
|
|
|
|
type: 'STATSV_LOGGED'
|
|
|
|
};
|
|
|
|
state = statsv( { data: 123 }, action );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state,
|
|
|
|
{
|
|
|
|
action: null,
|
|
|
|
data: null
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|