Fix broken tests

The signature of mw.Map was changed in I7ff0b230.

Bug: T150575
Bug: T146432
Change-Id: I464162549ef9b1decafc42f483c35a2c8e930a3b
This commit is contained in:
Gergő Tisza 2016-11-02 22:29:04 +00:00
parent 427e276171
commit 789ccdeae6
2 changed files with 15 additions and 12 deletions

View file

@ -136,9 +136,10 @@
QUnit.test( 'setMediaViewerEnabledOnClick sanity check', 3, function ( assert ) { QUnit.test( 'setMediaViewerEnabledOnClick sanity check', 3, function ( assert ) {
var localStorage = { getItem: this.sandbox.stub(), setItem: this.sandbox.stub(), removeItem: this.sandbox.stub() }, var localStorage = { getItem: this.sandbox.stub(), setItem: this.sandbox.stub(), removeItem: this.sandbox.stub() },
mwUser = { isAnon: this.sandbox.stub() }, mwUser = { isAnon: this.sandbox.stub() },
mwConfig = new mw.Map( { wgMediaViewerEnabledByDefault: false } ), mwConfig = new mw.Map( false ),
api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) }, api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) },
config = new mw.mmv.Config( {}, mwConfig, mwUser, api, localStorage ); config = new mw.mmv.Config( {}, mwConfig, mwUser, api, localStorage );
mwConfig.set( 'wgMediaViewerEnabledByDefault', false );
mwUser.isAnon.returns( false ); mwUser.isAnon.returns( false );
api.postWithToken.returns( $.Deferred().resolve() ); api.postWithToken.returns( $.Deferred().resolve() );
@ -176,15 +177,16 @@
QUnit.test( 'shouldShowStatusInfo', 12, function ( assert ) { QUnit.test( 'shouldShowStatusInfo', 12, function ( assert ) {
var config, var config,
mwConfig = new mw.Map( { mwConfig = new mw.Map( false ),
wgMediaViewer: true,
wgMediaViewerOnClick: true,
wgMediaViewerEnabledByDefault: true
} ),
fakeLocalStorage = mw.mmv.testHelpers.getFakeLocalStorage(), fakeLocalStorage = mw.mmv.testHelpers.getFakeLocalStorage(),
mwUser = { isAnon: this.sandbox.stub() }, mwUser = { isAnon: this.sandbox.stub() },
api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) }; api = { postWithToken: this.sandbox.stub().returns( $.Deferred().resolve() ) };
mwConfig.set( {
wgMediaViewer: true,
wgMediaViewerOnClick: true,
wgMediaViewerEnabledByDefault: true
} );
config = new mw.mmv.Config( {}, mwConfig, mwUser, api, fakeLocalStorage ); config = new mw.mmv.Config( {}, mwConfig, mwUser, api, fakeLocalStorage );
mwUser.isAnon.returns( false ); mwUser.isAnon.returns( false );
@ -194,13 +196,13 @@
config.setMediaViewerEnabledOnClick( true ); config.setMediaViewerEnabledOnClick( true );
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when MMV is enabled' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when MMV is enabled' );
config.setMediaViewerEnabledOnClick( false ); config.setMediaViewerEnabledOnClick( false );
assert.strictEqual( config.shouldShowStatusInfo(), true, 'Status info is shown after MMV is disabled the first time' ); assert.strictEqual( config.shouldShowStatusInfo(), true, 'Status info is shown after MMV is disabled the first time #2' );
config.disableStatusInfo(); config.disableStatusInfo();
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when already displayed once' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when already displayed once' );
config.setMediaViewerEnabledOnClick( true ); config.setMediaViewerEnabledOnClick( true );
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Further status changes have no effect' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Further status changes have no effect' );
config.setMediaViewerEnabledOnClick( false ); config.setMediaViewerEnabledOnClick( false );
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Further status changes have no effect' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Further status changes have no effect #2' );
// make sure disabling calls maybeEnableStatusInfo() for logged-in as well // make sure disabling calls maybeEnableStatusInfo() for logged-in as well
config.localStorage = mw.mmv.testHelpers.getFakeLocalStorage(); config.localStorage = mw.mmv.testHelpers.getFakeLocalStorage();
@ -212,10 +214,10 @@
// make sure popup is not shown immediately on disabled-by-default sites, but still works otherwise // make sure popup is not shown immediately on disabled-by-default sites, but still works otherwise
config.localStorage = mw.mmv.testHelpers.getFakeLocalStorage(); config.localStorage = mw.mmv.testHelpers.getFakeLocalStorage();
mwConfig.set( 'wgMediaViewerEnabledByDefault', false ); mwConfig.set( 'wgMediaViewerEnabledByDefault', false );
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown by default' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown by default #2' );
config.setMediaViewerEnabledOnClick( true ); config.setMediaViewerEnabledOnClick( true );
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when MMV is enabled' ); assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown when MMV is enabled #2' );
config.setMediaViewerEnabledOnClick( false ); config.setMediaViewerEnabledOnClick( false );
assert.strictEqual( config.shouldShowStatusInfo(), true, 'Status info is shown after MMV is disabled the first time' ); assert.strictEqual( config.shouldShowStatusInfo(), true, 'Status info is shown after MMV is disabled the first time #2' );
} ); } );
}( mediaWiki, jQuery ) ); }( mediaWiki, jQuery ) );

View file

@ -35,7 +35,8 @@
* @param {Object} [initialData] * @param {Object} [initialData]
*/ */
MTH.getFakeLocalStorage = function ( initialData ) { MTH.getFakeLocalStorage = function ( initialData ) {
var bag = new mw.Map( initialData ); var bag = new mw.Map( false );
bag.set( initialData );
return { return {
getItem: function ( key ) { return bag.get( key ); }, getItem: function ( key ) { return bag.get( key ); },