2020-11-16 18:43:00 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTemplateModel tests.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function () {
|
2021-04-29 14:42:18 +00:00
|
|
|
const transclusionData = {
|
2020-11-16 18:43:00 +00:00
|
|
|
params: {
|
|
|
|
foo: { wt: 'Foo value' },
|
|
|
|
bar: { wt: 'Bar value' },
|
|
|
|
empty: { wt: '' }
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
href: './Template:Test',
|
|
|
|
wt: 'Test'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QUnit.module( 've.dm.MWTemplateModel', ve.test.utils.mwEnvironment );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new MWTemplateModel initialized with a static transclusion data fixture.
|
|
|
|
*
|
|
|
|
* @return {ve.dm.MWTemplateModel}
|
|
|
|
*/
|
|
|
|
function newTemplateModel() {
|
2021-04-29 14:42:18 +00:00
|
|
|
const doc = ve.dm.Document.static.newBlankDocument(),
|
2020-11-16 18:43:00 +00:00
|
|
|
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
|
|
|
clonedTransclusionData = ve.extendObject( {}, transclusionData );
|
|
|
|
|
|
|
|
return ve.dm.MWTemplateModel.newFromData( transclusion, clonedTransclusionData );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'serialize input parameters', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const templateModel = newTemplateModel(),
|
2020-11-16 18:43:00 +00:00
|
|
|
serializedTransclusionData = templateModel.serialize();
|
|
|
|
|
|
|
|
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
|
|
|
} );
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'serialize changed input parameters', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const templateModel = newTemplateModel(),
|
|
|
|
newParameterModel = new ve.dm.MWParameterModel( templateModel, 'baz', 'Baz value' );
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
templateModel.addParameter( newParameterModel );
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
const serializedTransclusionData = templateModel.serialize();
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
assert.deepEqual( serializedTransclusionData.template.params.baz, { wt: 'Baz value' } );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// T75134
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'serialize after parameter was removed', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const templateModel = newTemplateModel(),
|
|
|
|
barParam = templateModel.getParameter( 'bar' );
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
templateModel.removeParameter( barParam );
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
const serializedTransclusionData = templateModel.serialize();
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
assert.deepEqual( serializedTransclusionData.template.params, { foo: { wt: 'Foo value' }, empty: { wt: '' } } );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// T101075
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'serialize without empty parameter not present in original parameter set', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const templateModel = newTemplateModel(),
|
|
|
|
newEmptyParam = new ve.dm.MWParameterModel( templateModel, 'new_empty', '' );
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
templateModel.addParameter( newEmptyParam );
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
const serializedTransclusionData = templateModel.serialize();
|
2020-11-16 18:43:00 +00:00
|
|
|
|
|
|
|
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
|
|
|
} );
|
|
|
|
}() );
|