mediawiki-extensions-Popups/tests/qunit/ext.popups/userSettings.test.js
Sam Smith 19349c0108 Add BOOT action
Changes:
* Make grunt:qunit run all QUnit tests in those modules whose names
  being with "ext.popups".
* Add ext.popups/index.js, which initialises the mw.popups namespace.
* Add ext.popups/userSettings.js, which contains the code that deals
  with interacting with the User Agent's storage.
* Add ext.popups/experiment.js, which contains the code that that
  decides whether or not the user is in the experiment condition.
* Add tests for both units, converting existing tests where appropriate.
* Remove the associated code from ext.popups.core/ext.popups.core.js.
* Finally, dispatch the BOOT action against the store in
  ext.popups/boot.js.

Change-Id: I697207677304bd49c7cfe1d37bb0a4af7810f387
2016-11-09 10:40:59 +00:00

65 lines
1.6 KiB
JavaScript

( function ( mw ) {
QUnit.module( 'ext.popups/userSettings', {
setup: function () {
var stubUser = {
generateRandomSessionId: function () {
return '1234567890';
}
};
this.storage = new mw.Map();
this.userSettings = mw.popups.createUserSettings( this.storage, stubUser );
}
} );
QUnit.test( '#getIsEnabled should return true if the storage is empty', 1, function ( assert ) {
assert.ok( this.userSettings.getIsEnabled() );
} );
QUnit.test( '#getIsEnabled should return false if Link Previews have been disabled', 2, function ( assert ) {
this.userSettings.setIsEnabled( false );
assert.notOk( this.userSettings.getIsEnabled() );
// ---
this.userSettings.setIsEnabled( true );
assert.ok( this.userSettings.getIsEnabled() );
} );
QUnit.test( '#hasIsEnabled', 2, function ( assert ) {
assert.notOk( this.userSettings.hasIsEnabled() );
// ---
this.userSettings.setIsEnabled( false );
assert.ok(
this.userSettings.hasIsEnabled(),
'#hasIsEnabled should return true even if "isEnabled" has been set to falsy.'
);
} );
QUnit.test( '#getToken', 2, function ( assert ) {
var token = this.userSettings.getToken();
assert.ok(
token,
'#getToken should return a token even if the storage is empty.'
);
assert.equal(
this.storage.get( 'PopupsExperimentID' ),
token,
'#getToken persists the token in the storage transparently.'
);
} );
QUnit.test( '#getToken should always return the same token', 1, function ( assert ) {
assert.equal( this.userSettings.getToken(), this.userSettings.getToken() );
} );
}( mediaWiki ) );