From 94cdb9d87cbc563b476ca0fb81dcd55cecc37ea5 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Sat, 7 Dec 2024 18:58:05 -0800 Subject: [PATCH] block: add regression test regression test for #2106 --- modules/twinkleblock.js | 25 ++++++++++++++++++------- tests/jest.setup.js | 1 + tests/twinkleblock.test.js | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 tests/twinkleblock.test.js diff --git a/modules/twinkleblock.js b/modules/twinkleblock.js index 16c39050c..8e831dab0 100644 --- a/modules/twinkleblock.js +++ b/modules/twinkleblock.js @@ -1899,13 +1899,14 @@ Twinkle.block.callback.issue_template = function twinkleblockCallbackIssueTempla // "talk page" of an IP range (which does not exist) const userTalkPage = 'User_talk:' + mw.config.get('wgRelevantUserName'); - const params = $.extend(formData, { - messageData: Twinkle.block.blockPresetsInfo[formData.template], - reason: Twinkle.block.field_template_options.block_reason, - disabletalk: Twinkle.block.field_template_options.notalk, - noemail: Twinkle.block.field_template_options.noemail_template, - nocreate: Twinkle.block.field_template_options.nocreate_template - }); + const params = Twinkle.block.callback.combineFormDataAndFieldTemplateOptions( + formData, + Twinkle.block.blockPresetsInfo[formData.template], + Twinkle.block.field_template_options.block_reason, + Twinkle.block.field_template_options.notalk, + Twinkle.block.field_template_options.noemail_template, + Twinkle.block.field_template_options.nocreate_template + ); Morebits.wiki.actionCompleted.redirect = userTalkPage; Morebits.wiki.actionCompleted.notice = 'Actions complete, loading user talk page in a few seconds'; @@ -1915,6 +1916,16 @@ Twinkle.block.callback.issue_template = function twinkleblockCallbackIssueTempla wikipedia_page.load(Twinkle.block.callback.main); }; +Twinkle.block.callback.combineFormDataAndFieldTemplateOptions = function(formData, messageData, reason, disabletalk, noemail, nocreate) { + return $.extend(formData, { + messageData: messageData, + reason: reason, + disabletalk: disabletalk, + noemail: noemail, + nocreate: nocreate + }); +}; + Twinkle.block.callback.getBlockNoticeWikitext = function(params) { let text = '{{', settings = Twinkle.block.blockPresetsInfo[params.template]; if (!settings.nonstandard) { diff --git a/tests/jest.setup.js b/tests/jest.setup.js index b3d3c7790..f25aeb8c4 100644 --- a/tests/jest.setup.js +++ b/tests/jest.setup.js @@ -6,6 +6,7 @@ mw.config.set({ require('../morebits.js'); require('../twinkle.js'); +require('../modules/twinkleblock.js'); require('../modules/twinklewarn.js'); require('../modules/twinklexfd.js'); global.Morebits = window.Morebits; diff --git a/tests/twinkleblock.test.js b/tests/twinkleblock.test.js new file mode 100644 index 000000000..05c17154c --- /dev/null +++ b/tests/twinkleblock.test.js @@ -0,0 +1,15 @@ +describe('modules/twinkleblock', () => { + describe('callback.combineFormDataAndFieldTemplateOptions', () => { + // https://github.com/wikimedia-gadgets/twinkle/issues/2106 + test('regression test: merging true and undefined should return true', () => { + const formData = {disabletalk: true}; + const messageData = undefined; + const reason = undefined; + const disabletalk = undefined; + const noemail = undefined; + const nocreate = undefined; + const expected = {disabletalk: true}; + expect(Twinkle.block.callback.combineFormDataAndFieldTemplateOptions(formData, messageData, reason, disabletalk, noemail, nocreate)).toStrictEqual(expected); + }); + }); +});