2017-02-15 15:18:59 +00:00
|
|
|
/* global Map: false */
|
|
|
|
|
2017-07-28 17:32:46 +00:00
|
|
|
import * as stubs from './stubs';
|
|
|
|
import isEnabled from '../../src/isEnabled';
|
2017-08-10 17:55:26 +00:00
|
|
|
import { BUCKETS } from '../../src/constants';
|
2017-02-15 15:18:59 +00:00
|
|
|
|
|
|
|
function createStubUserSettings( isEnabled ) {
|
|
|
|
return {
|
2018-03-14 22:04:59 +00:00
|
|
|
hasIsEnabled() {
|
2017-02-15 15:18:59 +00:00
|
|
|
return isEnabled !== undefined;
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
getIsEnabled() {
|
2017-02-15 15:18:59 +00:00
|
|
|
return Boolean( isEnabled );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2017-02-15 15:18:59 +00:00
|
|
|
this.user = stubs.createStubUser( /* isAnon = */ true );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'is should handle logged out users', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let user = stubs.createStubUser( /* isAnon = */ true ),
|
2017-02-15 15:18:59 +00:00
|
|
|
cases,
|
|
|
|
i, testCase,
|
|
|
|
userSettings,
|
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
cases = [
|
2017-08-10 17:55:26 +00:00
|
|
|
/*
|
|
|
|
[
|
|
|
|
<isAnon>, <bucket>, <expected value of isEnabled>, <test description>
|
|
|
|
]
|
|
|
|
*/
|
|
|
|
[ undefined, BUCKETS.on, true, 'When the user hasn\'t enabled or disabled' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' the feature and the user is in the sample.' ],
|
2017-08-10 17:55:26 +00:00
|
|
|
[ undefined, BUCKETS.control, false, 'When the user hasn\'t enabled or disabled' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' the feature and the user is not in the sample.' ],
|
2017-08-10 17:55:26 +00:00
|
|
|
[ false, BUCKETS.on, false, 'When the user has disabled the feature' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' and the user is in the sample.' ],
|
2017-08-10 17:55:26 +00:00
|
|
|
[ false, BUCKETS.control, false, 'When the user has disabled the feature' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' and the user is not in the sample.' ],
|
2017-08-10 17:55:26 +00:00
|
|
|
[ true, BUCKETS.on, true, 'When the user has enabled the feature' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' and the user is in the sample.' ],
|
2017-08-10 17:55:26 +00:00
|
|
|
[ true, BUCKETS.control, true, 'When the user has enabled the feature' +
|
2017-04-25 12:12:36 +00:00
|
|
|
' and the user is not in the sample.' ]
|
2017-02-15 15:18:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
|
|
testCase = cases[ i ];
|
|
|
|
userSettings = createStubUserSettings( testCase[ 0 ] );
|
|
|
|
|
|
|
|
assert.equal(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, testCase[ 1 ] ),
|
2017-02-27 19:31:34 +00:00
|
|
|
testCase[ 2 ],
|
|
|
|
testCase[ 3 ]
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
config.set( 'wgPopupsBetaFeature', true );
|
2017-02-27 19:31:34 +00:00
|
|
|
|
|
|
|
assert.notOk(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
2017-02-27 19:31:34 +00:00
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
2017-08-10 17:55:26 +00:00
|
|
|
' enabled for logged out users when they are in the on group.'
|
2017-02-27 19:31:34 +00:00
|
|
|
);
|
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
assert.notOk(
|
|
|
|
isEnabled( user, userSettings, config, BUCKETS.control ),
|
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
|
|
' enabled for logged out users when they are not in the control group.'
|
|
|
|
);
|
2017-02-15 15:18:59 +00:00
|
|
|
|
|
|
|
assert.notOk(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, BUCKETS.off ),
|
2017-02-27 19:31:34 +00:00
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
2017-08-10 17:55:26 +00:00
|
|
|
' enabled for logged out users when they are in the off group.'
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let user = stubs.createStubUser( /* isAnon = */ false ),
|
2017-02-15 15:18:59 +00:00
|
|
|
userSettings = createStubUserSettings( false ),
|
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsShouldSendModuleToUser', true );
|
|
|
|
|
|
|
|
assert.ok(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
|
|
|
'If the user is logged in and the user is in the on group, then it\'s enabled.'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
isEnabled( user, userSettings, config, BUCKETS.control ),
|
|
|
|
'Bucket does not have an affect on logged in users.' +
|
|
|
|
'If the user is logged in and they are in the control group it\'s still enabled.'
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
2017-02-27 19:31:34 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, BUCKETS.off ),
|
|
|
|
'Bucket does not have an affect on logged in users.' +
|
|
|
|
'If the user is logged in and the user is bucketed as off then it\'s still enabled.'
|
2017-02-27 19:31:34 +00:00
|
|
|
);
|
2017-02-15 15:18:59 +00:00
|
|
|
} );
|
2017-04-06 17:07:42 +00:00
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'it should handle the conflict with the Navigation Popups Gadget', ( assert ) => {
|
2018-03-15 16:30:11 +00:00
|
|
|
let user = stubs.createStubUser( /* isAnon = */ false ),
|
2017-04-06 17:07:42 +00:00
|
|
|
userSettings = createStubUserSettings( false ),
|
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsConflictsWithNavPopupGadget', true );
|
|
|
|
|
|
|
|
assert.notOk(
|
2017-08-10 17:55:26 +00:00
|
|
|
isEnabled( user, userSettings, config, BUCKETS.on ),
|
2017-04-06 17:07:42 +00:00
|
|
|
'Page Previews is disabled when it conflicts with the Navigation Popups Gadget.'
|
|
|
|
);
|
|
|
|
|
|
|
|
} );
|