mediawiki-extensions-Visual.../modules/ve/test/dm/nodes/ve.dm.MWTransclusionNode.test.js
Trevor Parscal d3a2fab2c4 Transclusion editing
Objectives:

* Rename just about every use of "template" to "transclusion"
* Make a proper data structure for transclusions
* Abstract away template data
* Use more template data in the user interface
* Allow adding parameters
* Allow removing templates, parameters and content

Changes:

ve.ui.Dialog.css
* Add rule to place add param controls on a single line

ve.ui.MWTemplateDialogs.js
* Move template spec loading into transclusion class
* Add remove button for parts and parameters
* Add parameter adding form
* Use template data for labels and descriptions

ve.dm.*
* Add new transclusion data structures

*.php
* Add links to new files

*.*
* Rename all things "template" to "transclusion"

Bug: 39598
Bug: 49403
Change-Id: I3bcf924a3e179cb65f19e833277a39dfd3dad8bd
2013-06-12 16:39:13 -07:00

74 lines
1.9 KiB
JavaScript

/*!
* VisualEditor DataModel MWTransclusionNode tests.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.MWTransclusionNode' );
/* Tests */
QUnit.test( 'getWikitext', function ( assert ) {
var i, node, cases = [
{
'msg': 'mix of numbered and named parameters',
'mw': {
'target': { 'wt': 'foo' },
'params': {
'1': { 'wt': 'bar' },
'baz': { 'wt': 'quux' }
}
},
'wikitext': '{{foo|1=bar|baz=quux}}'
},
{
'msg': 'parameter with self-closing nowiki',
'mw': {
'target': { 'wt': 'foo' },
'params': {
'bar': { 'wt': 'l\'<nowiki />\'\'\'Étranger\'\'\'' }
}
},
'wikitext': '{{foo|bar=l\'<nowiki />\'\'\'Étranger\'\'\'}}'
},
{
'msg': 'parameter with self-closing nowiki without space',
'mw': {
'target': { 'wt': 'foo' },
'params': {
'bar': { 'wt': 'l\'<nowiki/>\'\'\'Étranger\'\'\'' }
}
},
'wikitext': '{{foo|bar=l\'<nowiki/>\'\'\'Étranger\'\'\'}}'
},
{
'msg': 'parameter with spanning-nowiki',
'mw': {
'target': { 'wt': 'foo' },
'params': {
'bar': { 'wt': 'You should use <nowiki>\'\'\'</nowiki> to make things bold.' }
}
},
'wikitext': '{{foo|bar=You should use <nowiki>\'\'\'</nowiki> to make things bold.}}'
},
{
'msg': 'parameter with spanning-nowiki and nested transclusion',
'mw': {
'target': { 'wt': 'foo' },
'params': {
'bar': { 'wt': 'You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!' }
}
},
'wikitext': '{{foo|bar=You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!}}'
}
];
QUnit.expect( cases.length );
for ( i = 0; i < cases.length; i++ ) {
node = new ve.dm.MWTransclusionNode( 0,
{ 'type': 'mwTransclusion', 'attributes': { 'mw': cases[i].mw } }
);
assert.deepEqual( node.getWikitext(), cases[i].wikitext, cases[i].msg );
}
} );