mediawiki-extensions-Popups/tests/node-qunit/reducers/statsv.test.js
Stephen Niedzielski ae44042cbf Hygiene: add assertion messages
Change-Id: Ic0a47bd468532824e8648c3f6371cc403896603c
2018-05-08 15:55:23 -05:00

133 lines
2.6 KiB
JavaScript

import statsv from '../../../src/reducers/statsv';
QUnit.module( 'ext.popups/reducers#eventLogging', {
beforeEach() {
this.initialState = statsv( undefined, {
type: '@@INIT'
} );
}
} );
QUnit.test( '@@INIT', function ( assert ) {
assert.expect( 1, 'All assertions are executed.' );
assert.deepEqual( this.initialState, {}, 'The initial state is empty.' );
} );
QUnit.test( 'FETCH_START', function ( assert ) {
assert.expect( 1, 'All assertions are executed.' );
const action = {
type: 'FETCH_START',
timestamp: 123
};
const state = statsv( this.initialState, action );
assert.deepEqual(
state,
{
fetchStartedAt: 123
},
'The fetch start time is preserved.'
);
} );
QUnit.test( 'FETCH_END', ( assert ) => {
assert.expect( 1, 'All assertions are executed.' );
const startedAt = 200;
const endedAt = 500;
const action = {
type: 'FETCH_END',
timestamp: endedAt
};
const state = statsv( { fetchStartedAt: startedAt }, action );
assert.deepEqual(
state,
{
fetchStartedAt: startedAt,
action: 'timing.PagePreviewsApiResponse',
data: endedAt - startedAt
},
'The start, action, and data are preserved.'
);
} );
QUnit.test( 'FETCH_FAILED', ( assert ) => {
assert.expect( 1, 'All assertions are executed.' );
const action = {
type: 'FETCH_FAILED'
};
const state = statsv( {}, action );
assert.deepEqual(
state,
{
action: 'counter.PagePreviewsApiFailure',
data: 1
},
'The action and data are preserved.'
);
} );
QUnit.test( 'LINK_DWELL', ( assert ) => {
assert.expect( 1, 'All assertions are executed.' );
const timestamp = 100;
const action = {
type: 'LINK_DWELL',
timestamp
};
const state = statsv( {}, action );
assert.deepEqual(
state,
{
linkDwellStartedAt: timestamp
},
'The link dwell start time is preserved.'
);
} );
QUnit.test( 'PREVIEW_SHOW', ( assert ) => {
assert.expect( 1, 'All assertions are executed.' );
const startedAt = 100;
const endedAt = 300;
const action = {
type: 'PREVIEW_SHOW',
timestamp: endedAt
};
const state = statsv( { linkDwellStartedAt: startedAt }, action );
assert.deepEqual(
state,
{
linkDwellStartedAt: startedAt,
action: 'timing.PagePreviewsPreviewShow',
data: endedAt - startedAt
},
'The link dwell start time, action, and data are preserved.'
);
} );
QUnit.test( 'STATSV_LOGGED', ( assert ) => {
assert.expect( 1, 'All assertions are executed.' );
const action = {
type: 'STATSV_LOGGED'
};
const state = statsv( { data: 123 }, action );
assert.deepEqual(
state,
{
action: null,
data: null
},
'The action and data empty.'
);
} );