jenkins-bot has submitted this change and it was merged. Change subject: Add EditorApi#prependText ......................................................................
Add EditorApi#prependText This will be used in refactoring PhotoApi in following commits. Change-Id: Iee1b2349a4108bd4de4f3822e0c289d956398e24 --- M javascripts/modules/editor/EditorApi.js M tests/javascripts/modules/editor/test_EditorApi.js 2 files changed, 43 insertions(+), 3 deletions(-) Approvals: Kaldari: Looks good to me, approved jenkins-bot: Verified diff --git a/javascripts/modules/editor/EditorApi.js b/javascripts/modules/editor/EditorApi.js index 5a18714..6f45999 100644 --- a/javascripts/modules/editor/EditorApi.js +++ b/javascripts/modules/editor/EditorApi.js @@ -8,14 +8,14 @@ this.sectionId = options.sectionId; this.oldId = options.oldId; // return an empty section for new pages - this.content = options.isNew ? '' : null; + this.content = options.isNew ? '' : undefined; this.hasChanged = false; }, getContent: function() { var self = this, result = $.Deferred(), options; - if ( this.content !== null ) { + if ( this.content !== undefined ) { result.resolve( this.content ); } else { options = { @@ -67,6 +67,17 @@ }, /** + * Mark content as modified and set text that should be prepended to given + * section when #save is invoked. + * + * @param text String Text to be prepended. + */ + setPrependText: function( text ) { + this.prependtext = text; + this.hasChanged = true; + }, + + /** * Save the new content of the section, previously set using #setContent. * * @param [options.summary] String Optional summary for the edit. @@ -90,7 +101,6 @@ var apiOptions = { action: 'edit', title: self.title, - text: self.content, summary: options.summary, captchaid: options.captchaId, captchaword: options.captchaWord, @@ -99,6 +109,12 @@ starttimestamp: self.timestamp }; + if ( self.content !== undefined ) { + apiOptions.text = self.content; + } else if ( self.prependtext ) { + apiOptions.prependtext = self.prependtext; + } + if ( $.isNumeric( self.sectionId ) ) { apiOptions.section = self.sectionId; } diff --git a/tests/javascripts/modules/editor/test_EditorApi.js b/tests/javascripts/modules/editor/test_EditorApi.js index a1e7fb1..e0f9f16 100644 --- a/tests/javascripts/modules/editor/test_EditorApi.js +++ b/tests/javascripts/modules/editor/test_EditorApi.js @@ -118,6 +118,30 @@ assert.strictEqual( editorApi.hasChanged, false, 'reset hasChanged' ); } ); + QUnit.test( '#save, after #prependText', 2, function( assert ) { + var editorApi = new EditorApi( { title: 'test' } ); + + this.sandbox.stub( editorApi, 'post' ).returns( $.Deferred().resolve( + { edit: { result: 'Success' } } + ) ); + + editorApi.setPrependText( 'abc' ); + editorApi.save( { summary: 'summary' } ).done( function() { + assert.ok( editorApi.post.calledWith( { + action: 'edit', + title: 'test', + prependtext: 'abc', + summary: 'summary', + captchaid: undefined, + captchaword: undefined, + token: 'fake token', + basetimestamp: undefined, + starttimestamp: undefined + } ), 'prepend text' ); + } ); + assert.strictEqual( editorApi.hasChanged, false, 'reset hasChanged' ); + } ); + QUnit.test( '#save, submit CAPTCHA', 2, function( assert ) { var editorApi = new EditorApi( { title: 'test', sectionId: 1 } ); -- To view, visit https://gerrit.wikimedia.org/r/114366 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iee1b2349a4108bd4de4f3822e0c289d956398e24 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: JGonera <jgon...@wikimedia.org> Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits