summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js')
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js
new file mode 100644
index 00000000..6cef4a7c
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.storage.test.js
@@ -0,0 +1,36 @@
+( function ( mw ) {
+ QUnit.module( 'mediawiki.storage' );
+
+ QUnit.test( 'set/get with localStorage', 3, function ( assert ) {
+ this.sandbox.stub( mw.storage, 'localStorage', {
+ setItem: this.sandbox.spy(),
+ getItem: this.sandbox.stub()
+ } );
+
+ mw.storage.set( 'foo', 'test' );
+ assert.ok( mw.storage.localStorage.setItem.calledOnce );
+
+ mw.storage.localStorage.getItem.withArgs( 'foo' ).returns( 'test' );
+ mw.storage.localStorage.getItem.returns( null );
+ assert.strictEqual( mw.storage.get( 'foo' ), 'test', 'Check value gets stored.' );
+ assert.strictEqual( mw.storage.get( 'bar' ), null, 'Unset values are null.' );
+ } );
+
+ QUnit.test( 'set/get without localStorage', 3, function ( assert ) {
+ this.sandbox.stub( mw.storage, 'localStorage', {
+ getItem: this.sandbox.stub(),
+ removeItem: this.sandbox.stub(),
+ setItem: this.sandbox.stub()
+ } );
+
+ mw.storage.localStorage.getItem.throws();
+ assert.strictEqual( mw.storage.get( 'foo' ), false );
+
+ mw.storage.localStorage.setItem.throws();
+ assert.strictEqual( mw.storage.set( 'foo', 'test' ), false );
+
+ mw.storage.localStorage.removeItem.throws();
+ assert.strictEqual( mw.storage.remove( 'foo', 'test' ), false );
+ } );
+
+}( mediaWiki ) );