2017-02-15 15:18:59 +00:00
|
|
|
/* global Map: false */
|
|
|
|
|
|
|
|
var stubs = require( './stubs' ),
|
|
|
|
isEnabled = require( '../../src/isEnabled' );
|
|
|
|
|
|
|
|
function createStubUserSettings( isEnabled ) {
|
|
|
|
return {
|
|
|
|
hasIsEnabled: function () {
|
|
|
|
return isEnabled !== undefined;
|
|
|
|
},
|
|
|
|
getIsEnabled: function () {
|
|
|
|
return Boolean( isEnabled );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-27 19:31:34 +00:00
|
|
|
|
2017-02-15 15:18:59 +00:00
|
|
|
QUnit.module( 'ext.popups#isEnabled (logged out)', {
|
|
|
|
setup: function () {
|
|
|
|
this.user = stubs.createStubUser( /* isAnon = */ true );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'is should handle logged out users', function ( assert ) {
|
|
|
|
var user = stubs.createStubUser( /* isAnon = */ true ),
|
|
|
|
cases,
|
|
|
|
i, testCase,
|
|
|
|
userSettings,
|
2017-02-27 19:31:34 +00:00
|
|
|
experiments,
|
2017-02-15 15:18:59 +00:00
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
cases = [
|
2017-02-27 19:31:34 +00:00
|
|
|
[ undefined, true, true, 'When the user hasn\'t enabled or disabled' +
|
|
|
|
' the feature and the user is in the sample.' ],
|
|
|
|
[ undefined, false, false, 'When the user hasn\'t enabled or disabled' +
|
|
|
|
' the feature and the user is not in the sample.' ],
|
|
|
|
[ false, true, false, 'When the user has disabled the feature' +
|
|
|
|
' and the user is in the sample.'],
|
|
|
|
[ false, false, false, 'When the user has disabled the feature' +
|
|
|
|
' and the user is not in the sample.'],
|
|
|
|
[ true, true, true, 'When the user has enabled the feature' +
|
|
|
|
' and the user is in the sample.' ],
|
|
|
|
[ true, false, true, 'When the user has enabled the feature' +
|
|
|
|
' 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 ] );
|
2017-03-07 00:27:38 +00:00
|
|
|
experiments = stubs.createStubExperiments( testCase[ 1 ] );
|
2017-02-15 15:18:59 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2017-02-27 19:31:34 +00:00
|
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
|
|
testCase[ 2 ],
|
|
|
|
testCase[ 3 ]
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
config.set( 'wgPopupsBetaFeature', true );
|
2017-03-07 00:27:38 +00:00
|
|
|
experiments = stubs.createStubExperiments( true );
|
2017-02-27 19:31:34 +00:00
|
|
|
|
|
|
|
assert.notOk(
|
|
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
|
|
' enabled for logged out users when they are in the sample.'
|
|
|
|
);
|
|
|
|
|
2017-03-07 00:27:38 +00:00
|
|
|
experiments = stubs.createStubExperiments( false );
|
2017-02-15 15:18:59 +00:00
|
|
|
|
|
|
|
assert.notOk(
|
2017-02-27 19:31:34 +00:00
|
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
|
|
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
|
|
' enabled for logged out users when they are not in the sample.'
|
2017-02-15 15:18:59 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it should handle logged in users', function ( assert ) {
|
|
|
|
var user = stubs.createStubUser( /* isAnon = */ false ),
|
|
|
|
userSettings = createStubUserSettings( false ),
|
2017-03-07 00:27:38 +00:00
|
|
|
experiments = stubs.createStubExperiments( true ),
|
2017-02-15 15:18:59 +00:00
|
|
|
config = new Map();
|
|
|
|
|
|
|
|
config.set( 'wgPopupsShouldSendModuleToUser', true );
|
|
|
|
|
|
|
|
assert.ok(
|
2017-02-27 19:31:34 +00:00
|
|
|
isEnabled( user, userSettings, config, experiments ),
|
2017-02-15 15:18:59 +00:00
|
|
|
'If the user is logged in and Page Previews has booted, then it\'s enabled.'
|
|
|
|
);
|
2017-02-27 19:31:34 +00:00
|
|
|
|
2017-03-07 00:27:38 +00:00
|
|
|
experiments = stubs.createStubExperiments( false );
|
2017-02-27 19:31:34 +00:00
|
|
|
assert.ok(
|
|
|
|
isEnabled( user, userSettings, config, experiments ),
|
|
|
|
'Anon sampling does not have an affect on logged in users.' +
|
|
|
|
'If the user is logged in and Page Previews has booted, then it\'s enabled.'
|
|
|
|
);
|
2017-02-15 15:18:59 +00:00
|
|
|
} );
|