2017-06-14 11:00:01 +00:00
|
|
|
var isEnabled = require( '../../src/schema' ).isEnabled,
|
|
|
|
stubs = require( './stubs' );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/schema', {
|
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-06-14 11:00:01 +00:00
|
|
|
QUnit.test( 'it should use a 0 bucketing rate when sendBeacon isn\'t supported', function ( assert ) {
|
|
|
|
var window = {};
|
|
|
|
|
|
|
|
isEnabled( this.user, this.config, this.experiments, window );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
this.experiments.weightedBoolean.getCall( 0 ).args[ 1 ],
|
|
|
|
/* trueWeight = */ 0
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
window.navigator = {
|
|
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
|
|
};
|
|
|
|
|
|
|
|
isEnabled( this.user, this.config, this.experiments, window );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
this.experiments.weightedBoolean.getCall( 1 ).args[ 1 ],
|
|
|
|
/* trueWeight = */ 0
|
|
|
|
);
|
|
|
|
} );
|
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
|
|
|
} );
|