mediawiki-extensions-Popups/tests/node-qunit/reducers/statsv.test.js
joakin e6081106f1 Use EcmaScript modules instead of common.js modules
Why: Because they are the approved standard by TC39 and Ecma for
JavaScript modules.

Changes:
  * Wrap mw-node-qunit in run.js to register babel to transpile modules
    for node v6
  * Change all sources in src/ to use ES modules
    * Change constants.js to be able to run without
      jQuery.bracketedDevicePixelRatio given ES modules are hoisted to
      the top by spec so we can't patch globals before importing it
  * Change all tests in tests/node-qunit/ to use ES modules
  * Drop usage of mock-require given ES modules are easy to stub with
    sinon

Additional changes:
  * Rename tests/node-qunit/renderer.js to renderer.test.js to follow
    the convention of all the other files
  * Make npm run test:node run only .test.js test files so that it
    doesn't run the stubs.js or run.js file.

Bug: T171951
Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
2017-07-31 23:05:44 +00:00

139 lines
2.2 KiB
JavaScript

import statsv from '../../../src/reducers/statsv';
QUnit.module( 'ext.popups/reducers#eventLogging', {
beforeEach: function () {
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', function ( 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', function ( 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', function ( assert ) {
var timestamp, action, state;
assert.expect( 1 );
timestamp = 100;
action = {
type: 'LINK_DWELL',
timestamp: timestamp
};
state = statsv( {}, action );
assert.deepEqual(
state,
{
linkDwellStartedAt: timestamp
}
);
} );
QUnit.test( 'PREVIEW_SHOW', function ( 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', function ( assert ) {
var action, state;
assert.expect( 1 );
action = {
type: 'STATSV_LOGGED'
};
state = statsv( { data: 123 }, action );
assert.deepEqual(
state,
{
action: null,
data: null
}
);
} );