diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json index 9ad47d2d9..e2d17abda 100644 --- a/tests/.eslintrc.json +++ b/tests/.eslintrc.json @@ -13,7 +13,6 @@ "object-curly-spacing": "off", "space-in-parens": "off", - "new-cap": "warn", "no-undef": "warn", "no-useless-escape": "warn" } diff --git a/tests/morebits.batchOperation.js b/tests/morebits.batchOperation.js index 06aed974a..9fa045008 100644 --- a/tests/morebits.batchOperation.js +++ b/tests/morebits.batchOperation.js @@ -2,9 +2,9 @@ describe('Morebits.batchOperation', () => { test('Contruction', () => { - assert.true(new Morebits.batchOperation() instanceof Morebits.batchOperation, 'Correct instance'); + assert.true(new Morebits.BatchOperation() instanceof Morebits.batchOperation, 'Correct instance'); }); - const batch = new Morebits.batchOperation(); + const batch = new Morebits.BatchOperation(); const pageList = ['Macbeth', 'Hamlet', 'Romeo and Juliet', 'Much Ado About Nothing', 'Tempest']; batch.setPageList(pageList); const chunkLength = 2; diff --git a/tests/morebits.date.js b/tests/morebits.date.js index b9d535948..13f419ed3 100644 --- a/tests/morebits.date.js +++ b/tests/morebits.date.js @@ -6,21 +6,21 @@ describe('Morebits.date', () => { 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() - Date.now())).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'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format'); - assert.strictEqual(new Morebits.date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number'); - assert.strictEqual(new Morebits.date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string'); - 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'); + 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'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).toISOString(), timestampIso, 'enWiki timestamp format'); + assert.strictEqual(new Morebits.Date(naive).toISOString(), timestampIso, 'MediaWiki 14-digit number'); + assert.strictEqual(new Morebits.Date(naive.toString()).toISOString(), timestampIso, 'MediaWiki 14-digit string'); + 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'); }); - const date = new Morebits.date(timestampMediaWiki); + const date = new Morebits.Date(timestampMediaWiki); test('Methods', () => { assert.true(date.isValid(), 'Valid'); // Logs a message; not a failure, but annoying - assert.false(new Morebits.date('no').isValid(), 'Invalid'); + assert.false(new Morebits.Date('no').isValid(), 'Invalid'); // Ideally we would test the differences between UTC and non-UTC dates assert.strictEqual(date.getUTCDayName(), 'Saturday', 'getUTCDayName'); @@ -28,7 +28,7 @@ describe('Morebits.date', () => { assert.strictEqual(date.getUTCMonthName(), 'November', 'getUTCMonthName'); assert.strictEqual(date.getUTCMonthNameAbbrev(), 'Nov', 'getUTCMonthNameAbbrev'); - assert.true(new Morebits.date(now).isAfter(date), 'isAfter'); + assert.true(new Morebits.Date(now).isAfter(date), 'isAfter'); assert.true(date.isBefore(new Date(now)), 'isBefore'); }); test('RegEx headers', () => { @@ -43,25 +43,25 @@ describe('Morebits.date', () => { assert.false(date.monthHeaderRegex().test('==December 2020=='), 'Wrong month'); }); test('add/subtract', () => { - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); - assert.strictEqual(new Morebits.date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'day').toISOString(), '2020-11-08T16:26:00.000Z', 'Add 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'DaY').toISOString(), '2020-11-08T16:26:00.000Z', 'Loudly add 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add('1', 'day').toISOString(), '2020-11-08T16:26:00.000Z', "Add 1 day but it's a string"); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).subtract(1, 'day').toISOString(), '2020-11-06T16:26:00.000Z', 'Subtract 1 day'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').toISOString(), '2020-11-21T16:26:00.000Z', 'Add 2 weeks'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(2, 'weeks').subtract(2, 'weeks').toISOString(), timestampIso, '2 weeks roundtrip'); // Note, this intentionally twice-crosses a US DST - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); - assert.strictEqual(new Morebits.date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'second').toISOString(), '2020-11-07T16:26:01.000Z', 'Add 1 second'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'minute').toISOString(), '2020-11-07T16:27:00.000Z', 'Add 1 minute'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'hour').toISOString(), '2020-11-07T17:26:00.000Z', 'Add 1 hour'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'month').toISOString(), '2020-12-07T16:26:00.000Z', 'Add 1 month'); + assert.strictEqual(new Morebits.Date(timestampMediaWiki).add(1, 'year').toISOString(), '2021-11-07T16:26:00.000Z', 'Add 1 year'); - assert.throws(() => new Morebits.date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided'); - assert.throws(() => new Morebits.date(timestampMediaWiki).add(1), 'throws: no unit'); - assert.throws(() => new Morebits.date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).add('forty-two'), 'throws: non-number provided'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).add(1), 'throws: no unit'); + assert.throws(() => new Morebits.Date(timestampMediaWiki).subtract(1, 'dayo'), 'throws: bad unit'); }); test('Formats', () => { - assert.strictEqual(new Morebits.date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format'); + assert.strictEqual(new Morebits.Date(now).format('YYYY-MM-DDTHH:mm:ss.SSSZ', 'utc'), new Date(now).toISOString(), 'ISO format'); assert.strictEqual(date.format('dddd D MMMM YY h:mA', 'utc'), 'Saturday 7 November 20 4:26PM', 'Some weirder stuff'); assert.strictEqual(date.format('MMt[h month], [d]a[y] D, h [o\'clock] A', 'utc'), '11th month, day 7, 4 o\'clock PM', 'Format escapes'); assert.strictEqual(date.format('dddd D MMMM YY h:mA', 600), 'Sunday 8 November 20 2:26AM', 'non-UTC formatting'); @@ -70,7 +70,7 @@ describe('Morebits.date', () => { test('Calendar', () => { assert.strictEqual(date.calendar('utc'), '2020-11-07', 'Old calendar'); assert.strictEqual(date.calendar(600), '2020-11-08', 'Old non-UTC'); - assert.strictEqual(new Morebits.date(now).calendar('utc'), 'Today at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'New calendar'); - assert.strictEqual(new Morebits.date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.date(now).format('h:mm A', 'utc'), 'Close calendar'); + assert.strictEqual(new Morebits.Date(now).calendar('utc'), 'Today at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'New calendar'); + assert.strictEqual(new Morebits.Date(now).subtract(1, 'day').calendar('utc'), 'Yesterday at ' + new Morebits.Date(now).format('h:mm A', 'utc'), 'Close calendar'); }); }); diff --git a/tests/morebits.quickForm.js b/tests/morebits.quickForm.js index de48acb10..c3f2d5e4e 100644 --- a/tests/morebits.quickForm.js +++ b/tests/morebits.quickForm.js @@ -6,7 +6,7 @@ * @param data */ function renderElement(data) { - return new Morebits.quickForm.element(data).render(); + return new Morebits.QuickForm.Element(data).render(); } describe('quickform', () => { @@ -77,7 +77,7 @@ describe('quickform', () => { }; const getRenderedForm = () => { - const form = new Morebits.quickForm(() => {}); + const form = new Morebits.QuickForm(() => {}); form.append(inputConfig); form.append(checkboxesConfig); form.append(checkboxListConfig); diff --git a/tests/morebits.taskManager.js b/tests/morebits.taskManager.js index 7d5ea5f00..bcd03db49 100644 --- a/tests/morebits.taskManager.js +++ b/tests/morebits.taskManager.js @@ -2,7 +2,7 @@ describe('Morebits.taskManager', () => { test('Contruction', () => { - const tm = new Morebits.taskManager(); + const tm = new Morebits.TaskManager(); assert.true(tm instanceof Morebits.taskManager, 'Correct instance'); }); @@ -21,7 +21,7 @@ describe('Morebits.taskManager', () => { test('Simple', () => { generateFuncs(); - const 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]); @@ -32,7 +32,7 @@ describe('Morebits.taskManager', () => { }); test('Complex', () => { generateFuncs(); - const 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, []); diff --git a/tests/morebits.unbinder.js b/tests/morebits.unbinder.js index 98e7362ec..4c4cd6644 100644 --- a/tests/morebits.unbinder.js +++ b/tests/morebits.unbinder.js @@ -2,20 +2,20 @@ describe('Morebits.unbinder', () => { test('Construction', () => { - assert.throws(() => new Morebits.unbinder(), 'throws: no string'); - assert.throws(() => new Morebits.unbinder([42]), 'throws: not a string'); - const u = new Morebits.unbinder('Hello world'); + assert.throws(() => new Morebits.Unbinder(), 'throws: no string'); + assert.throws(() => new Morebits.Unbinder([42]), 'throws: not a string'); + const u = new Morebits.Unbinder('Hello world'); assert.true(u instanceof Morebits.unbinder, 'Correct instance'); assert.throws(() => u.unbind(), 'throws: Missing prefix'); assert.throws(() => u.unbind('w'), 'throws: Missing postfix'); }); test('Run', () => { - let u = new Morebits.unbinder('Hello world world'); + let u = new Morebits.Unbinder('Hello world world'); u.unbind(''); u.content = u.content.replace(/world/g, 'earth'); assert.strictEqual(u.rebind(), 'Hello earth earth', 'Simple replace'); - u = new Morebits.unbinder('Hello world world [link link] [[link|link]]'); + u = new Morebits.Unbinder('Hello world world [link link] [[link|link]]'); assert.true(u instanceof Morebits.unbinder, 'Correct instance'); u.unbind(''); u.unbind('\\[\\[', '\\]\\]'); diff --git a/tests/morebits.wikitext.js b/tests/morebits.wikitext.js index 6d7a8b5e1..a6e5a3b45 100644 --- a/tests/morebits.wikitext.js +++ b/tests/morebits.wikitext.js @@ -83,13 +83,13 @@ describe('Morebits.wikitext', () => { test('Morebits.wikitext.page', () => { const text = '{{short description}}{{about}}[[File:Fee.svg]]O, [[Juliet|she]] doth {{plural|teach}} the torches to burn bright!'; - const page = new Morebits.wikitext.page(text); + const page = new Morebits.wikitext.Page(text); assert.true(page instanceof Morebits.wikitext.page, 'Correct instance'); assert.strictEqual(page.getText(), text, 'Got text'); // Throws - assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates(), 'throws: no tag'); - assert.throws(() => new Morebits.wikitext.page(text).insertAfterTemplates('tag'), 'throws: no regex'); + assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates(), 'throws: no tag'); + assert.throws(() => new Morebits.wikitext.Page(text).insertAfterTemplates('tag'), 'throws: no regex'); // Define all the tests individually, with the appropriate method, // input, expected output, and (spreaded) parameters. @@ -356,7 +356,7 @@ describe('Morebits.wikitext', () => { ]; tests.forEach((test) => { - const page = new Morebits.wikitext.page(test.input); + const page = new Morebits.wikitext.Page(test.input); assert.strictEqual(page[test.method](...test.params).getText(), test.expected, test.method + ' - ' + test.name); }); });