Skip to content

Commit

Permalink
make title.test.js and date.test.js not depend on a local wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Mar 22, 2023
1 parent b60bf01 commit c2e2340
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 77 deletions.
9 changes: 9 additions & 0 deletions tests/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ describe('mwn', async function () {
});
});

it('loads date locale data using API', async function () {
bot.options.defaultParams.assert = undefined; // avoid sign-in
await bot.date.populateLocaleData('fr');
expect(bot.date.localeData.months[0]).to.equal('janvier');
expect(bot.date.localeData.monthsShort[0]).to.equal('janv.');
expect(bot.date.localeData.days[0]).to.equal('dimanche');
expect(bot.date.localeData.daysShort[0]).to.equal('dim.');
});

//////////////////////////////////////////
// UNSUCCESSFUL //
//////////////////////////////////////////
Expand Down
12 changes: 2 additions & 10 deletions tests/date.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { bot, expect } = require('./local_wiki');
const { mwn, expect } = require('./test_base');

// Includes some tests copied from https://github.com/wikimedia-gadgets/twinkle/blob/master/tests/morebits.date.js

const bot = new mwn();
describe('date', async function () {
it('date constructor', function () {
let mwTs = new bot.date('20120304050607');
Expand Down Expand Up @@ -67,13 +68,4 @@ describe('date', async function () {
expect(bot.date.getMonthName(1)).to.eq('January');
expect(bot.date.getMonthNameAbbrev(1)).to.eq('Jan');
});

it('loads locale data using API', async function () {
bot.options.defaultParams.assert = undefined; // avoid sign-in
await bot.date.populateLocaleData('fr');
expect(bot.date.localeData.months[0]).to.equal('janvier');
expect(bot.date.localeData.monthsShort[0]).to.equal('janv.');
expect(bot.date.localeData.days[0]).to.equal('dimanche');
expect(bot.date.localeData.daysShort[0]).to.equal('dim.');
});
});
10 changes: 4 additions & 6 deletions tests/static_utils.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

const { mwn, bot, expect, assert, setup, teardown } = require('./test_wiki');
const { mwn, expect, assert, populateTitleData } = require('./test_base');

describe('static utils', function () {
this.timeout(10000);

before('logs in and gets token & namespaceInfo', setup);
after('logs out', teardown);
const bot = new mwn();
populateTitleData(bot.title);

describe('static utils', function () {
it('link', function () {
expect(mwn.link('Main Page')).to.equal('[[Main Page]]');
expect(mwn.link('Main Page', 'homepage')).to.equal('[[Main Page|homepage]]');
Expand Down
62 changes: 61 additions & 1 deletion tests/test_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,64 @@ function verifyTokenAndSiteInfo(bot) {
expect(bot.title.nameIdMap).to.include.all.keys('project', 'user');
}

module.exports = { mwn, log, expect, assert, sinon, verifyTokenAndSiteInfo };
/** Populate title data without an API request **/
function populateTitleData(titleObj) {
Object.assign(titleObj, {
idNameMap: {
'-2': 'Media',
'-1': 'Special',
'0': '',
'1': 'Talk',
'2': 'User',
'3': 'User talk',
'4': 'Wikipedia',
'5': 'Wikipedia talk',
'6': 'File',
'7': 'File talk',
'8': 'MediaWiki',
'9': 'MediaWiki talk',
'10': 'Template',
'11': 'Template talk',
'12': 'Help',
'13': 'Help talk',
'14': 'Category',
'15': 'Category talk',
// testing custom / localized namespace
'100': 'Penguins',
},

nameIdMap: {
'media': -2,
'special': -1,
'': 0,
'talk': 1,
'user': 2,
'user_talk': 3,
'wikipedia': 4,
'wikipedia_talk': 5,
'file': 6,
'file_talk': 7,
'mediawiki': 8,
'mediawiki_talk': 9,
'template': 10,
'template_talk': 11,
'help': 12,
'help_talk': 13,
'category': 14,
'category_talk': 15,
'image': 6,
'image_talk': 7,
'project': 4,
'project_talk': 5,
// Testing custom namespaces and aliases
'penguins': 100,
'antarctic_waterfowl': 100,
},

caseSensitiveNamespaces: [],

legaltitlechars: ' %!"$&\'()*,\\-./0-9:;=?@A-Z\\\\\\^_`a-z~+\\u0080-\\uFFFF',
});
}

module.exports = { mwn, log, expect, assert, sinon, verifyTokenAndSiteInfo, populateTitleData };
63 changes: 3 additions & 60 deletions tests/title.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,11 @@
*
*/

const { mwn } = require('./test_base');
const { mwn, assert, populateTitleData } = require('./test_base');

const bot = new mwn();
const Title = bot.title;

const assert = require('assert');

Object.assign(Title, {
idNameMap: {
'-2': 'Media',
'-1': 'Special',
'0': '',
'1': 'Talk',
'2': 'User',
'3': 'User talk',
'4': 'Wikipedia',
'5': 'Wikipedia talk',
'6': 'File',
'7': 'File talk',
'8': 'MediaWiki',
'9': 'MediaWiki talk',
'10': 'Template',
'11': 'Template talk',
'12': 'Help',
'13': 'Help talk',
'14': 'Category',
'15': 'Category talk',
// testing custom / localized namespace
'100': 'Penguins',
},

nameIdMap: {
'media': -2,
'special': -1,
'': 0,
'talk': 1,
'user': 2,
'user_talk': 3,
'wikipedia': 4,
'wikipedia_talk': 5,
'file': 6,
'file_talk': 7,
'mediawiki': 8,
'mediawiki_talk': 9,
'template': 10,
'template_talk': 11,
'help': 12,
'help_talk': 13,
'category': 14,
'category_talk': 15,
'image': 6,
'image_talk': 7,
'project': 4,
'project_talk': 5,
// Testing custom namespaces and aliases
'penguins': 100,
'antarctic_waterfowl': 100,
},

caseSensitiveNamespaces: [],

legaltitlechars: ' %!"$&\'()*,\\-./0-9:;=?@A-Z\\\\\\^_`a-z~+\\u0080-\\uFFFF',
});
populateTitleData(Title);

describe('title', function () {
var repeat = function (input, multiplier) {
Expand Down

0 comments on commit c2e2340

Please sign in to comment.