2018-05-08 19:48:17 +00:00
|
|
|
import { createStubMap } from './stubs';
|
2017-07-28 17:32:46 +00:00
|
|
|
import createUserSettings from '../../src/userSettings';
|
2017-02-28 17:08:38 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/userSettings', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2017-02-28 17:08:38 +00:00
|
|
|
this.storage = createStubMap();
|
2018-05-08 19:48:17 +00:00
|
|
|
this.userSettings = createUserSettings( this.storage );
|
2017-02-28 17:08:38 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-03-31 08:51:54 +00:00
|
|
|
QUnit.test( '#isPagePreviewsEnabled should return false if Page Previews have been disabled', function ( assert ) {
|
|
|
|
this.userSettings.storePagePreviewsEnabled( false );
|
2017-02-28 17:08:38 +00:00
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.notOk(
|
2021-03-31 08:51:54 +00:00
|
|
|
this.userSettings.isPagePreviewsEnabled(),
|
2018-05-08 19:48:17 +00:00
|
|
|
'The user has disabled Page Previews.'
|
|
|
|
);
|
2017-02-28 17:08:38 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2021-03-31 08:51:54 +00:00
|
|
|
this.userSettings.storePagePreviewsEnabled( true );
|
2017-02-28 17:08:38 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2021-03-31 08:51:54 +00:00
|
|
|
this.userSettings.isPagePreviewsEnabled(),
|
|
|
|
'#isPagePreviewsEnabled should return true if Page Previews have been enabled'
|
2017-02-28 17:08:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-03-31 13:04:15 +00:00
|
|
|
QUnit.test( '#isReferencePreviewsEnabled', function ( assert ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
this.storage.get( 'mwe-popups-referencePreviews-enabled' ),
|
|
|
|
null,
|
|
|
|
'Precondition: storage is empty.'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
this.userSettings.isReferencePreviewsEnabled(),
|
|
|
|
'#isReferencePreviewsEnabled should default to true.'
|
|
|
|
);
|
|
|
|
|
|
|
|
this.userSettings.storeReferencePreviewsEnabled( false );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
this.storage.get( 'mwe-popups-referencePreviews-enabled' ),
|
|
|
|
'0',
|
|
|
|
'#storeReferencePreviewsEnabled changes the storage.'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
this.userSettings.isReferencePreviewsEnabled(),
|
|
|
|
'#isReferencePreviewsEnabled is now false.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-02-28 17:08:38 +00:00
|
|
|
QUnit.test( '#getPreviewCount should return the count as a number', function ( assert ) {
|
|
|
|
assert.strictEqual(
|
|
|
|
this.userSettings.getPreviewCount(),
|
|
|
|
0,
|
|
|
|
'#getPreviewCount returns 0 when the storage is empty.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
this.storage.set( 'ext.popups.core.previewCount', false );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
this.userSettings.getPreviewCount(),
|
|
|
|
-1,
|
|
|
|
'#getPreviewCount returns -1 when the storage isn\'t available.'
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
this.storage.set( 'ext.popups.core.previewCount', '111' );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
this.userSettings.getPreviewCount(),
|
2018-05-08 19:48:17 +00:00
|
|
|
111,
|
|
|
|
'#getPreviewCount returns the total.'
|
2017-02-28 17:08:38 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-03-31 08:51:54 +00:00
|
|
|
QUnit.test( '#storePreviewCount should store the count as a string', function ( assert ) {
|
|
|
|
this.userSettings.storePreviewCount( 222 );
|
2017-02-28 17:08:38 +00:00
|
|
|
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.strictEqual(
|
2018-05-08 19:48:17 +00:00
|
|
|
this.storage.get( 'ext.popups.core.previewCount' ),
|
|
|
|
'222',
|
|
|
|
'Storage returns the total as a string.'
|
|
|
|
);
|
2017-02-28 17:08:38 +00:00
|
|
|
} );
|
2017-08-17 16:29:56 +00:00
|
|
|
|
|
|
|
QUnit.test( '#getPreviewCount should override value in storage when is not a number', function ( assert ) {
|
|
|
|
this.storage.set( 'ext.popups.core.previewCount', 'NaN' );
|
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
this.userSettings.getPreviewCount(),
|
|
|
|
0,
|
|
|
|
'#getPreviewCount returns a sane default.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
this.storage.get( 'ext.popups.core.previewCount' ),
|
|
|
|
'0',
|
|
|
|
'Storage returns a sane default as a string.'
|
|
|
|
);
|
2017-08-17 16:29:56 +00:00
|
|
|
} );
|