mediawiki-extensions-Popups/tests/node-qunit/reducers/statsv.test.js
Stephen Niedzielski ece4670710 Hygiene: use arrow for anonymous functions
In some places, the arrow function seems more natural. This patch
approximates the following with manual amendments:

  find \
    -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \
    -iname \*.js|
  xargs -rd\\n sed -ri 's%function\s*(\([^)]*\))%\1 =>%g'

Files to focus on were identified with:

  rg -slg\!/resources/dist/ -g\!/i18n/ -g\!/doc/ 'this|self|arguments|bind|call|apply|new'|
  xargs -rd\\n git difftool -y

Bug: T165036
Change-Id: Ic66b6000b8fc000f9bfde39749f9cfa69924a13c
2018-03-20 09:27:08 -05:00

139 lines
2.1 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 );
assert.deepEqual( this.initialState, {} );
} );
QUnit.test( 'FETCH_START', function ( assert ) {
var action, state;
assert.expect( 1 );
action = {
type: 'FETCH_START',
timestamp: 123
};
state = statsv( this.initialState, action );
assert.deepEqual(
state,
{
fetchStartedAt: 123
}
);
} );
QUnit.test( 'FETCH_END', ( assert ) => {
var startedAt, endedAt, action, state;
assert.expect( 1 );
startedAt = 200;
endedAt = 500;
action = {
type: 'FETCH_END',
timestamp: endedAt
};
state = statsv( { fetchStartedAt: startedAt }, action );
assert.deepEqual(
state,
{
fetchStartedAt: startedAt,
action: 'timing.PagePreviewsApiResponse',
data: endedAt - startedAt
}
);
} );
QUnit.test( 'FETCH_FAILED', ( assert ) => {
var action, state;
assert.expect( 1 );
action = {
type: 'FETCH_FAILED'
};
state = statsv( {}, action );
assert.deepEqual(
state,
{
action: 'counter.PagePreviewsApiFailure',
data: 1
}
);
} );
QUnit.test( 'LINK_DWELL', ( assert ) => {
var timestamp, action, state;
assert.expect( 1 );
timestamp = 100;
action = {
type: 'LINK_DWELL',
timestamp
};
state = statsv( {}, action );
assert.deepEqual(
state,
{
linkDwellStartedAt: timestamp
}
);
} );
QUnit.test( 'PREVIEW_SHOW', ( assert ) => {
var startedAt, endedAt, action, state;
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
}
);
} );
QUnit.test( 'STATSV_LOGGED', ( assert ) => {
var action, state;
assert.expect( 1 );
action = {
type: 'STATSV_LOGGED'
};
state = statsv( { data: 123 }, action );
assert.deepEqual(
state,
{
action: null,
data: null
}
);
} );