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';
|
|
|
|
|
2016-02-20 15:29:45 +00:00
|
|
|
var i, testVars, finalJsonParams, finalJson,
|
2015-09-17 20:10:33 +00:00
|
|
|
resultDescCurrLang, resultDescMockLang, resultDescBothLang, currLanguage, originalWikitext;
|
|
|
|
|
2013-09-21 03:46:02 +00:00
|
|
|
QUnit.module( 'ext.templateData', QUnit.newMwEnvironment() );
|
|
|
|
|
2015-09-17 20:10:33 +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": {' +
|
2016-02-20 15:29:45 +00:00
|
|
|
' "' + currLanguage + '": "Timestamp of when the comment was posted, in YYYY-MM-DD format."' +
|
2015-09-17 20:10:33 +00:00
|
|
|
' },' +
|
|
|
|
' "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.';
|
2014-10-11 05:22:21 +00:00
|
|
|
|
|
|
|
// Prepare description language objects
|
2015-09-17 20:10:33 +00:00
|
|
|
resultDescCurrLang[ currLanguage ] = 'Some string here in ' + currLanguage + ' language.';
|
2014-10-11 05:22:21 +00:00
|
|
|
resultDescMockLang.blah = 'Some string here in blah language.';
|
|
|
|
resultDescBothLang = $.extend( {}, resultDescCurrLang, resultDescMockLang );
|
2016-02-20 15:29:45 +00:00
|
|
|
finalJsonParams = {
|
|
|
|
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: {
|
|
|
|
// currLanguage goes here
|
|
|
|
},
|
|
|
|
aliases: [ '2' ],
|
|
|
|
autovalue: '{{subst:CURRENTMONTHNAME}}',
|
|
|
|
suggested: true,
|
|
|
|
type: undefined
|
|
|
|
},
|
|
|
|
year: {
|
|
|
|
label: 'Year',
|
|
|
|
type: 'number'
|
|
|
|
},
|
|
|
|
month: {
|
|
|
|
label: 'Month',
|
|
|
|
inherits: 'year',
|
|
|
|
type: undefined
|
|
|
|
},
|
|
|
|
comment: {
|
|
|
|
required: false,
|
|
|
|
type: 'wiki-page-name'
|
|
|
|
},
|
|
|
|
newParam1: {
|
|
|
|
description: {
|
|
|
|
blah: 'Some string here in blah language.'
|
|
|
|
},
|
|
|
|
required: true,
|
|
|
|
type: undefined
|
|
|
|
},
|
|
|
|
newParam2: {
|
|
|
|
description: undefined,
|
|
|
|
type: undefined
|
|
|
|
},
|
|
|
|
newParam3: {
|
|
|
|
description: 'Some string here in ' + currLanguage + ' language.',
|
|
|
|
deprecated: 'This is deprecated.',
|
|
|
|
type: undefined
|
|
|
|
},
|
|
|
|
newParam4: {
|
|
|
|
description: {
|
|
|
|
// currLanguage goes here
|
|
|
|
blah: resultDescBothLang.blah
|
|
|
|
},
|
|
|
|
type: undefined
|
2016-04-06 23:39:24 +00:00
|
|
|
},
|
|
|
|
newParam5: {
|
|
|
|
type: 'wiki-page-name'
|
2016-02-20 15:29:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
finalJsonParams.date.description[ currLanguage ] = 'Timestamp of when the comment was posted, in YYYY-MM-DD format.';
|
|
|
|
finalJsonParams.newParam1.description[ currLanguage ] = 'Some string here in ' + currLanguage + ' language.';
|
|
|
|
finalJsonParams.newParam4.description[ currLanguage ] = resultDescBothLang[ currLanguage ];
|
|
|
|
|
|
|
|
finalJson = {
|
|
|
|
description: {
|
|
|
|
blah: 'Template description in some blah language.'
|
|
|
|
},
|
|
|
|
params: finalJsonParams,
|
|
|
|
sets: [
|
|
|
|
{
|
|
|
|
label: 'Date',
|
|
|
|
params: [
|
|
|
|
'year',
|
|
|
|
'month',
|
|
|
|
'day'
|
|
|
|
]
|
|
|
|
}
|
2016-04-06 22:23:45 +00:00
|
|
|
]
|
2016-02-20 15:29:45 +00:00
|
|
|
};
|
|
|
|
finalJson.description[ currLanguage ] = 'Label unsigned comments in a conversation.';
|
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: {
|
2016-01-13 19:29:05 +00:00
|
|
|
type: 'unknown',
|
2014-10-11 05:22:21 +00:00
|
|
|
aliases: [ 'alias2', 'alias1', 'alias3' ],
|
|
|
|
description: 'Some description',
|
|
|
|
required: true,
|
|
|
|
suggested: false
|
|
|
|
},
|
|
|
|
param2: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
obj2: {
|
|
|
|
param1: {
|
2016-01-13 19:29:05 +00:00
|
|
|
type: 'unknown',
|
2014-10-11 05:22:21 +00:00
|
|
|
aliases: [ 'alias2', 'alias1', 'alias3' ],
|
|
|
|
description: 'Some description',
|
|
|
|
required: true,
|
|
|
|
suggested: false
|
|
|
|
},
|
|
|
|
param2: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
result: true,
|
|
|
|
allowSubset: true,
|
|
|
|
msg: 'Compare: complex objects'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
obj1: {
|
|
|
|
param1: {
|
2016-01-13 19:29:05 +00:00
|
|
|
type: 'unknown',
|
2014-10-11 05:22:21 +00:00
|
|
|
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++ ) {
|
2015-09-17 20:10:33 +00:00
|
|
|
testVars = tests.compare[ i ];
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.strictEqual(
|
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++ ) {
|
2015-09-17 20:10:33 +00:00
|
|
|
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++ ) {
|
2015-09-17 20:10:33 +00:00
|
|
|
testVars = tests.arrayUnionWithoutEmpty[ i ];
|
2014-10-11 05:22:21 +00:00
|
|
|
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.'
|
2016-04-06 23:39:24 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam5',
|
|
|
|
data: { type: 'string/wiki-page-name' },
|
|
|
|
result: { name: 'newParam5', type: 'wiki-page-name' },
|
|
|
|
description: '',
|
|
|
|
msg: 'Adding parameter with obsolete type'
|
2014-10-11 05:22:21 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
paramChangeTest = [
|
|
|
|
{
|
|
|
|
key: 'newParam1',
|
|
|
|
property: 'description',
|
2016-02-20 15:29:45 +00:00
|
|
|
language: currLanguage,
|
2015-09-17 20:10:33 +00:00
|
|
|
value: resultDescCurrLang[ currLanguage ],
|
|
|
|
result: $.extend( {}, paramAddTest[ 0 ].result, {
|
2014-10-11 05:22:21 +00:00
|
|
|
description: resultDescCurrLang
|
|
|
|
} ),
|
|
|
|
msg: 'Adding description in current language.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'newParam1',
|
|
|
|
property: 'description',
|
|
|
|
language: 'blah',
|
|
|
|
value: resultDescMockLang.blah,
|
2015-09-17 20:10:33 +00:00
|
|
|
result: $.extend( {}, paramAddTest[ 0 ].result, {
|
2014-10-11 05:22:21 +00:00
|
|
|
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: '',
|
2015-09-17 20:10:33 +00:00
|
|
|
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,
|
2015-09-17 20:10:33 +00:00
|
|
|
result: $.extend( {}, paramAddTest[ 2 ].result, {
|
2015-03-12 20:51:59 +00:00
|
|
|
deprecated: true
|
|
|
|
} ),
|
|
|
|
msg: 'Adding deprecated property (boolean).'
|
|
|
|
},
|
2015-03-05 23:33:12 +00:00
|
|
|
{
|
|
|
|
key: 'newParam3',
|
|
|
|
property: 'deprecatedValue',
|
|
|
|
value: 'This is deprecated.',
|
2015-09-17 20:10:33 +00:00
|
|
|
result: $.extend( {}, paramAddTest[ 2 ].result, {
|
2015-03-05 23:33:12 +00:00
|
|
|
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
|
2016-02-20 13:46:12 +00:00
|
|
|
3
|
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
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.strictEqual(
|
2014-10-11 05:22:21 +00:00
|
|
|
model.getTemplateDescription(),
|
|
|
|
'Label unsigned comments in a conversation.',
|
|
|
|
'Description in default language.'
|
|
|
|
);
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.strictEqual(
|
2014-10-11 05:22:21 +00:00
|
|
|
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
|
2015-09-17 20:10:33 +00:00
|
|
|
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(
|
2015-09-17 20:10:33 +00:00
|
|
|
model.getParamData( paramAddTest[ i ].key ),
|
|
|
|
paramAddTest[ i ].result,
|
|
|
|
paramAddTest[ i ].msg + ' (parameter data)'
|
2014-10-11 05:22:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Check description in current language
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.strictEqual(
|
2016-02-20 14:34:37 +00:00
|
|
|
model.getParamValue( paramAddTest[ i ].key, 'description', currLanguage ),
|
2015-09-17 20:10:33 +00:00
|
|
|
paramAddTest[ i ].description,
|
|
|
|
paramAddTest[ i ].msg + ' (description in current language)'
|
2014-10-11 05:22:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change parameter properties
|
|
|
|
for ( i = 0; i < paramChangeTest.length; i++ ) {
|
2015-09-17 20:10:33 +00:00
|
|
|
testVars = paramChangeTest[ i ];
|
2014-10-11 05:22:21 +00:00
|
|
|
model.setParamProperty( testVars.key, testVars.property, testVars.value, testVars.language );
|
|
|
|
assert.deepEqual(
|
|
|
|
model.getParamData( testVars.key ),
|
2015-09-17 20:10:33 +00:00
|
|
|
paramChangeTest[ i ].result,
|
|
|
|
paramChangeTest[ i ].msg
|
2014-10-11 05:22:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete parameter
|
|
|
|
model.deleteParam( 'day' );
|
2014-05-20 22:51:46 +00:00
|
|
|
|
2016-02-20 15:29:45 +00:00
|
|
|
// Ouput a final templatedata
|
|
|
|
assert.deepEqual(
|
|
|
|
model.outputTemplateData(),
|
|
|
|
finalJson,
|
2014-10-11 05:22:21 +00:00
|
|
|
'Final templatedata output'
|
|
|
|
);
|
2013-09-21 03:46:02 +00:00
|
|
|
|
2016-02-20 13:46:12 +00:00
|
|
|
// Move 'user' to offset 3 (in original array), i.e. after 'year'
|
|
|
|
model.reorderParamOrderKey( 'user', 3 );
|
|
|
|
assert.deepEqual(
|
|
|
|
model.paramOrder,
|
2016-04-06 23:39:24 +00:00
|
|
|
[ 'date', 'year', 'user', 'month', 'comment', 'newParam1', 'newParam2', 'newParam3', 'newParam4', 'newParam5' ],
|
2016-02-20 13:46:12 +00:00
|
|
|
'Final templatedata output with paramOrder'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Move 'month' to offset 2, i.e. after 'year'
|
|
|
|
model.reorderParamOrderKey( 'month', 2 );
|
|
|
|
assert.deepEqual(
|
|
|
|
model.paramOrder,
|
2016-04-06 23:39:24 +00:00
|
|
|
[ 'date', 'year', 'month', 'user', 'comment', 'newParam1', 'newParam2', 'newParam3', 'newParam4', 'newParam5' ],
|
2015-01-06 00:04:51 +00:00
|
|
|
'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
|
2016-02-20 15:29:45 +00:00
|
|
|
' ' + currLanguage + ': "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
|
2015-03-07 00:17:21 +00:00
|
|
|
' }\n' +
|
|
|
|
' "suggested": true\n' +
|
|
|
|
' }\n' +
|
|
|
|
' }\n' +
|
|
|
|
'}</templatedata>';
|
|
|
|
|
|
|
|
QUnit.expect( 1 );
|
|
|
|
|
|
|
|
sourceHandler.buildModel( erronousString )
|
|
|
|
.always( function () {
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.strictEqual( this.state(), 'rejected', 'Promise rejected on erronous json string.' );
|
2015-03-07 00:17:21 +00:00
|
|
|
QUnit.start();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-10-02 10:34:57 +00:00
|
|
|
// Test model gets default format
|
|
|
|
QUnit.asyncTest( 'TemplateData sourceHandler adding default format', function ( assert ) {
|
|
|
|
var sourceHandler = new mw.TemplateData.SourceHandler(),
|
|
|
|
simpleTemplateDataNoFormat = '<templatedata>{\n' +
|
|
|
|
' "params": {}\n' +
|
|
|
|
'}</templatedata>',
|
2016-02-20 15:29:45 +00:00
|
|
|
simpleTemplateDataDefaultFormat = {
|
2016-04-06 22:23:45 +00:00
|
|
|
params: {}
|
2016-02-20 15:29:45 +00:00
|
|
|
};
|
2015-10-02 10:34:57 +00:00
|
|
|
|
|
|
|
QUnit.expect( 1 );
|
|
|
|
|
|
|
|
sourceHandler.buildModel( simpleTemplateDataNoFormat )
|
|
|
|
.done( function ( model ) {
|
2016-02-20 15:29:45 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
model.outputTemplateData(),
|
2015-10-02 10:34:57 +00:00
|
|
|
simpleTemplateDataDefaultFormat,
|
|
|
|
'Final templatedata output'
|
|
|
|
);
|
|
|
|
} )
|
|
|
|
.always( function () {
|
|
|
|
QUnit.start();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-02-17 23:56:44 +00:00
|
|
|
}() );
|