Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmtr order #1735

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2016,8 +2016,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 @@ -2034,7 +2034,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);
});
});
});
Loading