User:Evad37/rater/test.js
Appearance
< User:Evad37 | rater
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Evad37/rater/test. |
//<nowiki>
$( function($) {
// Only load on script's pages
if ( mw.config.get('wgPageName').indexOf(':Evad37/rater') === -1 ) {
return;
}
// Create (hidden) output div, if needed
$('<div>').attr('id', 'qunit').hide().insertBefore('#firstHeading');
// Load QUnit
mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=User:Evad37/qunit-2.8.0.css&action=raw&ctype=text/css', 'text/css' );
/* ========== Unit tests ======================================================================== */
var runTests = function() {
$.getScript( 'https://en.wikipedia.org/w/index.php?title=User:Evad37/qunit-2.8.0.js&action=raw&ctype=text/javascript', function() {
// Show output div
$('#qunit').show();
// Import vars
var config = window.testRater.config;
var API = window.testRater.API;
var getListOfBanner = window.testRater.getListOfBaners;
var Page = window.testRater.Page;
var Template = window.testRater.Template;
var SuggestionLookupTextInputWidget = window.testRater.SuggestionLookupTextInputWidget;
var ComboBoxInputPrompt = window.testRater.ComboBoxInputPrompt;
var OverlayDialog = window.testRater.OverlayDialog;
var windowFactory = window.testRater.windowFactory;
var windowManager = window.testRater.windowManager;
var Dialog = window.testRater.Dialog;
var setupRater = window.testRater.setupRater;
var autoStart = window.testRater.autoStart;
var writeToCache = window.testRater.writeToCache;
QUnit.module("Config")
QUnit.test("Banners are set", function( assert ) {
assert.expect();
var done = assert.async();
config.gotListOfBanners.always(function() {
assert.ok(config.banners != null, "config.banners is set");
assert.ok(config.banners.withRatings != null, "config.banners.withRatings is set");
assert.ok(config.banners.withoutRatings != null, "config.banners.withoutRatings is set");
assert.ok(config.banners.withoutRatings != null, "config.banners.withoutRatings is set");
assert.ok(config.banners.wrappers != null, "config.banners.wrappers is set");
assert.ok(config.banners.withRatings instanceof Object, "config.banners.withRatings is an Object");
assert.ok(config.banners.withoutRatings instanceof Array, "config.banners.withoutRatings is an Array");
assert.ok(config.banners.withoutRatings instanceof Array, "config.banners.withoutRatings is an Array");
assert.ok(config.banners.wrappers instanceof Array, "config.banners.wrappers is an Array");
done();
});
})
QUnit.module( "Page class");
QUnit.test( "newFromText()", function( assert ) {
assert.ok( Page.newFromText('Example') instanceof Page, "'Example' makes a Page object" );
assert.ok( Page.newFromText('Talk:Example') instanceof Page, "'Talk:Example' makes a Page object" );
assert.notOk( Page.newFromText(':::Example') instanceof Page, "':::Example' does not make a Page object" );
});
QUnit.test( "getTalk()", function( assert ) {
assert.equal( Page.newFromText('Example').getTalk(), 'Talk:Example', "Talk page for 'Example' is 'Talk:Example'" );
assert.equal( Page.newFromText('Talk:Example').getTalk(), 'Talk:Example', "Talk page for 'Talk:Example' is 'Talk:Example'" );
assert.equal( Page.newFromText('Template:Example').getTalk(), 'Template talk:Example', "Talk page for 'Template:Example' is 'Template talk:Example'" );
assert.equal( Page.newFromText('Template talk:Example').getTalk(), 'Template talk:Example', "Talk page for 'Template talk:Example' is 'Template talk:Example'" );
});
QUnit.test( "getSubject()", function( assert ) {
assert.equal( Page.newFromText('Example').getSubject(), 'Example', "Subject page for 'Example' is 'Example'" );
assert.equal( Page.newFromText('Talk:Example').getSubject(), 'Example', "Subject page for 'Talk:Example' is 'Example'" );
assert.equal( Page.newFromText('Template:Example').getSubject(), 'Template:Example', "Subject page for 'Template:Example' is 'Template:Example'" );
assert.equal( Page.newFromText('Template talk:Example').getSubject(), 'Template:Example', "Subject page for 'Template talk:Example' is 'Template:Example'" );
});
QUnit.test( "getListasAutofill()", function( assert ) {
assert.equal( Page.newFromText('Single').getListasAutofill(), 'Single', "Single" );
assert.equal( Page.newFromText('First Last').getListasAutofill(), 'Last, First', "First Last" );
assert.equal( Page.newFromText('First Middle Last').getListasAutofill(), 'Last, First Middle', "First Middle Last" );
assert.equal( Page.newFromText('First Middle Other Last').getListasAutofill(), 'Last, First Middle Other', "First Middle Other Last" );
assert.equal( Page.newFromText('Single (disambig)').getListasAutofill(), 'Single', "Single (disambig)" );
assert.equal( Page.newFromText('First Last (disambig)').getListasAutofill(), 'Last, First', "First Last (disambig)" );
assert.equal( Page.newFromText('First Middle Last (disambig)').getListasAutofill(), 'Last, First Middle', "First Middle Last (disambig)" );
assert.equal( Page.newFromText('First Middle Other Last (disambig)').getListasAutofill(), 'Last, First Middle Other', "First Middle Other Last (disambig)" );
assert.equal( Page.newFromText('Single Jr.').getListasAutofill(), 'Single Jr.', "Single Jr." );
assert.equal( Page.newFromText('First Last Jr.').getListasAutofill(), 'Last, First Jr.', "First Last Jr." );
assert.equal( Page.newFromText('First Middle Last Jr.').getListasAutofill(), 'Last, First Middle Jr.', "First Middle Last Jr." );
assert.equal( Page.newFromText('First Middle Other Last Jr.').getListasAutofill(), 'Last, First Middle Other Jr.', "First Middle Other Last Jr." );
assert.equal( Page.newFromText('Single Jr. (disambig)').getListasAutofill(), 'Single Jr.', "Single Jr. (disambig)" );
assert.equal( Page.newFromText('First Last Jr. (disambig)').getListasAutofill(), 'Last, First Jr.', "First Last Jr. (disambig)" );
assert.equal( Page.newFromText('First Middle Last Jr. (disambig)').getListasAutofill(), 'Last, First Middle Jr.', "First Middle Last Jr. (disambig)" );
assert.equal( Page.newFromText('First Middle Other Last Jr. (disambig)').getListasAutofill(), 'Last, First Middle Other Jr.', "First Middle Other Last Jr. (disambig)" );
assert.equal( Page.newFromText('Single XIV').getListasAutofill(), 'Single XIV', "Single XIV" );
assert.equal( Page.newFromText('First Last XIV').getListasAutofill(), 'Last, First XIV', "First Last XIV" );
assert.equal( Page.newFromText('First Middle Last XIV').getListasAutofill(), 'Last, First Middle XIV', "First Middle Last XIV" );
assert.equal( Page.newFromText('First Middle Other Last XIV').getListasAutofill(), 'Last, First Middle Other XIV', "First Middle Other Last XIV" );
assert.equal( Page.newFromText('Single XIV (disambig)').getListasAutofill(), 'Single XIV', "Single XIV (disambig)" );
assert.equal( Page.newFromText('First Last XIV (disambig)').getListasAutofill(), 'Last, First XIV', "First Last XIV (disambig)" );
assert.equal( Page.newFromText('First Middle Last XIV (disambig)').getListasAutofill(), 'Last, First Middle XIV', "First Middle Last XIV (disambig)" );
assert.equal( Page.newFromText('First Middle Other Last XIV (disambig)').getListasAutofill(), 'Last, First Middle Other XIV', "First Middle Other Last XIV (disambig)" );
});
QUnit.test( "getBannerFromNameOrRedirect()", function( assert ) {
var examplePage = Page.newFromText('Perth (suburb)');
examplePage.banners = [
Template.newFromRawWikitext('{{WP AUSTRALIA}}'),
Template.newFromRawWikitext('{{WikiProject Biography}}'),
Template.newFromRawWikitext('{{WikiProject Australian Roads}}')
];
examplePage.banners[0].redirectsTo = Template.newFromRawWikitext('{{WikiProject Australia}}');
assert.notOk( Page.newFromText('Example').getBannerFromNameOrRedirect('Some banner name'), "Page has no banners" );
assert.notOk( examplePage.getBannerFromNameOrRedirect('Some banner name'), "Banner not present" );
assert.deepEqual( examplePage.getBannerFromNameOrRedirect('WikiProject Biography'), examplePage.banners[1], "Banner is present" );
assert.deepEqual( examplePage.getBannerFromNameOrRedirect('WikiProject Australia'), examplePage.banners[0], "Banner's redirect is present" );
});
QUnit.test( "getTalkpageTopSection", function( assert ) {
assert.expect();
var done = assert.async();
var exampleWhereTalkExists = Page.newFromText('Perth (suburb)');
var exampleWhereTalkDoesNotExist = Page.newFromText('ifdjbingjuhtrsiugbbvhsiuriutniuv');
$.when(
exampleWhereTalkExists.getTalkpageTopSection(),
exampleWhereTalkDoesNotExist.getTalkpageTopSection()
).always(function() {
assert.ok( exampleWhereTalkExists.oldTopSection, "Page exists --> oldTopSection is set" );
assert.equal( exampleWhereTalkDoesNotExist.oldTopSection, '', "Page does not exist --> oldTopSection is empty string" );
done();
});
});
QUnit.test( "getLatestSubjectRevisionID", function( assert ) {
assert.expect();
var done = assert.async();
var exampleWhereTalkExists = Page.newFromText('Perth (suburb)');
var exampleWhereTalkDoesNotExist = Page.newFromText('ifdjbingjuhtrsiugbbvhsiuriutniuv');
$.when(
exampleWhereTalkExists.getLatestSubjectRevisionID(),
exampleWhereTalkDoesNotExist.getLatestSubjectRevisionID()
)
.done(function() {
assert.equal( typeof exampleWhereTalkExists.latestSubjectRevisionID, 'number', "Page exists --> latestSubjectRevisionID is a number" );
})
.always(function(){
assert.notOk( exampleWhereTalkDoesNotExist.latestSubjectRevisionID, "Page does not exist --> latestSubjectRevisionID not set" );
done();
});
});
QUnit.test( "getOresScore", function( assert ) {
assert.expect();
var done = assert.async();
var examplePage = Page.newFromText('Example');
var randomTitle = ''+Math.floor(Math.random()*20);
var randomPage = Page.newFromText(randomTitle);
$.when( examplePage.getLatestSubjectRevisionID(), randomPage.getLatestSubjectRevisionID() ).then(function(){
$.when( examplePage.getOresScore(), randomPage.getOresScore() ).always(function() {
assert.equal(typeof examplePage.oresScore, 'string', 'ORES score is a string for "Example"');
assert.notEqual( config.bannerDefaults.classes.indexOf(examplePage.oresScore), -1, 'ORES score is a valid class for "Example"');
assert.equal(typeof randomPage.oresScore, 'string', 'ORES score is a string for random page "'+randomTitle+'"');
assert.notEqual( config.bannerDefaults.classes.indexOf(examplePage.oresScore), -1, 'ORES score ("'+randomPage.oresScore+'") is a valid class for random page "'+randomTitle+'"');
done();
});
});
});
QUnit.test( "splitOldTopSection", function(assert) {
var examplePage = Page.newFromText('Example');
assert.deepEqual(examplePage.splitOldTopSection(), {above:'', projects:'', below: ''}, 'Splits correctly with empty talk page, no banners');
var example2Page = Page.newFromText('Example2');
example2Page.oldTopSection = 'Lorem ipsum dorem par';
assert.deepEqual(example2Page.splitOldTopSection(), {above:'Lorem ipsum dorem par', projects:'', below: ''}, 'Splits correctly with non-empty talk page, no banners');
examplePage.banners = [
Template.newFromRawWikitext('{{WP AUSTRALIA}}\n'),
Template.newFromRawWikitext('{{WikiProject Biography}}\n'),
Template.newFromRawWikitext('{{WikiProject Australian Roads}}')
];
assert.deepEqual(examplePage.splitOldTopSection(), {above:'', projects:'', below: ''}, 'Splits correctly with empty talk page, and added banners');
examplePage.oldTopSection = '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}';
assert.deepEqual(
examplePage.splitOldTopSection(),
{ above: '',
projects: '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}',
below: ''
},
'Splits correctly with only banners'
);
examplePage.oldTopSection = '{{talk header}}\n{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}';
assert.deepEqual(
examplePage.splitOldTopSection(),
{ above: '{{talk header}}',
projects: '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}',
below: ''
},
'Splits correctly with banners and content above'
);
examplePage.oldTopSection = '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}\n{{archive banner}}';
assert.deepEqual(
examplePage.splitOldTopSection(),
{ above: '',
projects: '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}',
below: '{{archive banner}}'
},
'Splits correctly with banners and contennt below'
);
examplePage.oldTopSection = '{{talk header}}\n{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}\n{{archive banner}}';
assert.deepEqual(
examplePage.splitOldTopSection(),
{ above: '{{talk header}}',
projects: '{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}',
below: '{{archive banner}}'
},
'Splits correctly with banners and contennt above and below'
);
});
QUnit.test("makeBannerShellWikitext", function(assert) {
var examplePage = Page.newFromText('Example');
examplePage.hasShellTemplate = true;
assert.notOk(examplePage.makeBannerShellWikitext(), 'No shell if there is already a shell');
examplePage.hasShellTemplate = false;
assert.notOk(examplePage.makeBannerShellWikitext(), 'No shell if there are no banners');
examplePage.banners = [
Template.newFromRawWikitext('{{WP AUSTRALIA}}\n')
];
assert.notOk(examplePage.makeBannerShellWikitext(), 'No shell if there is one banner');
examplePage.banners.push(
Template.newFromRawWikitext('{{WikiProject Austria}}\n')
);
assert.notOk(examplePage.makeBannerShellWikitext(), 'No shell if there are two banners');
examplePage.banners.push(
Template.newFromRawWikitext('{{WikiProject Australian Roads}}\n')
);
assert.ok(examplePage.makeBannerShellWikitext(), 'Is a shell if there are three banners');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|1=',
bottom:'}}'
}, 'Standard wikitext when no Bio banner');
examplePage.banners.push(
Template.newFromRawWikitext('{{WikiProject Biography}}\n')
);
assert.ok(examplePage.makeBannerShellWikitext(), 'Is a shell if there are four banners');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|1=',
bottom:'}}'
}, 'Standard wikitext when Bio banner has no parameters');
examplePage.banners[3].setParamValue('living', 'yes');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|living=yes|1=',
bottom:'}}'
}, 'Wikitext has `|living=yes` when Bio banner does');
examplePage.banners[3].setParamValue('activepol', '1');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|living=yes|activepol=yes|1=',
bottom:'}}'
}, 'Wikitext has `|living=yes|activepol=yes` when Bio banner does');
examplePage.banners[3].setParamValue('living', 'no');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|1=',
bottom:'}}'
}, 'Standard wikitext when Bio banner has living=no');
examplePage.banners[3].setParamValue('blpo', 'true');
assert.deepEqual(examplePage.makeBannerShellWikitext(), {
top:'{{WikiProject banner shell|blpo=yes|1=',
bottom:'}}'
}, 'Wikitext has `|blpo=yes` when Bio banner has that and `living=no`');
});
QUnit.test("makeUpdatedBanners", function(assert) {
var examplePage = Page.newFromText('Example');
examplePage.banners = [
Template.newFromRawWikitext('{{WP AUSTRALIA}}\n'),
Template.newFromRawWikitext('{{WikiProject Biography}}\n'),
Template.newFromRawWikitext('{{WikiProject Australian Roads}}')
];
var isTrue = function() { return true; };
var isFalse = function() { return false; };
examplePage.banners[0].setParamValue('class', 'C'); examplePage.banners[1].setParamValue('class', 'C'); examplePage.banners[2].setParamValue('class', 'C');
examplePage.banners[0].isNew = isTrue; examplePage.banners[1].isNew = isTrue; examplePage.banners[2].isNew = isTrue;
assert.equal(examplePage.makeUpdatedBanners(''), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Biography |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'No existing projects');
examplePage.banners[0].isNew = isFalse; examplePage.banners[1].isNew = isFalse;
assert.equal(examplePage.makeUpdatedBanners('{{WP AUSTRALIA}}\n{{WikiProject Biography}}'), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Biography |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'Some existing projects');
examplePage.banners[2].isNew = isFalse;
assert.equal(examplePage.makeUpdatedBanners('{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}'), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Biography |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'All existing projects');
examplePage.banners[2].isNew = isFalse;
examplePage.banners[1].remove = true;
assert.equal(examplePage.makeUpdatedBanners('{{WP AUSTRALIA}}\n{{WikiProject Biography}}\n{{WikiProject Australian Roads}}'), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'A project to remove');
examplePage.banners[1].remove = false;
examplePage.banners[0].rawWikitext = '{{WP AUSTRALIA|class=stub}}';
examplePage.banners[1].rawWikitext = '{{WikiProject Biography |class = Stub}}';
examplePage.banners[2].rawWikitext = '{{WikiProject Australian Roads | class = stub }}';
assert.equal(examplePage.makeUpdatedBanners('{{WP AUSTRALIA|class=stub}}\n{{WikiProject Biography |class = Stub}}\n{{WikiProject Australian Roads | class = stub }}'), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Biography |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'All existing projects with parameters to update');
examplePage.banners[0].rawWikitext = '{{WP AUSTRALIA|class=stub|small=yes}}';
examplePage.banners[0].setParamValue('small', 'yes'); examplePage.banners[0].deleteParam('small');
examplePage.banners[1].rawWikitext = '{{WikiProject Biography |class = Stub |blpo= true}}';
examplePage.banners[1].setParamValue('blpo', 'true'); examplePage.banners[1].deleteParam('blpo');
examplePage.banners[2].rawWikitext = '{{WikiProject Australian Roads | class = stub | WA = yes }}';
examplePage.banners[2].setParamValue('WA', 'yes'); examplePage.banners[2].deleteParam('WA');
assert.equal(examplePage.makeUpdatedBanners('{{WP AUSTRALIA|class=stub|small=yes}}\n{{WikiProject Biography |class = Stub |blpo= true}}\n{{WikiProject Australian Roads | class = stub | WA = yes }}'), '{{WP AUSTRALIA |class=C}}\n{{WikiProject Biography |class=C}}\n{{WikiProject Australian Roads |class=C}}', 'All existing projects with parameters to update and parameters to remove');
});
QUnit.test("makeEditSummary", function(assert) {
var examplePage = Page.newFromText('Example');
var isTrue = function() { return true; };
var isFalse = function() { return false; };
assert.equal(examplePage.makeEditSummary(), 'Assessment', 'No additions, modifications, or removals');
examplePage.banners = [
Template.newFromRawWikitext('{{WikiProject Biography}}\n'),
];
examplePage.banners[0].isNew = isTrue;
assert.equal(examplePage.makeEditSummary(), 'Assessment: +Biography', '{{WikiProject Biography}} banner added');
examplePage.banners[0].isNew = isFalse;
examplePage.banners[0].touched = {foo: true};
assert.equal(examplePage.makeEditSummary(), 'Assessment: Biography', '{{WikiProject Biography}} banner modified');
examplePage.banners[0].remove = true;
assert.equal(examplePage.makeEditSummary(), 'Assessment: −Biography', '{{WikiProject Biography}} banner removed');
examplePage.banners[0].remove = false;
examplePage.banners[0].setParamValue('class', 'C');
assert.equal(examplePage.makeEditSummary(), 'Assessment: Biography (C)', '{{WikiProject Biography}} banner modified, class changed');
examplePage.banners[0].touched = {};
examplePage.banners[0].setParamValue('importance', 'Low');
assert.equal(examplePage.makeEditSummary(), 'Assessment: Biography (Low)', '{{WikiProject Biography}} banner modified, including importance changed');
examplePage.banners[0].setParamValue('class', 'C');
assert.equal(examplePage.makeEditSummary(), 'Assessment: Biography (C/Low)', '{{WikiProject Biography}} banner modified, including class and importance changed');
examplePage.banners = [
Template.newFromRawWikitext('{{WP Australia}}\n'),
];
examplePage.banners[0].isNew = isTrue;
assert.equal(examplePage.makeEditSummary(), 'Assessment: +WP Australia', '{{WP Australia}} banner added');
examplePage.banners[0].isNew = isFalse;
examplePage.banners[0].touched = {foo: true};
assert.equal(examplePage.makeEditSummary(), 'Assessment: WP Australia', '{{WP Australia}} banner modified');
examplePage.banners[0].remove = true;
assert.equal(examplePage.makeEditSummary(), 'Assessment: −WP Australia', '{{WP Australia}} banner removed');
examplePage.banners[0].remove = false;
examplePage.banners[0].setParamValue('class', 'C');
assert.equal(examplePage.makeEditSummary(), 'Assessment: WP Australia (C)', '{{WP Australia}} banner modified, class changed');
examplePage.banners[0].touched = {};
examplePage.banners[0].setParamValue('importance', 'Low');
assert.equal(examplePage.makeEditSummary(), 'Assessment: WP Australia (Low)', '{{WP Australia}} banner modified, including importance changed');
examplePage.banners[0].setParamValue('class', 'C');
assert.equal(examplePage.makeEditSummary(), 'Assessment: WP Australia (C/Low)', '{{WP Australia}} banner modified, including class and importance changed');
/* Example from Mr. Guye (Template talk:Infobox government agency: 9 December 2017)
{{talkheader}}
− {{WP Australia|class=template|importance=NA|politics=yes}}
{{WikiProject Infoboxes}}
+ {{WikiProject Politics of the United Kingdom}}
{{archives|search=yes}}
Expected: `Assessment: −WP Australia; +Politics of the United Kingdom`
Actual was: `Assessment: +Politics of the United Kingdom`
*/
exampleTwo = Page.newFromText('Template talk:Infobox government agency');
exampleTwo.banners = [
Template.newFromRawWikitext('{{WP Australia|class=template|importance=NA|politics=yes}}'),
Template.newFromRawWikitext('{{WikiProject Infoboxes}}'),
Template.newFromRawWikitext('{{WikiProject Politics of the United Kingdom}}')
];
exampleTwo.banners[0].remove = true;
exampleTwo.banners[0].isNew = isFalse;
exampleTwo.banners[1].isNew = isFalse;
exampleTwo.banners[2].isNew = isTrue;
assert.equal(exampleTwo.makeEditSummary(), 'Assessment: −WP Australia; +Politics of the United Kingdom', 'One banner removed, a second unchanged, another added');
});
QUnit.module( "Template class");
QUnit.test("Template.makeParamsObject", function(assert) {
assert.deepEqual(Template.makeParamsObject('|class=c'), {'class':'c'}, 'Single named parameter');
assert.deepEqual(Template.makeParamsObject('|class=c|importance=low'), {'class':'c', 'importance':'low'}, 'Two named parameters');
assert.deepEqual(Template.makeParamsObject('|foo'), {'1':'foo'}, 'Single unnamed parameter');
assert.deepEqual(Template.makeParamsObject('|foo|bar'), {'1':'foo', '2':'bar'}, 'Two unnamed parameters');
assert.deepEqual(Template.makeParamsObject('|1=foo'), {'1':'foo'}, 'Single numbered parameter');
assert.deepEqual(Template.makeParamsObject('|1=foo|2=bar'), {'1':'foo', '2':'bar'}, 'Two numbered parameters');
assert.deepEqual(Template.makeParamsObject('|foo|bar=qux'), {'1':'foo', 'bar':'qux'}, 'Unnamed and then named parameter');
assert.deepEqual(Template.makeParamsObject('|bar=qux|foo'), {'1':'foo', 'bar':'qux'}, 'Named and then unnamed parameter');
assert.deepEqual(Template.makeParamsObject('|class=c|bar=qux|foo|baz'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (1)');
assert.deepEqual(Template.makeParamsObject('|class=c|foo|bar=qux|baz'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (2)');
assert.deepEqual(Template.makeParamsObject('|foo|class=c|bar=qux|baz'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (3)');
assert.deepEqual(Template.makeParamsObject('|class=c|foo|baz|bar=qux'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (4)');
assert.deepEqual(Template.makeParamsObject('|foo|class=c|baz|bar=qux'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (5)');
assert.deepEqual(Template.makeParamsObject('|foo|baz|class=c|bar=qux'), {'1':'foo', '2':'baz', 'class':'c', 'bar':'qux'}, 'Two named and two unnamed parameters (6)');
assert.deepEqual(Template.makeParamsObject('|class =c'), {'class':'c'}, 'Spacing should not matter - single param (1)');
assert.deepEqual(Template.makeParamsObject('|class= c'), {'class':'c'}, 'Spacing should not matter - single param (2)');
assert.deepEqual(Template.makeParamsObject('|class = c'), {'class':'c'}, 'Spacing should not matter - single param (3)');
assert.deepEqual(Template.makeParamsObject('|class = c'), {'class':'c'}, 'Spacing should not matter - single param (4)');
assert.deepEqual(Template.makeParamsObject('| class =c'), {'class':'c'}, 'Spacing should not matter - single param (5)');
assert.deepEqual(Template.makeParamsObject('| class= c'), {'class':'c'}, 'Spacing should not matter - single param (6)');
assert.deepEqual(Template.makeParamsObject('| class = c'), {'class':'c'}, 'Spacing should not matter - single param (7)');
assert.deepEqual(Template.makeParamsObject('| class = c'), {'class':'c'}, 'Spacing should not matter - single param (8)');
assert.deepEqual(Template.makeParamsObject('|nested={{WPAUS}}'), {'nested':'{{WPAUS}}'}, 'Nested template (without its own parameters) - in named parameter');
assert.deepEqual(Template.makeParamsObject('|nested={{WPAUS|class=c}}'), {'nested':'{{WPAUS|class=c}}'}, 'Nested template (with its own single parameter) - in named parameter');
assert.deepEqual(Template.makeParamsObject('|nested={{WPAUS|class=c|importance=low}}'), {'nested':'{{WPAUS|class=c|importance=low}}'}, 'Nested template (with its own parameters) - in named parameter');
assert.deepEqual(Template.makeParamsObject('|1={{WPAUS}}'), {'1':'{{WPAUS}}'}, 'Nested template (without its own parameters) - in numbered parameter');
assert.deepEqual(Template.makeParamsObject('|1={{WPAUS|class=c}}'), {'1':'{{WPAUS|class=c}}'}, 'Nested template (with its own single parameter) - in numbered parameter');
assert.deepEqual(Template.makeParamsObject('|1={{WPAUS|class=c|importance=low}}'), {'1':'{{WPAUS|class=c|importance=low}}'}, 'Nested template (with its own parameters) - in numbered parameter');
assert.deepEqual(Template.makeParamsObject('|{{WPAUS}}'), {'1':'{{WPAUS}}'}, 'Nested template (without its own parameters) - in unnamed parameter');
assert.deepEqual(Template.makeParamsObject('|{{WPAUS|class=c}}'), {'1':'{{WPAUS|class=c}}'}, 'Nested template (with its own single parameter) - in unnamed parameter');
assert.deepEqual(Template.makeParamsObject('|{{WPAUS|class=c|importance=low}}'), {'1':'{{WPAUS|class=c|importance=low}}'}, 'Nested template (with its own parameters) - in unnamed parameter');
});
QUnit.test("setParamDataAndSuggestions", function(assert) {
assert.expect();
var done = assert.async();
var templateWithData = Template.newFromRawWikitext('{{WikiProject Biography}}');
var templateNoData = Template.newFromRawWikitext('{{Foo}}');
$.when( templateWithData.setParamDataAndSuggestions(), templateNoData.setParamDataAndSuggestions() )
.then( function() {
assert.ok(templateWithData.paramData, 'paramData set for template with TemplateData');
assert.ok(templateWithData.parameterSuggestions, 'parameterSuggestions set for template with TemplateData');
assert.ok(templateNoData.paramData, 'paramData set for template without TemplateData');
assert.ok(templateNoData.parameterSuggestions, 'parameterSuggestions set for template without TemplateData');
done();
})
.fail(function() {
assert.ok(false, 'Deferred failed');
});
});
});
};
// Add portlet link
mw.util.addPortletLink( 'p-views', '#', 'Test script', 'ca-testScript', 'Run unit tests for this script' );
$('#ca-testScript').click(function(e) {
e.preventDefault();
runTests();
});
// On test page, run automatically after 2.5 seconds
if ( mw.config.get('wgPageName') === 'User:Evad37/rater/test' ) {
setTimeout(runTests, 2500);
}
});
//</nowiki>