resourceloader: Add tests for mw.loader not storing private/user response
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Aug 2019 18:58:40 +0000 (19:58 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Aug 2019 19:36:37 +0000 (20:36 +0100)
This is in preparation for changing the way group indexes are transmitted
between the server and client, to confirm that the behaviour doesn't break.

Change-Id: I1f84c4c407a4eb69b5b9659d768c643d4a83df0d

tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js

index ed1288b..e1b8d55 100644 (file)
                        } );
        } );
 
+       QUnit.test( 'No storing of group=private responses', function ( assert ) {
+               var name = 'test.group.priv';
+
+               // Enable store and stub timeout/idle scheduling
+               this.sandbox.stub( mw.loader.store, 'enabled', true );
+               this.sandbox.stub( window, 'setTimeout', function ( fn ) {
+                       fn();
+               } );
+               this.sandbox.stub( mw, 'requestIdleCallback', function ( fn ) {
+                       fn();
+               } );
+
+               mw.loader.register( name, 'x', [], 'private' );
+               assert.strictEqual( mw.loader.store.get( name ), false, 'Not in store' );
+
+               mw.loader.implement( name, function () {} );
+               return mw.loader.using( name ).then( function () {
+                       assert.strictEqual( mw.loader.getState( name ), 'ready' );
+                       assert.strictEqual( mw.loader.store.get( name ), false, 'Still not in store' );
+               } );
+       } );
+
+       QUnit.test( 'No storing of group=user responses', function ( assert ) {
+               var name = 'test.group.user';
+
+               // Enable store and stub timeout/idle scheduling
+               this.sandbox.stub( mw.loader.store, 'enabled', true );
+               this.sandbox.stub( window, 'setTimeout', function ( fn ) {
+                       fn();
+               } );
+               this.sandbox.stub( mw, 'requestIdleCallback', function ( fn ) {
+                       fn();
+               } );
+
+               mw.loader.register( name, 'y', [], 'user' );
+               assert.strictEqual( mw.loader.store.get( name ), false, 'Not in store' );
+
+               mw.loader.implement( name, function () {} );
+               return mw.loader.using( name ).then( function () {
+                       assert.strictEqual( mw.loader.getState( name ), 'ready' );
+                       assert.strictEqual( mw.loader.store.get( name ), false, 'Still not in store' );
+               } );
+       } );
+
        QUnit.test( 'require()', function ( assert ) {
                mw.loader.register( [
                        [ 'test.require1', '0' ],