Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.experiments.test.js
blob774b2053710d4163ea2452fccab19297fcd11df0
1 ( function ( mw ) {
3         var getBucket = mw.experiments.getBucket;
5         function createExperiment() {
6                 return {
7                         name: 'experiment',
8                         enabled: true,
9                         buckets: {
10                                 control: 0.25,
11                                 A: 0.25,
12                                 B: 0.25,
13                                 C: 0.25
14                         }
15                 };
16         }
18         QUnit.module( 'mediawiki.experiments' );
20         QUnit.test( 'getBucket( experiment, token )', 4, function ( assert ) {
21                 var experiment = createExperiment(),
22                         token = '123457890';
24                 assert.equal(
25                         getBucket( experiment, token ),
26                         getBucket( experiment, token ),
27                         'It returns the same bucket for the same experiment-token pair.'
28                 );
30                 // --------
31                 experiment = createExperiment();
32                 experiment.buckets = {
33                         A: 0.314159265359
34                 };
36                 assert.equal(
37                         'A',
38                         getBucket( experiment, token ),
39                         'It returns the bucket if only one is defined.'
40                 );
42                 // --------
43                 experiment = createExperiment();
44                 experiment.enabled = false;
46                 assert.equal(
47                         'control',
48                         getBucket( experiment, token ),
49                         'It returns "control" if the experiment is disabled.'
50                 );
52                 // --------
53                 experiment = createExperiment();
54                 experiment.buckets = {};
56                 assert.equal(
57                         'control',
58                         getBucket( experiment, token ),
59                         'It returns "control" if the experiment doesn\'t have any buckets.'
60                 );
61         } );
63 }( mediaWiki ) );