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-19 19:39:41 +00:00
|
|
|
const getBucketStub = this.sandbox.stub(),
|
2017-06-14 10:32:29 +00:00
|
|
|
stubMWExperiments = {
|
|
|
|
getBucket: getBucketStub
|
|
|
|
},
|
|
|
|
experiments = createExperiments( stubMWExperiments );
|
|
|
|
|
|
|
|
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' );
|
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getBucketStub.callCount,
|
|
|
|
1,
|
|
|
|
'The bucketer was invoked once.'
|
|
|
|
);
|
2017-06-14 10:32:29 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
getBucketStub.getCall( 0 ).args,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
|
|
|
|
name: 'foo',
|
|
|
|
buckets: {
|
2019-01-17 22:17:27 +00:00
|
|
|
true: 0.2,
|
|
|
|
false: 0.8 // 1 - 0.2
|
2017-06-14 10:32:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'barbaz'
|
2018-05-08 19:48:17 +00:00
|
|
|
],
|
|
|
|
'The bucketer was called with the correct arguments.'
|
2017-06-14 10:32:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
getBucketStub.returns( 'true' );
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' ),
|
|
|
|
'It should return true if the bucket is "true".'
|
|
|
|
);
|
|
|
|
} );
|