Jhernandez has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/326516 )
Change subject: Introduce the settings change listener ...................................................................... Introduce the settings change listener Which for the moment is only in charge of showing and hiding the dialog Change-Id: Ib57250236ff424abddb0fa627d2a48167a5d8d74 --- M extension.json A resources/ext.popups/changeListeners/settings.js A tests/qunit/ext.popups/changeListeners/settings.test.js 3 files changed, 86 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups refs/changes/16/326516/1 diff --git a/extension.json b/extension.json index ce1e870..c8cfbbb 100644 --- a/extension.json +++ b/extension.json @@ -74,6 +74,7 @@ "resources/ext.popups/changeListeners/render.js", "resources/ext.popups/changeListeners/eventLogging.js", "resources/ext.popups/changeListeners/previewCount.js", + "resources/ext.popups/changeListeners/settings.js", "resources/ext.popups/boot.js" ], "templates": { diff --git a/resources/ext.popups/changeListeners/settings.js b/resources/ext.popups/changeListeners/settings.js new file mode 100644 index 0000000..589743d --- /dev/null +++ b/resources/ext.popups/changeListeners/settings.js @@ -0,0 +1,24 @@ +( function ( mw ) { + + /** + * Creates an instance of the settings change listener. + * + * @param {Object} boundActions + * @param {Object} render function that renders a jQuery el with the settings + * @return {ext.popups.ChangeListener} + */ + mw.popups.changeListeners.settings = function ( boundActions, render ) { + var settings; + + return function ( prevState, state ) { + if ( state.settings.shouldShow && !settings ) { + settings = render( boundActions ); + settings.show(); + } else if ( !state.settings.shouldShow && settings ) { + settings.hide(); + settings = undefined; + } + }; + }; + +}( mediaWiki ) ); diff --git a/tests/qunit/ext.popups/changeListeners/settings.test.js b/tests/qunit/ext.popups/changeListeners/settings.test.js new file mode 100644 index 0000000..1c06834 --- /dev/null +++ b/tests/qunit/ext.popups/changeListeners/settings.test.js @@ -0,0 +1,61 @@ +( function ( mw ) { + + QUnit.module( 'ext.popups/changeListeners/settings', { + setup: function () { + this.render = this.sandbox.spy(); + this.rendered = { + show: this.sandbox.spy(), + hide: this.sandbox.spy() + }; + this.defaultState = { settings: { shouldShow: false } }; + this.showState = { settings: { shouldShow: true } }; + this.settings = + mw.popups.changeListeners.settings('actions', this.render ); + } + } ); + + QUnit.test( 'it should not create settings when shouldShow is false', function ( assert ) { + this.settings( null, this.defaultState ); + assert.notOk( this.render.called, 'The renderer should not be called' ); + } ); + + QUnit.test( 'it should not create settings when shouldShow keeps being false', function ( assert ) { + this.settings( null, this.defaultState ); + this.settings( this.defaultState, this.defaultState ); + + assert.notOk( this.render.called, 'The renderer should not be called' ); + } ); + + QUnit.test( 'it should create settings when shouldShow becomes true', function ( assert ) { + this.render.withArgs( 'actions' ).returns( this.rendered ); + + this.settings( null, this.defaultState ); + this.settings( this.defaultState, this.showState ); + + assert.ok( this.render.calledWith('actions'), 'The renderer should be called with the actions' ); + assert.ok( this.rendered.show.called, 'The rendered object should be showed' ); + } ); + + QUnit.test( 'it should not create settings when shouldShow keeps being true', function ( assert ) { + this.render.withArgs( 'actions' ).returns( this.rendered ); + + this.settings( null, this.defaultState ); + this.settings( this.defaultState, this.showState ); + this.settings( this.showState, this.showState ); + + assert.ok( this.render.calledOnce, 'The renderer should be called only the first time' ); + assert.ok( this.rendered.show.calledOnce, 'The rendered object should be showed just once' ); + assert.notOk( this.rendered.hide.called, 'The rendered object should not be hidden' ); + } ); + + QUnit.test( 'it should hide settings when shouldShow becomes false', function ( assert ) { + this.render.withArgs( 'actions' ).returns( this.rendered ); + + this.settings( null, this.defaultState ); + this.settings( this.defaultState, this.showState ); + this.settings( this.showState, this.defaultState ); + + assert.ok( this.rendered.hide.calledOnce, 'The rendered object should be hidden' ); + } ); + +}( mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/326516 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib57250236ff424abddb0fa627d2a48167a5d8d74 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Popups Gerrit-Branch: mpga Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits