mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-23 19:43:19 +00:00
6cbedbf9d2
* Remove need for manual hacking of sub groups via "msg" strings carefully prepended to every assertion. * Improve CI details, by reporting the specific case that failed, and local dev via ability to re-run each case, and reporting names directly in the HTML Reporter and CLI summary. * Reduce need for assert.async() and tracking of callbacks, especially to improve failure details in case of Promise rejection. Current logic was likely to cause a confusing timeout instead of a clear failure if the promise ends up rejected. QUnit propagates these as part of awaiting and asserting the test closure's promise value (as async fn) automatically. This approach also avoids the pitfal of a falsely passing test when an assertion inside a done() handler was never reached. * Use modern for-of where possible to remove need for closures and arrow functions. Thus reducing complexity of test code, where complexity should be kept lowest to avoid false confidence. * Use plain for-in instead of overly complex Object.keys().forEach(). Change-Id: I934a266e75e64371081f104cfb867fb2c282c84a
100 lines
2.5 KiB
JavaScript
100 lines
2.5 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTransclusionNode tests.
|
|
*
|
|
* @copyright See AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.dm.MWTransclusionNode' );
|
|
|
|
QUnit.test.each( 'getWikitext', {
|
|
'mix of numbered and named parameters': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
1: { wt: 'bar' },
|
|
baz: { wt: 'quux' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|1=bar|baz=quux}}'
|
|
},
|
|
'parameter with self-closing nowiki': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'l\'<nowiki />\'\'\'Étranger\'\'\'' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=l\'<nowiki />\'\'\'Étranger\'\'\'}}'
|
|
},
|
|
'parameter with self-closing nowiki without space': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'l\'<nowiki/>\'\'\'Étranger\'\'\'' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=l\'<nowiki/>\'\'\'Étranger\'\'\'}}'
|
|
},
|
|
'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.}}'
|
|
},
|
|
'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!}}'
|
|
},
|
|
'parameter containing another template invocation': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '{{ping|foo=bar|2=1}}' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar={{ping|foo=bar|2=1}}}}'
|
|
},
|
|
'parameter containing another parameter': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '{{{1}}}' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar={{{1}}}}}'
|
|
},
|
|
'parameter containing unmatched close brackets and floating pipes': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '}} | {{a|{{b}}}} |' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=<nowiki>}}</nowiki> <nowiki>|</nowiki> {{a|{{b}}}} <nowiki>|</nowiki>}}'
|
|
},
|
|
'parameter containing piped link': {
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '[[baz|quux]]' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=[[baz|quux]]}}'
|
|
}
|
|
}, ( assert, caseItem ) => {
|
|
const node = new ve.dm.MWTransclusionNode(
|
|
{ type: 'mwTransclusion', attributes: { mw: caseItem.mw } }
|
|
);
|
|
assert.strictEqual( node.getWikitext(), caseItem.wikitext );
|
|
}
|
|
);
|