Skip to content

Commit

Permalink
Rmtr order (#1735)
Browse files Browse the repository at this point in the history
* Change placement order at RMTR

* Fix newline issues

* level 4 heading

* add tests, always add exactly 1 empty line

* comment

---------

Co-authored-by: NovemLinguae <[email protected]>
  • Loading branch information
Trialpearswiki and NovemLinguae authored Aug 10, 2023
1 parent 466443f commit 7133c38
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,8 @@ Twinkle.xfd.callbacks = {
var params = pageobj.getCallbackParameters();
var statelem = pageobj.getStatusElement();

var hiddenCommentRE = /==== ?Uncontroversial technical requests ?====(?:.|\n)*? -->/i;
var newtext = text.replace(hiddenCommentRE, '$&\n' + Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params));
var discussionWikitext = Twinkle.xfd.callbacks.getDiscussionWikitext('rm', params);
var newtext = Twinkle.xfd.insertRMTR(text, discussionWikitext);
if (text === newtext) {
statelem.error('failed to find target spot for the entry');
return;
Expand All @@ -2040,7 +2040,16 @@ Twinkle.xfd.callbacks = {
}
};


/**
* Given the wikitext of the WP:RM/TR page and the wikitext to insert, insert it at the bottom of the ==== Uncontroversial technical requests ==== section.
* @param {String} pageWikitext
* @param {String} wikitextToInsert Will typically be `{{subst:RMassist|1=From|2=To|reason=Reason}}`, which expands out to `* {{RMassist/core | 1 = From | 2 = To | discuss = yes | reason = Reason | sig = Signature | requester = YourUserName}}`
* @return {String} pageWikitext
*/
Twinkle.xfd.insertRMTR = function(pageWikitext, wikitextToInsert) {
var placementRE = /\n{1,}(==== ?Requests to revert undiscussed moves ?====)/i;
return pageWikitext.replace(placementRE, '\n' + wikitextToInsert + '\n\n$1');
};

Twinkle.xfd.callback.evaluate = function(e) {
var form = e.target;
Expand Down
1 change: 1 addition & 0 deletions tests/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mw.config.set({
require('../morebits.js');
require('../twinkle.js');
require('../modules/twinklewarn.js');
require('../modules/twinklexfd.js');
global.Morebits = window.Morebits;

global.assert = require('assert');
Expand Down
110 changes: 110 additions & 0 deletions tests/twinklexfd.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
describe('modules/twinklexfd', () => {
describe('insertRMTR', () => {
test('0 rows, 1 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('0 rows, 1 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('0 rows, 2 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('1 rows, 0 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('2 rows, 0 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
* {{RMassist/core3}}
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
* {{RMassist/core3}}
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('1 rows, 1 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});

test('1 rows, 2 line breaks', () => {
const pageWikitext =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
==== Requests to revert undiscussed moves ====`;
const wikitextToInsert = `* {{RMassist/core}}`;
const expected =
`<!-- Insert the following code below, filling in page names and reason: {{subst:RMassist| current page title | new title | reason = reason for move}} and enter on a new line, at the bottom of the existing list; do not add spare lines between entries; do not add a bullet point; if you do not wish the request to be converted into an RM if contested, then add |discuss=no -->
* {{RMassist/core2}}
* {{RMassist/core}}
==== Requests to revert undiscussed moves ====`;
expect(Twinkle.xfd.insertRMTR(pageWikitext, wikitextToInsert)).toBe(expected);
});
});
});

0 comments on commit 7133c38

Please sign in to comment.