Skip to content

Commit

Permalink
Merge branch 'master' into tests-new-cap
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored Dec 12, 2024
2 parents f9da103 + c7b2abe commit bcd6535
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 135 deletions.
11 changes: 1 addition & 10 deletions tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,8 @@
"space-in-parens": "off",

"camelcase": "warn",
"comma-dangle": "warn",
"eol-last": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"no-trailing-spaces": "warn",
"no-undef": "warn",
"no-useless-escape": "warn",
"no-var": "warn",
"semi": "warn",
"strict": "warn",
"quotes": "warn",
"unicorn/prefer-date-now": "warn"
"strict": "warn"
}
}
6 changes: 3 additions & 3 deletions tests/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tweak some mw.configs as needed by tests
mw.config.set({
wgPageName: 'Macbeth,_King_of_Scotland',
wgUserGroups: ['interface-admin', 'sysop', '*', 'user', 'autoconfirmed'],
wgUserGroups: ['interface-admin', 'sysop', '*', 'user', 'autoconfirmed']
});

require('../morebits.js');
Expand All @@ -20,9 +20,9 @@ assert.true = function (arg, message) {
if (arg !== true) {
throw new Error(message);
}
}
};
assert.false = function (arg, message) {
if (arg !== false) {
throw new Error(message);
}
}
};
14 changes: 7 additions & 7 deletions tests/morebits.batchOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ describe('Morebits.batchOperation', () => {
test('Contruction', () => {
assert.true(new Morebits.BatchOperation() instanceof Morebits.batchOperation, 'Correct instance');
});
var batch = new Morebits.BatchOperation();
var pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest'];
const batch = new Morebits.BatchOperation();
const pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest'];
batch.setPageList(pageList);
var chunkLength = 2;
const chunkLength = 2;
batch.setOption('chunkSize', chunkLength);
test('Run', () => {
var all = '';
var runFunc = function (page) {
let all = '';
const runFunc = function (page) {
all += page;
batch.workerSuccess();
};
Expand All @@ -18,8 +18,8 @@ describe('Morebits.batchOperation', () => {
});
// Will leave a run hanging, who cares?
test('Chunksize', () => {
var list = [];
var runFunc = function (page) {
const list = [];
const runFunc = function (page) {
list.push(page);
};
batch.run(runFunc);
Expand Down
8 changes: 4 additions & 4 deletions tests/morebits.createHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ describe('Morebits.createHtml', () => {
test('renderWikilinks', () => {
assert.strictEqual(
Morebits.createHtml.renderWikilinks('[[Main Page]]'),
`<a target="_blank" href="/wiki/Main_Page" title="Main Page">Main Page</a>`,
'<a target="_blank" href="/wiki/Main_Page" title="Main Page">Main Page</a>',
'simple link'
);
assert.strictEqual(
Morebits.createHtml.renderWikilinks('surrounding text [[Main Page|the main page]]'),
`surrounding text <a target="_blank" href="/wiki/Main_Page" title="Main Page">the main page</a>`,
'surrounding text <a target="_blank" href="/wiki/Main_Page" title="Main Page">the main page</a>',
'link with display text'
);
assert.strictEqual(
Morebits.createHtml.renderWikilinks('surrounding text [["Weird Al" Yankovic]]'),
`surrounding text <a target="_blank" href="/wiki/%22Weird_Al%22_Yankovic" title="&#34;Weird Al&#34; Yankovic">"Weird Al" Yankovic</a>`,
'surrounding text <a target="_blank" href="/wiki/%22Weird_Al%22_Yankovic" title="&#34;Weird Al&#34; Yankovic">"Weird Al" Yankovic</a>',
// jsdom in node turns " in title attribute into &#34; whereas Chrome seems turns it into &quot;
// but it works either way
'link with double quote'
);

assert.strictEqual(
Morebits.createHtml.renderWikilinks('<code>[[CODE]]</code> [[Yankovic]]'),
`<code>[[CODE]]</code> <a target="_blank" href="/wiki/Yankovic" title="Yankovic">Yankovic</a>`,
'<code>[[CODE]]</code> <a target="_blank" href="/wiki/Yankovic" title="Yankovic">Yankovic</a>',
'wikilink in <code> tag'
);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/morebits.date.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe('Morebits.date', () => {
var now = Date.now();
var ts_mw = '16:26, 7 November 2020 (UTC)', ts_iso = '2020-11-07T16:26:00.000Z', naive = 20201107162600;
const now = Date.now();
const ts_mw = '16:26, 7 November 2020 (UTC)', ts_iso = '2020-11-07T16:26:00.000Z', naive = 20201107162600;
test('Construction', () => {
// getTime and toISOString imply testing of inherited methods
// Allow off-by-one values in milliseconds for not-quite-simultaneous date contructions
expect(Math.abs(new Morebits.Date().getTime() - new Date().getTime())).toBeLessThanOrEqual(1);
expect(Math.abs(new Morebits.Date().getTime() - Date.now())).toBeLessThanOrEqual(1);

assert.strictEqual(new Morebits.Date(now).getTime(), new Date(now).getTime(), 'Constructor from timestring');
assert.strictEqual(new Morebits.Date(2020, 11, 7, 16, 26).getTime(), new Date(2020, 11, 7, 16, 26).getTime(), 'Constructor from parts');
Expand All @@ -14,7 +14,7 @@ describe('Morebits.date', () => {
assert.strictEqual(new Morebits.Date(parseInt(naive / 10, 10)).toISOString(), new Date(parseInt(naive / 10, 10)).toISOString(), 'native 13 digit');
assert.strictEqual(new Morebits.Date(naive * 10).toISOString(), new Date(naive * 10).toISOString(), 'native 15 digit');
});
var date = new Morebits.Date(ts_mw);
const date = new Morebits.Date(ts_mw);
test('Methods', () => {
assert.true(date.isValid(), 'Valid');
// Logs a message; not a failure, but annoying
Expand Down
130 changes: 67 additions & 63 deletions tests/morebits.quickForm.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,81 @@
/** Simple helper to render a quickform element */
/**
* Simple helper to render a quickform element
*
* @param data
*/
function renderElement(data) {
return new Morebits.QuickForm.Element(data).render();
}

describe("quickform", () => {
let inputConfig = {
type: "input",
label: "Label",
name: "inputname",
value: "prefilled value",
describe('quickform', () => {
const inputConfig = {
type: 'input',
label: 'Label',
name: 'inputname',
value: 'prefilled value'
};
let selectConfig = {
type: "select",
label: "Select label",
name: "selectname",
const selectConfig = {
type: 'select',
label: 'Select label',
name: 'selectname',
list: [
{ label: "select label 1", value: "selectvalue1" },
{ label: "select label 2", value: "selectvalue2" },
],
{ label: 'select label 1', value: 'selectvalue1' },
{ label: 'select label 2', value: 'selectvalue2' }
]
};
let checkboxListConfig = {
type: "checkbox",
name: "checkboxlist1",
const checkboxListConfig = {
type: 'checkbox',
name: 'checkboxlist1',
list: [
{ label: "checkbox 1", value: "checkval1" },
{ label: "checkbox 2", value: "checkval2", checked: true },
],
{ label: 'checkbox 1', value: 'checkval1' },
{ label: 'checkbox 2', value: 'checkval2', checked: true }
]
};
let checkboxesConfig = {
type: "checkbox",
const checkboxesConfig = {
type: 'checkbox',
list: [
{
label: "checkbox 1",
value: "checkval1",
name: "checkname1",
checked: true,
label: 'checkbox 1',
value: 'checkval1',
name: 'checkname1',
checked: true
},
{ label: "checkbox 2", value: "checkval2", name: "checkname2" },
],
{ label: 'checkbox 2', value: 'checkval2', name: 'checkname2' }
]
};
let radiosConfig = {
type: "radio",
name: "radiolist1",
const radiosConfig = {
type: 'radio',
name: 'radiolist1',
list: [
{
label: "radio 1",
value: "radioval1",
name: "radioname1",
label: 'radio 1',
value: 'radioval1',
name: 'radioname1'
},
{
label: "radio 2",
value: "radioval2",
name: "radioname2",
checked: true,
},
],
label: 'radio 2',
value: 'radioval2',
name: 'radioname2',
checked: true
}
]
};
let textareaConfig = {
type: "textarea",
name: "textareaname1",
value: "textarea prefilled value",
cols: 4,
const textareaConfig = {
type: 'textarea',
name: 'textareaname1',
value: 'textarea prefilled value',
cols: 4
};
let submitConfig = {
type: "submit",
const submitConfig = {
type: 'submit'
};
let buttonConfig = {
type: "button",
label: "button label",
const buttonConfig = {
type: 'button',
label: 'button label'
};

let getRenderedForm = () => {
let form = new Morebits.QuickForm(function () {});
const getRenderedForm = () => {
const form = new Morebits.QuickForm(() => {});
form.append(inputConfig);
form.append(checkboxesConfig);
form.append(checkboxListConfig);
Expand All @@ -80,42 +84,42 @@ describe("quickform", () => {
form.append(submitConfig);
form.append(buttonConfig);
return form.render();
}
};

test("input element", () => {
test('input element', () => {
expect(renderElement(inputConfig)).toMatchSnapshot();
});

test("select element", () => {
test('select element', () => {
expect(renderElement(selectConfig)).toMatchSnapshot();
});

test("checkbox elements", () => {
test('checkbox elements', () => {
expect(renderElement(checkboxListConfig)).toMatchSnapshot();
});

test("checkbox elements (with data-single attribute)", () => {
test('checkbox elements (with data-single attribute)', () => {
expect(renderElement(checkboxesConfig)).toMatchSnapshot();
});

test("radio elements", () => {
test('radio elements', () => {
expect(renderElement(radiosConfig)).toMatchSnapshot();
});

test("textarea element", () => {
test('textarea element', () => {
expect(renderElement(textareaConfig)).toMatchSnapshot();
});

test("submit", () => {
test('submit', () => {
expect(renderElement(submitConfig)).toMatchSnapshot();
});

test("getInputData", () => {
test('getInputData', () => {
expect(Morebits.quickForm.getInputData(getRenderedForm())).toMatchSnapshot();
});

test("getElements", () => {
let form = getRenderedForm();
test('getElements', () => {
const form = getRenderedForm();
expect(Morebits.quickForm.getElements(form, 'checkboxlist1')).toMatchSnapshot();
});

Expand Down
16 changes: 8 additions & 8 deletions tests/morebits.string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ describe('Morebits.string', () => {
assert.strictEqual(Morebits.string.escapeRegExp('Four_score_and_seven_years_ago'), 'Four[_ ]score[_ ]and[_ ]seven[_ ]years[_ ]ago', 'Underscores');
});
test('formatReasonForLog', () => {
var reason = 'They were wrong';
const reason = 'They were wrong';
assert.strictEqual(Morebits.string.formatReasonForLog(reason), reason, 'Simple, unchanged');
var more = 'Really wrong';
const more = 'Really wrong';
assert.strictEqual(Morebits.string.formatReasonForLog(reason + '\n' + more), reason + '{{pb}}' + more, '\n -> {{pb}}');
assert.strictEqual(Morebits.string.formatReasonForLog('#' + reason + '\n' + more), '##' + reason + '{{pb}}' + more, 'Prepend extra #');
assert.strictEqual(Morebits.string.formatReasonForLog('*' + reason + '\n' + more), '#*' + reason + '{{pb}}' + more, 'Prepend extra #');
});
test('formatReasonText', () => {
var reason = 'They were correct';
let reason = 'They were correct';
assert.strictEqual(Morebits.string.formatReasonText(reason), reason, 'Simple, unchanged');
assert.strictEqual(Morebits.string.formatReasonText(reason, true), reason + ' ~~~~', 'Simple');
var more = 'Technically correct';
const more = 'Technically correct';
assert.strictEqual(Morebits.string.formatReasonText(reason + '|' + more), reason + '{{subst:!}}' + more, 'Replace pipe');
assert.strictEqual(Morebits.string.formatReasonText(reason + '|' + more, true), reason + '{{subst:!}}' + more + ' ~~~~', 'Replace pipe');
reason += 'The <nowiki>{{best|kind|of}}</nowiki> correct: ';
assert.strictEqual(Morebits.string.formatReasonText(reason + more), reason + more, 'No replace in nowiki');
assert.strictEqual(Morebits.string.formatReasonText(), '', 'Empty');
var alreadySigned = 'already signed ~~~~';
const alreadySigned = 'already signed ~~~~';
assert.strictEqual(Morebits.string.formatReasonText(alreadySigned, true), alreadySigned, 'No sig duplication');
assert.strictEqual(Morebits.string.formatReasonText('alreadySigned~~~~ ', true), 'alreadySigned~~~~', 'trims and avoids duplicating sig');
assert.strictEqual(Morebits.string.formatReasonText('Wow', true), 'Wow ~~~~', '3-letter reason');
Expand All @@ -38,13 +38,13 @@ describe('Morebits.string', () => {
assert.false(Morebits.string.isInfinity('2020-04-17T09:31:00.000Z'), 'ISO string');
});
test('safeReplace', () => {
var string = '{{subst:board|thread=$SECTION|but=$NOTTHIS}} ~~~~';
const string = '{{subst:board|thread=$SECTION|but=$NOTTHIS}} ~~~~';
assert.strictEqual(Morebits.string.safeReplace(string, '$SECTIONAL', 'thread$'), string, 'No replacement');
assert.strictEqual(Morebits.string.safeReplace(string, '$SECTION', 'thread$'), '{{subst:board|thread=thread$|but=$NOTTHIS}} ~~~~', 'Replacement');
});
test('splitWeightedByKeys', () => {
var split = ['{{thisis|one|template}}', '{{another|one}}', '[[heresalink]]', '[[thislink|ispiped]]'];
var text = split.join(' also ');
const split = ['{{thisis|one|template}}', '{{another|one}}', '[[heresalink]]', '[[thislink|ispiped]]'];
const text = split.join(' also ');
assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '{{', '}}'), split.slice(0, 2), 'Templates');
assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '[[', ']]'), split.slice(2), 'Links');
assert.deepEqual(Morebits.string.splitWeightedByKeys(text, '{{', '}}', split[0]), [split[1]], 'Skiplist, non-array');
Expand Down
10 changes: 5 additions & 5 deletions tests/morebits.taskManager.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
describe('Morebits.taskManager', () => {
test('Contruction', () => {
var tm = new Morebits.TaskManager();
const tm = new Morebits.TaskManager();
assert.true(tm instanceof Morebits.taskManager, 'Correct instance');
});

// Helper to generate functions as well as testing output in proper order;
// verifySteps not used because it would require some extra duplication
var data = {};
var generateFuncs = () => {
const data = {};
const generateFuncs = () => {
data.out = [];
['one', 'two', 'three', 'four'].forEach((step) => {
data[step] = () => {
Expand All @@ -19,7 +19,7 @@ describe('Morebits.taskManager', () => {

test('Simple', () => {
generateFuncs();
var simple = new Morebits.TaskManager();
const simple = new Morebits.TaskManager();
simple.add(data.one, []);
simple.add(data.two, [data.one]);
simple.add(data.three, [data.two]);
Expand All @@ -30,7 +30,7 @@ describe('Morebits.taskManager', () => {
});
test('Complex', () => {
generateFuncs();
var complex = new Morebits.TaskManager();
const complex = new Morebits.TaskManager();
complex.add(data.one, [data.two]);
complex.add(data.two, [data.three, data.four]);
complex.add(data.three, []);
Expand Down
Loading

0 comments on commit bcd6535

Please sign in to comment.