mediawiki-extensions-Popups/tests/qunit/ext.popups/schema.test.js
Sam Smith 3f2752b039 Initial Popups logging implementation
Action changes:
* Include whether the user is logged in/out and information about the
  current page in the BOOT action.
* Add the EVENT_LOGGED action, which represents the eventLoggined change
  listener logging the queued event.

Reducer changes:
* Move all tokens and timing information from the preview reducer to the
  eventLogging reducer.
* Make the eventLogging reducer reset the state.

Changes:
* Add the mw.popups.createSchema function, which constructs an instance
  of the mw.eventLog.Schema object that can be used to log Popups
  events.
* Add the eventLogging change listener, which logs the queued event.
* Add hand-crafted, artisanal documentation.

Bug: T152225
Change-Id: I8a3f58358b211cc55417dcda7e796fe538e3d910
2016-12-12 13:01:44 +00:00

67 lines
1.6 KiB
JavaScript

( function ( mw ) {
QUnit.module( 'ext.popups/schema', {
setup: function () {
this.config = new mw.Map();
this.config.set( 'wgPopupsSchemaPopupsSamplingRate', 1 );
this.window = {
navigator: {
sendBeacon: function () {}
}
};
// Stub out the mw.eventLog.Schema constructor function.
this.sandbox.stub( mw.eventLog, 'Schema', function () {} );
}
} );
QUnit.test( 'it should use $wgPopupsSchemaPopupsSamplingRate as the sampling rate', function ( assert ) {
assert.expect( 2 );
mw.popups.createSchema( this.config, this.window );
assert.ok( mw.eventLog.Schema.calledWith( 'Popups', 1 ) );
// ---
mw.popups.createSchema( new mw.Map(), this.window );
assert.ok(
mw.eventLog.Schema.calledWith( 'Popups', 0 ),
'If $wgPopupsSchemaPopupsSamplingRate isn\'t set, then the sampling rate should be 0.'
);
} );
QUnit.test( 'it should use a 0 sampling rate when sendBeacon isn\'t supported', function ( assert ) {
var expectedArgs = [ 'Popups', 0 ];
assert.expect( 2 );
mw.popups.createSchema( this.config, { } );
assert.deepEqual( mw.eventLog.Schema.getCall( 0 ).args, expectedArgs );
// ---
mw.popups.createSchema( this.config, {
navigator: {
sendBeacon: 'NOT A FUNCTION'
}
} );
assert.deepEqual( mw.eventLog.Schema.getCall( 1 ).args, expectedArgs );
} );
QUnit.test( 'it should use a 0 sampling rate in a unit testing environment', function ( assert ) {
assert.expect( 1 );
this.window.QUnit = {};
mw.popups.createSchema( this.config, this.window );
assert.ok( mw.eventLog.Schema.calledWith( 'Popups', 0 ) );
} );
}( mediaWiki ) );