2013-09-21 03:46:02 +00:00
|
|
|
/**
|
|
|
|
* TemplateData Generator GUI Unit Tests
|
|
|
|
*/
|
|
|
|
|
2015-02-17 23:56:44 +00:00
|
|
|
( function () {
|
2013-09-21 03:46:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
QUnit.module( 'ext.templateData', QUnit.newMwEnvironment() );
|
|
|
|
|
2015-01-06 00:04:51 +00:00
|
|
|
var i, testVars, finalJsonStringParams, finalJsonStringOnly, finalJsonStringOnlyParamOrder,
|
2014-10-11 05:22:21 +00:00
|
|
|
resultDescCurrLang = {},
|
|
|
|
resultDescMockLang = {},
|
|
|
|
resultDescBothLang = {},
|
|
|
|
currLanguage = mw.config.get( 'wgContentLanguage' ) || 'en',
|
|
|
|
originalWikitext = 'Some text here that is not templatedata information.' +
|
|
|
|
'<templatedata>' +
|
|
|
|
'{' +
|
|
|
|
' "description": {\n' +
|
|
|
|
' "' + currLanguage + '": "Label unsigned comments in a conversation.",\n' +
|
|
|
|
' "blah": "Template description in some blah language."\n' +
|
|
|
|
' },' +
|
|
|
|
' "params": {' +
|
|
|
|
' "user": {' +
|
|
|
|
' "label": "Username",' +
|
|
|
|
' "type": "wiki-user-name",' +
|
|
|
|
' "required": true,' +
|
|
|
|
' "description": "User name of person who forgot to sign their comment.",' +
|
|
|
|
' "aliases": ["1"]' +
|
|
|
|
' },' +
|
|
|
|
' "date": {' +
|
|
|
|
' "label": "Date",' +
|
|
|
|
' "description": {' +
|
|
|
|
' "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."' +
|
|
|
|
' },' +
|
|
|
|
' "aliases": ["2"],' +
|
|
|
|
' "autovalue": "{{subst:CURRENTMONTHNAME}}",' +
|
|
|
|
' "suggested": true' +
|
|
|
|
' },' +
|
|
|
|
' "year": {' +
|
|
|
|
' "label": "Year",' +
|
|
|
|
' "type": "number"' +
|
|
|
|
' },' +
|
|
|
|
' "month": {' +
|
|
|
|
' "label": "Month",' +
|
|
|
|
' "inherits": "year"' +
|
|
|
|
' },' +
|
|
|
|
' "day": {' +
|
|
|
|
' "label": "Day",' +
|
|
|
|
' "inherits": "year"' +
|
|
|
|
' },' +
|
|
|
|
' "comment": {' +
|
|
|
|
' "required": false' +
|
|
|
|
' }' +
|
|
|
|
' },' +
|
|
|
|
' "sets": [' +
|
|
|
|
' {' +
|
|
|
|
' "label": "Date",' +
|
|
|
|
' "params": ["year", "month", "day"]' +
|
|
|
|
' }' +
|
|
|
|
' ]' +
|
|
|
|
'}' +
|
|
|
|
'</templatedata>' +
|
|
|
|
'Trailing text at the end.';
|
|
|
|
|
|
|
|
// Prepare description language objects
|
|
|
|
resultDescCurrLang[currLanguage] = 'Some string here in ' + currLanguage + ' language.';
|
|
|
|
resultDescMockLang.blah = 'Some string here in blah language.';
|
|
|
|
resultDescBothLang = $.extend( {}, resultDescCurrLang, resultDescMockLang );
|
2015-01-06 00:04:51 +00:00
|
|
|
finalJsonStringParams = ' "params": {\n' +
|
2013-09-21 03:46:02 +00:00
|
|
|
' "user": {\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' "label": "Username",\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "type": "wiki-user-name",\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' "required": true,\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "description": "User name of person who forgot to sign their comment.",\n' +
|
|
|
|
' "aliases": [\n' +
|
|
|
|
' "1"\n' +
|
|
|
|
' ]\n' +
|
2013-09-21 03:46:02 +00:00
|
|
|
' },\n' +
|
|
|
|
' "date": {\n' +
|
|
|
|
' "label": "Date",\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "description": {\n' +
|
|
|
|
' "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
|
|
|
|
' },\n' +
|
|
|
|
' "aliases": [\n' +
|
|
|
|
' "2"\n' +
|
|
|
|
' ],\n' +
|
2014-09-02 15:29:33 +00:00
|
|
|
' "autovalue": "{{subst:CURRENTMONTHNAME}}",\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "suggested": true\n' +
|
2013-09-21 03:46:02 +00:00
|
|
|
' },\n' +
|
|
|
|
' "year": {\n' +
|
|
|
|
' "label": "Year",\n' +
|
|
|
|
' "type": "number"\n' +
|
|
|
|
' },\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "month": {\n' +
|
|
|
|
' "label": "Month",\n' +
|
|
|
|
' "inherits": "year"\n' +
|
|
|
|
' },\n' +
|
2013-09-21 03:46:02 +00:00
|
|
|
' "comment": {\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' "required": false,\n' +
|
|
|
|
' "type": "wiki-page-name"\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' },\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' "newParam1": {\n' +
|
|
|
|
' "description": {\n' +
|
|
|
|
' "' + currLanguage + '": "Some string here in ' + currLanguage + ' language.",\n' +
|
|
|
|
' "blah": "Some string here in blah language."\n' +
|
|
|
|
' },\n' +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "required": true\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' },\n' +
|
|
|
|
' "newParam2": {},\n' +
|
|
|
|
' "newParam3": {\n' +
|
2015-03-05 23:33:12 +00:00
|
|
|
' "description": "Some string here in ' + currLanguage + ' language.",\n' +
|
|
|
|
' "deprecated": "This is deprecated."\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
' },\n' +
|
|
|
|
' "newParam4": {\n' +
|
|
|
|
' "description": {\n' +
|
|
|
|
' "' + currLanguage + '": "' + resultDescBothLang[currLanguage] + '",\n' +
|
|
|
|
' "blah": "' + resultDescBothLang.blah + '"\n' +
|
|
|
|
' }\n' +
|
2013-09-21 03:46:02 +00:00
|
|
|
' }\n' +
|
2015-01-06 00:04:51 +00:00
|
|
|
' },\n';
|
|
|
|
finalJsonStringOnly = '{\n' +
|
|
|
|
' "description": {\n' +
|
|
|
|
' "' + currLanguage + '": "Label unsigned comments in a conversation.",\n' +
|
|
|
|
' "blah": "Template description in some blah language."\n' +
|
|
|
|
' },\n' + finalJsonStringParams +
|
2014-05-20 22:51:46 +00:00
|
|
|
' "sets": [\n' +
|
|
|
|
' {\n' +
|
|
|
|
' "label": "Date",\n' +
|
|
|
|
' "params": [\n' +
|
|
|
|
' "year",\n' +
|
|
|
|
' "month",\n' +
|
|
|
|
' "day"\n' +
|
|
|
|
' ]\n' +
|
|
|
|
' }\n' +
|
|
|
|
' ]\n' +
|
2014-10-11 05:22:21 +00:00
|
|
|
'}';
|
2015-01-06 00:04:51 +00:00
|
|
|
finalJsonStringOnlyParamOrder = '{\n' +
|
|
|
|
' "description": {\n' +
|
|
|
|
' "' + currLanguage + '": "Label unsigned comments in a conversation.",\n' +
|
|
|
|
' "blah": "Template description in some blah language."\n' +
|
|
|
|
' },\n' + finalJsonStringParams +
|
|
|
|
' "sets": [\n' +
|
|
|
|
' {\n' +
|
|
|
|
' "label": "Date",\n' +
|
|
|
|
' "params": [\n' +
|
|
|
|
' "year",\n' +
|
|
|
|
' "month",\n' +
|
|
|
|
' "day"\n' +
|
|
|
|
' ]\n' +
|
|
|
|
' }\n' +
|
|
|
|
' ],\n' +
|
|
|
|
' "paramOrder": [\n' +
|
|
|
|
' "date",\n' +
|
|
|
|
' "year",\n' +
|
|
|
|
' "user",\n' +
|
|
|
|
' "month",\n' +
|
|
|
|
' "comment",\n' +
|
|
|
|
' "newParam1",\n' +
|
|
|
|
' "newParam2",\n' +
|
|
|
|
' "newParam3",\n' +
|
|
|
|
' "newParam4"\n' +
|
|
|
|
' ]\n' +
|
|
|
|
'}';
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Test validation tools
|
|
|
|
QUnit.test( 'Validation tools', function ( assert ) {
|
|
|
|
var tests = {
|
2015-06-06 01:21:18 +00:00
|
|
|
compare: [
|
2014-10-11 05:22:21 +00:00
|
|
|
{
|
|
|
|
obj1: {},
|
|
|
|
obj2: [],
|
|
|
|
result: false,
|
|
|
|
msg: 'Compare: object vs array'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: null,
|
|
|
|
obj2: undefined,
|
|
|
|
result: false,
|
|
|
|
msg: 'Compare: null vs undefined'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: 'string',
|
|
|
|
obj2: undefined,
|
|
|
|
result: false,
|
|
|
|
msg: 'Compare: string vs undefined'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: undefined,
|
|
|
|
obj2: undefined,
|
|
|
|
result: true,
|
|
|
|
msg: 'Compare: undefined vs undefined'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: null,
|
|
|
|
obj2: null,
|
|
|
|
result: true,
|
|
|
|
msg: 'Compare: null vs null'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: 'A proper string.',
|
|
|
|
obj2: 'A proper string.',
|
|
|
|
result: true,
|
|
|
|
msg: 'Compare: strings'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: true,
|
|
|
|
obj2: true,
|
|
|
|
result: true,
|
|
|
|
msg: 'Compare: booleans'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
|
|
|
|
obj2: { 1: 'string', 2: 'another', 4: 'and another' },
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: plain object full equality'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
|
|
|
|
obj2: { 1: 'another', 2: 'and another', 4: 'string' },
|
|
|
|
result: false,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: plain object full inequality'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
|
|
|
|
obj2: { 4: 'and another' },
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: plain object subset equality'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: [ 'val1', 'val2', 'val3' ],
|
|
|
|
obj2: [ 'val1', 'val2', 'val3' ],
|
|
|
|
result: true,
|
|
|
|
msg: 'Compare: arrays'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: [ 'val1', 'val2', 'val3' ],
|
|
|
|
obj2: [ 'val1' ],
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: array subset: true'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: [ 'val1', 'val2', 'val3' ],
|
|
|
|
obj2: [ 'val1' ],
|
|
|
|
result: false,
|
|
|
|
allowSubset: false,
|
|
|
|
msg: 'Compare: array subset: false'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: {
|
|
|
|
param1: {
|
|
|
|
type: 'undefined',
|
|
|
|
aliases: [ 'alias2', 'alias1', 'alias3' ],
|
|
|
|
description: 'Some description',
|
|
|
|
required: true,
|
|
|
|
suggested: false
|
|
|
|
},
|
|
|
|
param2: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
obj2: {
|
|
|
|
param1: {
|
|
|
|
type: 'undefined',
|
|
|
|
aliases: [ 'alias2', 'alias1', 'alias3' ],
|
|
|
|
description: 'Some description',
|
|
|
|
required: true,
|
|
|
|
suggested: false
|
|
|
|
},
|
|
|
|
param2: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: complex objects'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: {
|
|
|
|
param1: {
|
|
|
|
type: 'undefined',
|
|
|
|
aliases: [ 'alias1', 'alias2', 'alias3' ],
|
|
|
|
description: 'Some description',
|
|
|
|
required: true,
|
|
|
|
suggested: false
|
|
|
|
},
|
|
|
|
param2: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
obj2: {
|
|
|
|
param1: {
|
|
|
|
aliases: [ 'alias1', 'alias2', 'alias3' ],
|
|
|
|
suggested: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: complex objects subset'
|
|
|
|
}
|
|
|
|
],
|
2015-06-06 01:21:18 +00:00
|
|
|
splitAndTrimArray: [
|
2014-10-11 05:22:21 +00:00
|
|
|
{
|
|
|
|
string: 'str1 , str2 ',
|
|
|
|
delim: ',',
|
|
|
|
result: [ 'str1', 'str2' ],
|
|
|
|
msg: 'splitAndTrimArray: split and trim'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
string: 'str1, str2, , , , str3',
|
|
|
|
delim: ',',
|
|
|
|
result: [ 'str1', 'str2', 'str3' ],
|
|
|
|
msg: 'splitAndTrimArray: remove empty values'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
string: 'str1|str2|str3',
|
|
|
|
delim: '|',
|
|
|
|
result: [ 'str1', 'str2', 'str3' ],
|
|
|
|
msg: 'splitAndTrimArray: different delimeter'
|
|
|
|
}
|
|
|
|
],
|
2015-06-06 01:21:18 +00:00
|
|
|
arrayUnionWithoutEmpty: [
|
2014-10-11 05:22:21 +00:00
|
|
|
{
|
|
|
|
arrays: [ [ 'en', 'he', '' ], [ 'he', 'de', '' ], [ 'en', 'de' ] ],
|
|
|
|
result: [ 'en', 'he', 'de' ],
|
|
|
|
msg: 'arrayUnionWithoutEmpty: Remove duplications'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arrays: [ [ 'en', '', '' ], [ 'he', '', '' ], [ 'de', '' ] ],
|
|
|
|
result: [ 'en', 'he', 'de' ],
|
|
|
|
msg: 'arrayUnionWithoutEmpty: Remove empty values'
|
|
|
|
}
|
|
|
|
],
|
2015-06-06 01:21:18 +00:00
|
|
|
props: {
|
|
|
|
all: [
|
2014-10-11 05:22:21 +00:00
|
|
|
'name',
|
|
|
|
'aliases',
|
|
|
|
'label',
|
|
|
|
'description',
|
2015-03-04 20:32:38 +00:00
|
|
|
'example',
|
2014-10-11 05:22:21 +00:00
|
|
|
'type',
|
|
|
|
'default',
|
|
|
|
'autovalue',
|
2015-01-16 18:56:06 +00:00
|
|
|
'deprecated',
|
2015-03-05 23:33:12 +00:00
|
|
|
'deprecatedValue',
|
2014-10-11 05:22:21 +00:00
|
|
|
'required',
|
|
|
|
'suggested'
|
|
|
|
],
|
2015-06-06 01:21:18 +00:00
|
|
|
language: [
|
2014-10-11 05:22:21 +00:00
|
|
|
'label',
|
2015-03-09 21:45:04 +00:00
|
|
|
'description',
|
2015-03-04 20:32:38 +00:00
|
|
|
'example',
|
2015-03-09 21:45:04 +00:00
|
|
|
'default'
|
2014-10-11 05:22:21 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
QUnit.expect(
|
|
|
|
tests.compare.length +
|
|
|
|
tests.splitAndTrimArray.length +
|
|
|
|
tests.arrayUnionWithoutEmpty.length +
|
|
|
|
Object.keys( tests.props ).length
|
|
|
|
);
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Compare
|
|
|
|
for ( i = 0; i < tests.compare.length; i++ ) {
|
|
|
|
testVars = tests.compare[i];
|
|
|
|
assert.equal(
|
2015-02-17 23:56:44 +00:00
|
|
|
mw.TemplateData.Model.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ),
|
2014-10-11 05:22:21 +00:00
|
|
|
testVars.result,
|
|
|
|
testVars.msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split and trim
|
|
|
|
for ( i = 0; i < tests.splitAndTrimArray.length; i++ ) {
|
|
|
|
testVars = tests.splitAndTrimArray[i];
|
2014-05-20 22:51:46 +00:00
|
|
|
assert.deepEqual(
|
2015-02-17 23:56:44 +00:00
|
|
|
mw.TemplateData.Model.static.splitAndTrimArray( testVars.string, testVars.delim ),
|
2014-10-11 05:22:21 +00:00
|
|
|
testVars.result,
|
|
|
|
testVars.msg
|
2014-05-20 22:51:46 +00:00
|
|
|
);
|
2014-10-11 05:22:21 +00:00
|
|
|
}
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// arrayUnionWithoutEmpty
|
|
|
|
for ( i = 0; i < tests.arrayUnionWithoutEmpty.length; i++ ) {
|
|
|
|
testVars = tests.arrayUnionWithoutEmpty[i];
|
|
|
|
assert.deepEqual(
|
2015-02-17 23:56:44 +00:00
|
|
|
mw.TemplateData.Model.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ),
|
2014-10-11 05:22:21 +00:00
|
|
|
testVars.result,
|
|
|
|
testVars.msg
|
2014-05-20 22:51:46 +00:00
|
|
|
);
|
2014-10-11 05:22:21 +00:00
|
|
|
}
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Props
|
|
|
|
assert.deepEqual(
|
2015-02-17 23:56:44 +00:00
|
|
|
mw.TemplateData.Model.static.getAllProperties( false ),
|
2014-10-11 05:22:21 +00:00
|
|
|
tests.props.all,
|
|
|
|
'All properties'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
2015-02-17 23:56:44 +00:00
|
|
|
mw.TemplateData.Model.static.getPropertiesWithLanguage(),
|
2014-10-11 05:22:21 +00:00
|
|
|
tests.props.language,
|
|
|
|
'Language properties'
|
|
|
|
);
|
|
|
|
} );
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Test model load
|
|
|
|
QUnit.asyncTest( 'TemplateData model', function ( assert ) {
|
|
|
|
var i,
|
2015-03-07 00:17:21 +00:00
|
|
|
sourceHandler = new mw.TemplateData.SourceHandler(),
|
2014-10-11 05:22:21 +00:00
|
|
|
paramAddTest = [
|
|
|
|
{
|
|
|
|
key: 'newParam1',
|
|
|
|
data: { required: true },
|
|
|
|
result: { name: 'newParam1', required: true },
|
|
|
|
description: '',
|
|
|
|
msg: 'Adding a simple parameter.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam2',
|
|
|
|
data: null,
|
|
|
|
result: { name: 'newParam2' },
|
|
|
|
description: '',
|
|
|
|
msg: 'Adding new parameter without data.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam3',
|
|
|
|
data: { description: 'Some string here in ' + currLanguage + ' language.' },
|
|
|
|
result: { name: 'newParam3', description: resultDescCurrLang },
|
|
|
|
description: 'Some string here in ' + currLanguage + ' language.',
|
|
|
|
msg: 'Adding parameter with language prop: original without language.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam4',
|
|
|
|
data: {
|
|
|
|
description: resultDescBothLang
|
|
|
|
},
|
|
|
|
result: { name: 'newParam4', description: resultDescBothLang },
|
|
|
|
description: 'Some string here in ' + currLanguage + ' language.',
|
|
|
|
msg: 'Adding parameter with language prop: original with multiple languages.'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
paramChangeTest = [
|
|
|
|
{
|
|
|
|
key: 'newParam1',
|
|
|
|
property: 'description',
|
|
|
|
language: 'en',
|
|
|
|
value: resultDescCurrLang[currLanguage],
|
|
|
|
result: $.extend( {}, paramAddTest[0].result, {
|
|
|
|
description: resultDescCurrLang
|
|
|
|
} ),
|
|
|
|
msg: 'Adding description in current language.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam1',
|
|
|
|
property: 'description',
|
|
|
|
language: 'blah',
|
|
|
|
value: resultDescMockLang.blah,
|
|
|
|
result: $.extend( {}, paramAddTest[0].result, {
|
|
|
|
description: $.extend( {}, resultDescCurrLang, resultDescMockLang )
|
|
|
|
} ),
|
|
|
|
msg: 'Adding description in mock language.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'comment',
|
|
|
|
property: 'type',
|
|
|
|
value: 'wiki-page-name',
|
|
|
|
result: {
|
|
|
|
name: 'comment',
|
|
|
|
type: 'wiki-page-name',
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
msg: 'Adding type to comment.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam2',
|
|
|
|
property: 'description',
|
|
|
|
language: 'blah',
|
|
|
|
value: '',
|
|
|
|
result: $.extend( {}, paramAddTest[1].result, {
|
2015-06-06 01:21:18 +00:00
|
|
|
description: { blah: '' }
|
2014-10-11 05:22:21 +00:00
|
|
|
} ),
|
|
|
|
msg: 'Adding empty description in mock language.'
|
2015-03-05 23:33:12 +00:00
|
|
|
},
|
2015-03-12 20:51:59 +00:00
|
|
|
{
|
|
|
|
key: 'newParam3',
|
|
|
|
property: 'deprecated',
|
|
|
|
value: true,
|
|
|
|
result: $.extend( {}, paramAddTest[2].result, {
|
|
|
|
deprecated: true
|
|
|
|
} ),
|
|
|
|
msg: 'Adding deprecated property (boolean).'
|
|
|
|
},
|
2015-03-05 23:33:12 +00:00
|
|
|
{
|
|
|
|
key: 'newParam3',
|
|
|
|
property: 'deprecatedValue',
|
|
|
|
value: 'This is deprecated.',
|
|
|
|
result: $.extend( {}, paramAddTest[2].result, {
|
|
|
|
deprecated: true,
|
|
|
|
deprecatedValue: 'This is deprecated.'
|
|
|
|
} ),
|
2015-03-12 20:51:59 +00:00
|
|
|
msg: 'Adding deprecated property (string).'
|
2014-10-11 05:22:21 +00:00
|
|
|
}
|
|
|
|
];
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
QUnit.expect(
|
|
|
|
// Description and parameter list
|
|
|
|
3 +
|
|
|
|
// Add parameter tests
|
|
|
|
2 * paramAddTest.length +
|
|
|
|
// Change properties tests
|
|
|
|
paramChangeTest.length +
|
|
|
|
// Json output
|
2015-01-06 00:04:51 +00:00
|
|
|
2
|
2014-10-11 05:22:21 +00:00
|
|
|
);
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2015-03-07 00:17:21 +00:00
|
|
|
sourceHandler.buildModel( originalWikitext )
|
|
|
|
.done( function ( model ) {
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Check description
|
|
|
|
assert.equal(
|
|
|
|
model.getTemplateDescription(),
|
|
|
|
'Label unsigned comments in a conversation.',
|
|
|
|
'Description in default language.'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
model.getTemplateDescription( 'blah' ),
|
|
|
|
'Template description in some blah language.',
|
|
|
|
'Description in mock language.'
|
|
|
|
);
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Check parameters
|
|
|
|
assert.deepEqual(
|
|
|
|
Object.keys( model.getParams() ),
|
|
|
|
[ 'user', 'date', 'year', 'month', 'day', 'comment' ],
|
|
|
|
'Parameters retention.'
|
|
|
|
);
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
for ( i = 0; i < paramAddTest.length; i++ ) {
|
|
|
|
// Add parameter
|
|
|
|
model.addParam( paramAddTest[i].key, paramAddTest[i].data );
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Test new param data
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getParamData( paramAddTest[i].key ),
|
|
|
|
paramAddTest[i].result,
|
|
|
|
paramAddTest[i].msg + ' (parameter data)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check description in current language
|
|
|
|
assert.equal(
|
|
|
|
model.getParamDescription( paramAddTest[i].key, currLanguage ),
|
|
|
|
paramAddTest[i].description,
|
|
|
|
paramAddTest[i].msg + ' (description in current language)'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change parameter properties
|
|
|
|
for ( i = 0; i < paramChangeTest.length; i++ ) {
|
|
|
|
testVars = paramChangeTest[i];
|
|
|
|
model.setParamProperty( testVars.key, testVars.property, testVars.value, testVars.language );
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getParamData( testVars.key ),
|
|
|
|
paramChangeTest[i].result,
|
|
|
|
paramChangeTest[i].msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete parameter
|
|
|
|
model.deleteParam( 'day' );
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
// Ouput a final templatedata string
|
|
|
|
assert.equal(
|
|
|
|
model.outputTemplateDataString(),
|
|
|
|
finalJsonStringOnly,
|
|
|
|
'Final templatedata output'
|
|
|
|
);
|
2013-09-21 03:46:02 +00:00
|
|
|
|
2015-01-06 00:04:51 +00:00
|
|
|
// Change order and verify result now has paramOrder
|
|
|
|
model.reorderParamOrderKey( 'user', 2 );
|
|
|
|
// Ouput a final templatedata string
|
|
|
|
assert.equal(
|
|
|
|
model.outputTemplateDataString(),
|
|
|
|
finalJsonStringOnlyParamOrder,
|
|
|
|
'Final templatedata output with paramOrder'
|
|
|
|
);
|
|
|
|
|
2014-10-11 05:22:21 +00:00
|
|
|
} )
|
|
|
|
.always( function () {
|
|
|
|
QUnit.start();
|
|
|
|
} );
|
2013-09-21 03:46:02 +00:00
|
|
|
} );
|
|
|
|
|
2015-03-07 00:17:21 +00:00
|
|
|
// Test model fail
|
|
|
|
QUnit.asyncTest( 'TemplateData sourceHandler', function ( assert ) {
|
|
|
|
var sourceHandler = new mw.TemplateData.SourceHandler(),
|
|
|
|
erronousString = '<templatedata>{\n' +
|
|
|
|
' "params": {\n' +
|
|
|
|
// Open quote
|
|
|
|
' "user: {\n' +
|
|
|
|
' "label": "Username",\n' +
|
|
|
|
' "type": "wiki-user-name",\n' +
|
|
|
|
' "required": true,\n' +
|
|
|
|
' "description": "User name of person who forgot to sign their comment.",\n' +
|
|
|
|
' "aliases": [\n' +
|
|
|
|
' "1"\n' +
|
|
|
|
' ]\n' +
|
|
|
|
' },\n' +
|
|
|
|
' "date": {\n' +
|
|
|
|
' "label": "Date",\n' +
|
|
|
|
' "description": {\n' +
|
|
|
|
// Forgotten quotes
|
|
|
|
' en: "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
|
|
|
|
' }\n' +
|
|
|
|
' "suggested": true\n' +
|
|
|
|
' }\n' +
|
|
|
|
' }\n' +
|
|
|
|
'}</templatedata>';
|
|
|
|
|
|
|
|
QUnit.expect( 1 );
|
|
|
|
|
|
|
|
sourceHandler.buildModel( erronousString )
|
|
|
|
.always( function () {
|
|
|
|
assert.ok( this.state() === 'rejected', 'Promise rejected on erronous json string.' );
|
|
|
|
QUnit.start();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-02-17 23:56:44 +00:00
|
|
|
}() );
|