2021-09-20 08:27:37 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTemplateModel tests.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2021-09-20 08:27:37 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2021-10-13 13:21:04 +00:00
|
|
|
{
|
2021-09-20 08:27:37 +00:00
|
|
|
const transclusionData = {
|
|
|
|
params: {
|
|
|
|
foo: { wt: 'Foo value' },
|
|
|
|
bar: { wt: 'Bar value' },
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: { wt: 'Bar value' },
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: { wt: '' },
|
|
|
|
'': { wt: '' }
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
href: './Template:Test',
|
|
|
|
wt: 'Test'
|
|
|
|
}
|
|
|
|
};
|
2021-09-09 07:16:37 +00:00
|
|
|
|
|
|
|
QUnit.module( 've.dm.MWTemplateModel' );
|
|
|
|
|
|
|
|
/**
|
2021-09-20 08:27:37 +00:00
|
|
|
* Create a new MWTemplateModel initialized with a static transclusion data fixture.
|
|
|
|
*
|
|
|
|
* @return {ve.dm.MWTemplateModel}
|
2021-09-09 07:16:37 +00:00
|
|
|
*/
|
2021-10-13 13:21:04 +00:00
|
|
|
const newTemplateModel = function () {
|
2021-09-20 08:27:37 +00:00
|
|
|
const doc = ve.dm.Document.static.newBlankDocument(),
|
|
|
|
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
|
|
|
clonedTransclusionData = ve.extendObject( {}, transclusionData );
|
|
|
|
|
|
|
|
return ve.dm.MWTemplateModel.newFromData( transclusion, clonedTransclusionData );
|
2021-10-13 13:21:04 +00:00
|
|
|
};
|
2021-09-09 07:16:37 +00:00
|
|
|
|
2021-09-20 08:27:37 +00:00
|
|
|
/* 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[]' ]
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( [ href, expected ] ) => QUnit.test( 'getTitle: ' + href, ( assert ) => {
|
2022-04-19 11:46:34 +00:00
|
|
|
const transclusion = { nextUniquePartId: () => '' },
|
2021-09-20 08:27:37 +00:00
|
|
|
template = new ve.dm.MWTemplateModel( transclusion, { href } );
|
|
|
|
assert.strictEqual( template.getTitle(), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
QUnit.test( 'hasParameter', ( assert ) => {
|
|
|
|
const template = newTemplateModel();
|
|
|
|
|
|
|
|
// All parameters are primary as long as the TemplateData documentation isn't known
|
|
|
|
assert.strictEqual( template.hasParameter( 'bar' ), true );
|
|
|
|
assert.strictEqual( template.hasParameter( 'resolved-bar' ), false );
|
|
|
|
assert.strictEqual( template.hasParameter( 'alternative-bar' ), false );
|
|
|
|
|
|
|
|
template.getSpec().setTemplateData( { params: {
|
|
|
|
'resolved-bar': { aliases: [ 'bar', 'alternative-bar' ] }
|
|
|
|
} } );
|
|
|
|
|
|
|
|
// Now "bar" and "alternative-bar" are aliases, and "resolved-bar" is the primary name
|
|
|
|
assert.strictEqual( template.hasParameter( 'bar' ), true );
|
|
|
|
assert.strictEqual( template.hasParameter( 'resolved-bar' ), true );
|
|
|
|
assert.strictEqual( template.hasParameter( 'alternative-bar' ), true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'getOriginalParameterName', ( assert ) => {
|
|
|
|
const template = newTemplateModel();
|
|
|
|
template.addParameter( new ve.dm.MWParameterModel( template, 'p1' ) );
|
|
|
|
template.addParameter( new ve.dm.MWParameterModel( template, 'p2-alias' ) );
|
|
|
|
|
|
|
|
// These are all independent parameters as long as we don't know anything about aliases
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p1' ), 'p1' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p1-alias' ), 'p1-alias' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p2' ), 'p2' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p2-alias' ), 'p2-alias' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p3' ), 'p3' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p3-alias' ), 'p3-alias' );
|
|
|
|
|
|
|
|
template.getSpec().setTemplateData( { params: {
|
|
|
|
p1: { aliases: [ 'p1-alias' ] },
|
|
|
|
p2: { aliases: [ 'p2-alias' ] },
|
|
|
|
p3: { aliases: [ 'p3-alias' ] }
|
|
|
|
} } );
|
|
|
|
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p1' ), 'p1' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p1-alias' ), 'p1' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p2' ), 'p2-alias' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p2-alias' ), 'p2-alias' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p3' ), 'p3' );
|
|
|
|
assert.strictEqual( template.getOriginalParameterName( 'p3-alias' ), 'p3' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'serialize input parameters', ( assert ) => {
|
|
|
|
const template = newTemplateModel();
|
|
|
|
|
|
|
|
const serialization = template.serialize();
|
|
|
|
assert.deepEqual( serialization, { template: {
|
|
|
|
params: {
|
|
|
|
foo: { wt: 'Foo value' },
|
|
|
|
bar: { wt: 'Bar value' },
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: { wt: 'Bar value' },
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: { wt: '' }
|
|
|
|
},
|
|
|
|
target: { href: './Template:Test', wt: 'Test' }
|
|
|
|
} } );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'serialize changed input parameters', ( assert ) => {
|
|
|
|
const template = newTemplateModel(),
|
|
|
|
newParameter = new ve.dm.MWParameterModel( template, 'baz', 'Baz value' );
|
|
|
|
|
|
|
|
template.addParameter( newParameter );
|
|
|
|
|
|
|
|
const serialization = template.serialize();
|
|
|
|
assert.deepEqual( serialization.template.params.baz, { wt: 'Baz value' } );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// T75134
|
|
|
|
QUnit.test( 'serialize after parameter was removed', ( assert ) => {
|
|
|
|
const template = newTemplateModel(),
|
|
|
|
existingParameter = template.getParameter( 'bar' );
|
|
|
|
|
|
|
|
template.removeParameter( existingParameter );
|
|
|
|
|
|
|
|
const serialization = template.serialize();
|
|
|
|
assert.deepEqual( serialization.template.params, {
|
|
|
|
foo: { wt: 'Foo value' },
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: { wt: 'Bar value' },
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: { wt: '' }
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// T101075
|
|
|
|
QUnit.test( 'serialize without empty parameter not present in original parameter set', ( assert ) => {
|
|
|
|
const template = newTemplateModel(),
|
|
|
|
parameterWithoutValue = new ve.dm.MWParameterModel( template, 'new_empty', '' );
|
|
|
|
|
|
|
|
template.addParameter( parameterWithoutValue );
|
|
|
|
|
|
|
|
const serialization = template.serialize();
|
|
|
|
assert.deepEqual( serialization.template.params, {
|
|
|
|
foo: { wt: 'Foo value' },
|
|
|
|
bar: { wt: 'Bar value' },
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: { wt: 'Bar value' },
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: { wt: '' }
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'serialize with explicit parameter order',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
foo: {},
|
|
|
|
empty: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
bar: {},
|
|
|
|
Bar: {}
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
paramOrder: [ 'bar', 'foo', 'empty', 'Bar' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
expected: [ 'foo', 'bar', 'Bar', 'empty' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'serialize with no parameter order',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
foo: {},
|
|
|
|
empty: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
bar: {},
|
|
|
|
Bar: {}
|
2021-09-20 08:27:37 +00:00
|
|
|
}
|
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
expected: [ 'foo', 'bar', 'Bar', 'empty' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'serialize with aliases',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
foo: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: {},
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: {},
|
|
|
|
hasaliases: { aliases: [ 'bar', 'baz' ] }
|
|
|
|
}
|
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
expected: [ 'foo', 'bar', 'Bar', 'empty' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'serialize with unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
bar: {}
|
|
|
|
}
|
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
expected: [ 'foo', 'bar', 'Bar', 'empty' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
}
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( { name, spec, expected } ) => QUnit.test( name, ( assert ) => {
|
2021-09-20 08:27:37 +00:00
|
|
|
const template = newTemplateModel();
|
|
|
|
|
|
|
|
template.getSpec().setTemplateData( spec );
|
|
|
|
|
|
|
|
const serialization = template.serialize();
|
|
|
|
assert.deepEqual( Object.keys( serialization.template.params ), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'no spec retrieved',
|
|
|
|
spec: null,
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'empty spec',
|
|
|
|
spec: {},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder and all known params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
bar: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: {},
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
paramOrder: [ 'foo', 'Bar', 'empty', 'bar', 'unused' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'foo',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'bar',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder and some unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
},
|
|
|
|
paramOrder: [ 'foo', 'empty', 'unused' ]
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'foo',
|
|
|
|
'empty',
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder but all unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {},
|
|
|
|
paramOrder: []
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with no paramOrder, all known params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
bar: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: {},
|
2021-09-20 08:27:37 +00:00
|
|
|
foo: {},
|
|
|
|
unused: {},
|
|
|
|
empty: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'foo',
|
|
|
|
'empty',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with no paramOrder and some unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
}
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( { name, spec, expected } ) => QUnit.test( 'getOrderedParameterNames: ' + name, ( assert ) => {
|
2021-09-20 08:27:37 +00:00
|
|
|
const template = newTemplateModel();
|
|
|
|
|
|
|
|
if ( spec ) {
|
|
|
|
template.getSpec().setTemplateData( spec );
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual( template.getOrderedParameterNames(), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'no spec retrieved',
|
|
|
|
spec: null,
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder and all known params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
bar: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: {},
|
2021-09-20 08:27:37 +00:00
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
},
|
2021-10-07 09:37:10 +00:00
|
|
|
paramOrder: [ 'foo', 'Bar', 'empty', 'unused', 'bar' ]
|
2021-09-20 08:27:37 +00:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'foo',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'unused',
|
|
|
|
'bar',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder and some unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
},
|
|
|
|
paramOrder: [ 'foo', 'empty', 'unused' ]
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'foo',
|
|
|
|
'empty',
|
|
|
|
'unused',
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder but all unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {},
|
|
|
|
paramOrder: []
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'empty',
|
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with no paramOrder, all known params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
bar: {},
|
2021-10-07 09:37:10 +00:00
|
|
|
Bar: {},
|
2021-09-20 08:27:37 +00:00
|
|
|
foo: {},
|
|
|
|
unused: {},
|
|
|
|
empty: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'foo',
|
|
|
|
'unused',
|
|
|
|
'empty',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with no paramOrder and some unknown params',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
foo: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'empty',
|
|
|
|
'unused',
|
|
|
|
'foo',
|
|
|
|
'bar',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'spec with explicit paramOrder and aliases',
|
|
|
|
spec: {
|
|
|
|
params: {
|
|
|
|
empty: {},
|
|
|
|
unused: {},
|
|
|
|
hasalias: {
|
|
|
|
aliases: [ 'bar', 'baz' ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
paramOrder: [ 'hasalias', 'empty', 'unused' ]
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
'bar',
|
|
|
|
'empty',
|
|
|
|
'unused',
|
2021-10-07 09:37:10 +00:00
|
|
|
'Bar',
|
2021-09-20 08:27:37 +00:00
|
|
|
'foo',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
}
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( { name, spec, expected } ) => QUnit.test( 'getAllParametersOrdered: ' + name, ( assert ) => {
|
2021-09-20 08:27:37 +00:00
|
|
|
const template = newTemplateModel();
|
|
|
|
|
|
|
|
if ( spec ) {
|
|
|
|
template.getSpec().setTemplateData( spec );
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual( template.getAllParametersOrdered(), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
2022-06-09 08:52:31 +00:00
|
|
|
QUnit.test( 'same documented parameter used with different aliases', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel();
|
|
|
|
const template = ve.dm.MWTemplateModel.newFromData( transclusion, {
|
|
|
|
target: {},
|
|
|
|
params: { d: {}, c: {}, b: {}, a: {} }
|
|
|
|
} );
|
|
|
|
template.getSpec().setTemplateData( {
|
|
|
|
params: { a: { aliases: [ 'b', 'c' ] }, e: {} }
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.deepEqual( template.getOrderedParameterNames(), [ 'a', 'c', 'b', 'd' ] );
|
|
|
|
assert.deepEqual( template.getAllParametersOrdered(), [ 'a', 'c', 'b', 'e', 'd' ] );
|
|
|
|
} );
|
|
|
|
|
2021-09-17 14:13:19 +00:00
|
|
|
[
|
|
|
|
[ 'a', 'b', 'Template:A', 'prefers .wt when it is a valid title' ],
|
|
|
|
[ '{{a}}', 'subst:b', 'subst:b', 'falls back to unmodified getTitle' ],
|
|
|
|
[ 'subst:a', 'b', 'Template:A', 'strips subst:' ],
|
|
|
|
[ 'safesubst:a', 'b', 'Template:A', 'strips safesubst:' ],
|
|
|
|
[ ' SUBST: a', 'b', 'Template:A', 'ignores capitalization and whitespace' ],
|
|
|
|
[ 'subst :a', 'b', 'Template:Subst :a', 'leaves bad whitespace untouched' ],
|
|
|
|
[ 'int:a', 'b', 'Template:Int:a', 'leaves other prefixes untouched' ]
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( [ wt, href, expected, message ] ) => QUnit.test( 'getTemplateDataQueryTitle: ' + message, ( assert ) => {
|
2022-04-19 11:46:34 +00:00
|
|
|
const transclusion = { nextUniquePartId: () => '' },
|
2021-09-20 08:27:37 +00:00
|
|
|
data = { target: { wt, href } },
|
|
|
|
model = ve.dm.MWTemplateModel.newFromData( transclusion, data );
|
2021-09-17 14:13:19 +00:00
|
|
|
|
|
|
|
assert.strictEqual( model.getTemplateDataQueryTitle(), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
2021-09-09 07:16:37 +00:00
|
|
|
[
|
|
|
|
[ {}, false, 'no parameters' ],
|
|
|
|
[ { p1: {}, p2: { wt: 'foo' } }, true, 'multiple parameters' ],
|
|
|
|
[ { p1: {} }, false, 'undefined' ],
|
|
|
|
[ { p1: { wt: null } }, false, 'null' ],
|
|
|
|
[ { p1: { wt: '' } }, false, 'empty string' ],
|
|
|
|
[ { p1: { wt: ' ' } }, true, 'space' ],
|
|
|
|
[ { p1: { wt: '0' } }, true, '0' ],
|
|
|
|
[ { p1: { wt: '\nfoo' } }, true, 'newline' ]
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( [ params, expected, message ] ) => QUnit.test( 'containsValuableData: ' + message, ( assert ) => {
|
2022-04-19 11:46:34 +00:00
|
|
|
const transclusion = { nextUniquePartId: () => '' },
|
2021-09-20 08:27:37 +00:00
|
|
|
data = { target: {}, params },
|
|
|
|
model = ve.dm.MWTemplateModel.newFromData( transclusion, data );
|
2021-09-09 07:16:37 +00:00
|
|
|
|
|
|
|
assert.strictEqual( model.containsValuableData(), expected );
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
2021-10-13 13:21:04 +00:00
|
|
|
}
|