2017-07-28 17:32:46 +00:00
|
|
|
import createExperiments from '../../src/experiments';
|
2017-06-14 10:32:29 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/experiments#weightedBoolean' );
|
|
|
|
|
|
|
|
QUnit.test( 'it should call mw.experiments#getBucket', function ( assert ) {
|
2018-03-15 16:30:11 +00:00
|
|
|
let getBucketStub = this.sandbox.stub(),
|
2017-06-14 10:32:29 +00:00
|
|
|
stubMWExperiments = {
|
|
|
|
getBucket: getBucketStub
|
|
|
|
},
|
|
|
|
experiments = createExperiments( stubMWExperiments );
|
|
|
|
|
|
|
|
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' );
|
|
|
|
|
|
|
|
assert.ok( getBucketStub.calledOnce );
|
|
|
|
assert.deepEqual(
|
|
|
|
getBucketStub.getCall( 0 ).args,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
|
|
|
|
name: 'foo',
|
|
|
|
buckets: {
|
|
|
|
'true': 0.2,
|
|
|
|
'false': 0.8 // 1 - 0.2
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'barbaz'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
getBucketStub.returns( 'true' );
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' ),
|
|
|
|
'It should return true if the bucket is "true".'
|
|
|
|
);
|
|
|
|
} );
|