Tests for some trivial but critical template model methods

Not only do we want to make sure getUniquePartId() always starts
at 0 and increments correctly, it should return a number (and
not e.g. "part_0").

I realize the getTitle() test is also testing functionality from
mw.libs.ve.… (can be found in the file ve.utils.parsoid.js).
This is intentional. What we care about at this point is not a
library but the very specific functionality of a very specific
method we use quite a lot in code we touch.

Bug: T289560
Change-Id: I43c1d00dacf27a68b16f62ecca4adda22f437391
This commit is contained in:
Thiemo Kreuz 2021-08-27 13:00:35 +02:00 committed by Thiemo Kreuz (WMDE)
parent e778057389
commit 55beccbb79
2 changed files with 20 additions and 0 deletions

View file

@ -36,6 +36,19 @@
/* Tests */
[
[ undefined, null ],
[ '', null ],
[ 'no_prefix', 'no prefix' ],
[ '/unexpected_prefix', '/unexpected prefix' ],
[ './Template:%C3%9Cnicode%5Fexample/subpage', 'Template:Ünicode example/subpage' ],
[ './Template:Possibly_invalid%5B%5D', 'Template:Possibly invalid[]' ]
].forEach( ( [ href, expected ] ) => QUnit.test( 'getTitle: ' + href, ( assert ) => {
const transclusion = { getUniquePartId: () => 0 },
template = new ve.dm.MWTemplateModel( transclusion, { href } );
assert.strictEqual( template.getTitle(), expected );
} ) );
QUnit.test( 'hasParameter', ( assert ) => {
const template = newTemplateModel();

View file

@ -35,6 +35,13 @@
} );
}
QUnit.test( 'getUniquePartId', function ( assert ) {
const transclusion = new ve.dm.MWTransclusionModel();
assert.strictEqual( transclusion.getUniquePartId(), 0 );
assert.strictEqual( transclusion.getUniquePartId(), 1 );
assert.strictEqual( transclusion.getUniquePartId(), 2 );
} );
QUnit.test( 'fetch template part data', function ( assert ) {
const response = {
batchcomplete: '',