Skip to content

Commit

Permalink
block: add regression test
Browse files Browse the repository at this point in the history
regression test for wikimedia-gadgets#2106
  • Loading branch information
NovemLinguae committed Dec 8, 2024
1 parent 5152750 commit 94cdb9d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
25 changes: 18 additions & 7 deletions modules/twinkleblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tests/twinkleblock.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 94cdb9d

Please sign in to comment.