2017-06-15 12:15:46 +00:00
|
|
|
var isEnabled = require( '../../../src/instrumentation/eventLogging' ).isEnabled,
|
|
|
|
stubs = require( '../stubs' );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-15 12:15:46 +00:00
|
|
|
QUnit.module( 'ext.popups/instrumentation/eventLogging', {
|
2017-04-25 15:10:11 +00:00
|
|
|
beforeEach: function () {
|
2017-06-14 11:00:01 +00:00
|
|
|
this.config = stubs.createStubMap();
|
2017-02-28 17:32:35 +00:00
|
|
|
|
|
|
|
this.config.set( 'wgPopupsSchemaSamplingRate', 1 );
|
|
|
|
|
|
|
|
this.window = {
|
|
|
|
navigator: {
|
|
|
|
sendBeacon: function () {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.experiments = {
|
|
|
|
weightedBoolean: this.sandbox.stub()
|
|
|
|
};
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.user = stubs.createStubUser();
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
// Helper function that DRYs up the tests below.
|
|
|
|
this.isEnabled = function () {
|
|
|
|
return isEnabled(
|
|
|
|
this.user,
|
|
|
|
this.config,
|
|
|
|
this.experiments,
|
|
|
|
this.window
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
QUnit.test( 'it should use wgPopupsSchemaSamplingRate as the sampling rate', function ( assert ) {
|
|
|
|
this.isEnabled();
|
|
|
|
|
|
|
|
assert.ok( this.experiments.weightedBoolean.calledOnce );
|
|
|
|
assert.deepEqual(
|
|
|
|
this.experiments.weightedBoolean.getCall( 0 ).args,
|
|
|
|
[
|
|
|
|
'ext.Popups.instrumentation.eventLogging',
|
|
|
|
this.config.get( 'wgPopupsSchemaSamplingRate' ),
|
|
|
|
this.user.sessionId()
|
|
|
|
]
|
|
|
|
);
|
2017-02-28 17:32:35 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.config.delete( 'wgPopupsSchemaSamplingRate' );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.isEnabled();
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
this.experiments.weightedBoolean.getCall( 1 ).args[ 1 ],
|
|
|
|
0,
|
|
|
|
'The bucketing rate should be 0 by default.'
|
2017-02-28 17:32:35 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-07-03 12:05:00 +00:00
|
|
|
QUnit.test( 'it should return false when sendBeacon isn\'t supported', function ( assert ) {
|
2017-06-14 11:00:01 +00:00
|
|
|
var window = {};
|
|
|
|
|
2017-07-03 12:05:00 +00:00
|
|
|
assert.notOk( isEnabled( this.user, this.config, this.experiments, window ) );
|
2017-06-14 11:00:01 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
window.navigator = {
|
|
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
|
|
};
|
|
|
|
|
2017-07-03 12:05:00 +00:00
|
|
|
assert.notOk( isEnabled( this.user, this.config, this.experiments, window ) );
|
2017-06-14 11:00:01 +00:00
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
QUnit.test( 'it should return the weighted boolean', function ( assert ) {
|
|
|
|
this.experiments.weightedBoolean.returns( true );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
assert.ok( this.isEnabled() );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.experiments.weightedBoolean.returns( false );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
assert.notOk( this.isEnabled() );
|
2017-02-28 17:32:35 +00:00
|
|
|
} );
|
2017-06-30 16:19:39 +00:00
|
|
|
|
|
|
|
QUnit.test( 'it should respect the debug flag', function ( assert ) {
|
|
|
|
this.config.set( 'wgPopupsSchemaSamplingRate', 0 );
|
|
|
|
this.config.set( 'debug', false );
|
|
|
|
assert.notOk( this.isEnabled() );
|
|
|
|
|
|
|
|
this.config.set( 'debug', true );
|
|
|
|
assert.ok( this.isEnabled() );
|
|
|
|
} );
|