Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.storage.test.js
1 ( function ( mw ) {
2 QUnit.module( 'mediawiki.storage' );
3
4 QUnit.test( 'set/get with localStorage', 3, function ( assert ) {
5 this.sandbox.stub( mw.storage, 'localStorage', {
6 setItem: this.sandbox.spy(),
7 getItem: this.sandbox.stub()
8 } );
9
10 mw.storage.set( 'foo', 'test' );
11 assert.ok( mw.storage.localStorage.setItem.calledOnce );
12
13 mw.storage.localStorage.getItem.withArgs( 'foo' ).returns( 'test' );
14 mw.storage.localStorage.getItem.returns( null );
15 assert.strictEqual( mw.storage.get( 'foo' ), 'test', 'Check value gets stored.' );
16 assert.strictEqual( mw.storage.get( 'bar' ), null, 'Unset values are null.' );
17 } );
18
19 QUnit.test( 'set/get without localStorage', 3, function ( assert ) {
20 this.sandbox.stub( mw.storage, 'localStorage', {
21 getItem: this.sandbox.stub(),
22 removeItem: this.sandbox.stub(),
23 setItem: this.sandbox.stub()
24 } );
25
26 mw.storage.localStorage.getItem.throws();
27 assert.strictEqual( mw.storage.get( 'foo' ), false );
28
29 mw.storage.localStorage.setItem.throws();
30 assert.strictEqual( mw.storage.set( 'foo', 'test' ), false );
31
32 mw.storage.localStorage.removeItem.throws();
33 assert.strictEqual( mw.storage.remove( 'foo', 'test' ), false );
34 } );
35
36 }( mediaWiki ) );