2 QUnit
.module( 'mediawiki.storage: normal case.', {
4 this.sandbox
.stub( mw
.storage
, 'isLocalStorageSupported', true );
5 this.spy
= this.sandbox
.spy( localStorage
, 'setItem' );
6 this.sandbox
.stub( localStorage
, 'getItem' )
7 .withArgs( 'foo' ).returns( 'test' )
8 .withArgs( 'bar' ).returns( null );
12 QUnit
.test( 'set/get with localStorage', 4, function ( assert
) {
13 mw
.storage
.set( 'foo', 'test' );
14 assert
.strictEqual( this.spy
.calledOnce
, true, 'Check localStorage called.' );
15 assert
.strictEqual( this.spy
.calledWith( 'foo', 'test' ), true,
17 assert
.strictEqual( mw
.storage
.get( 'foo' ), 'test', 'Check value gets stored.' );
18 assert
.strictEqual( mw
.storage
.get( 'bar' ), null, 'Unset values are null.' );
21 QUnit
.module( 'mediawiki.storage: localStorage does not exist', {
23 this.sandbox
.stub( mw
.storage
, 'isLocalStorageSupported', false );
24 this.sandbox
.stub( localStorage
, 'setItem' ).throws();
28 QUnit
.test( 'set/get without localStorage', 3, function ( assert
) {
29 assert
.strictEqual( mw
.storage
.set( 'foo', 'test' ), false,
30 'When localStorage not available save fails.' );
32 assert
.strictEqual( mw
.storage
.remove( 'foo', 'test' ), false,
33 'When localStorage not available remove fails.' );
35 assert
.strictEqual( mw
.storage
.get( 'foo' ), false,
36 'Inability to retrieve values return false to differentiate from null (not set).' );
39 QUnit
.module( 'mediawiki.storage: localStorage exhausted', {
41 this.sandbox
.stub( mw
.storage
, 'isLocalStorageSupported', true );
42 this.sandbox
.stub( localStorage
, 'setItem' ).throws();
43 this.sandbox
.stub( localStorage
, 'getItem' ).returns( null );
47 QUnit
.test( 'set/get without localStorage', 2, function ( assert
) {
48 assert
.strictEqual( mw
.storage
.set( 'foo', 'test' ), false,
49 'When localStorage not available inform user with false.' );
50 assert
.strictEqual( mw
.storage
.get( 'foo' ), null, 'No value registered.' );