2021-08-24 09:31:14 +00:00
|
|
|
QUnit.module( 've.ui.MWTransclusionOutlineTemplateWidget' );
|
|
|
|
|
|
|
|
QUnit.test( 'Constructor', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
2021-08-24 11:17:16 +00:00
|
|
|
template = new ve.dm.MWTemplateModel( transclusion, { wt: 'Example' } ),
|
2021-08-24 09:31:14 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
|
2021-08-24 11:17:16 +00:00
|
|
|
assert.strictEqual( widget.getData(), 'part_0' );
|
|
|
|
assert.strictEqual(
|
2021-10-27 09:39:03 +00:00
|
|
|
widget.$element.find( '.ve-ui-mwTransclusionOutlineButtonWidget .oo-ui-buttonElement-button' ).text(),
|
2021-08-24 11:17:16 +00:00
|
|
|
'Example'
|
|
|
|
);
|
2021-08-25 15:08:34 +00:00
|
|
|
assert.notOk( widget.searchWidget.isVisible() );
|
|
|
|
assert.notOk( widget.infoWidget.isVisible() );
|
2021-08-24 09:31:14 +00:00
|
|
|
} );
|
2021-08-25 09:29:23 +00:00
|
|
|
|
2021-08-25 11:48:41 +00:00
|
|
|
QUnit.test( 'insertCheckboxAtCanonicalPosition()', ( assert ) => {
|
|
|
|
function assertOrder( widget, expected ) {
|
|
|
|
assert.deepEqual( widget.parameters.items.map( ( item ) => item.data ), expected );
|
|
|
|
}
|
|
|
|
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
template = ve.dm.MWTemplateModel.newFromData( transclusion, {
|
2021-10-07 11:06:03 +00:00
|
|
|
target: { wt: '' },
|
2021-08-25 11:48:41 +00:00
|
|
|
params: { b: {}, e: {} }
|
|
|
|
} );
|
|
|
|
template.getSpec().setTemplateData( {
|
|
|
|
params: {
|
|
|
|
e: { deprecated: true },
|
|
|
|
h: { deprecated: true },
|
|
|
|
g: {}
|
|
|
|
},
|
|
|
|
paramOrder: [ 'g', 'h', 'e' ]
|
|
|
|
} );
|
|
|
|
const widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
|
|
|
|
// Expected order on construction time is:
|
|
|
|
// - Documented params in paramOrder (g, h, e), excluding unused deprected params (- h)
|
|
|
|
// - Undocumented params currently used in the template (+ b)
|
|
|
|
assertOrder( widget, [ 'g', 'e', 'b' ] );
|
|
|
|
|
|
|
|
let insertAt = widget.findCanonicalPosition( 'h' );
|
|
|
|
// Most minimal mock instead of an actual ve.ui.MWTransclusionOutlineParameterWidget
|
|
|
|
widget.parameters.addItems( [ new OO.ui.Widget( { data: 'h' } ) ], insertAt );
|
|
|
|
// Deprecated param appears at it's canonical position via paramOrder
|
|
|
|
assert.strictEqual( insertAt, 1 );
|
|
|
|
assertOrder( widget, [ 'g', 'h', 'e', 'b' ] );
|
|
|
|
|
|
|
|
const newParam = new ve.dm.MWParameterModel( template, 'a1' );
|
|
|
|
// This fires an "add" event the widget listens to, i.e. this covers onAddParameter() as well
|
|
|
|
template.addParameter( newParam );
|
|
|
|
assertOrder( widget, [ 'g', 'h', 'e', 'a1', 'b' ] );
|
|
|
|
// Removing the param doesn't remove it's checkbox item from the widget
|
|
|
|
template.removeParameter( newParam );
|
|
|
|
assertOrder( widget, [ 'g', 'h', 'e', 'a1', 'b' ] );
|
|
|
|
|
|
|
|
// This is effectively the same as above: teach the spec a new param without adding it to the
|
|
|
|
// template. This doesn't fire events, which allows us to test the private method in isolation.
|
|
|
|
template.getSpec().seenParameterNames.a2 = true;
|
|
|
|
insertAt = widget.findCanonicalPosition( 'a2' );
|
|
|
|
// Most minimal mock instead of an actual ve.ui.MWTransclusionOutlineParameterWidget
|
|
|
|
widget.parameters.addItems( [ new OO.ui.Widget( { data: 'a2' } ) ], insertAt );
|
|
|
|
assert.strictEqual( insertAt, 4 );
|
|
|
|
assertOrder( widget, [ 'g', 'h', 'e', 'a1', 'a2', 'b' ] );
|
|
|
|
} );
|
2021-08-25 09:29:23 +00:00
|
|
|
|
|
|
|
QUnit.test( 'filterParameters() on an empty template', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
2021-10-07 11:06:03 +00:00
|
|
|
template = new ve.dm.MWTemplateModel( transclusion, { wt: '' } ),
|
2021-08-25 09:29:23 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
|
|
|
|
let eventsFired = 0;
|
|
|
|
widget.connect( this, {
|
2021-08-31 08:05:25 +00:00
|
|
|
filterParametersById: ( visibility ) => {
|
2021-08-25 09:29:23 +00:00
|
|
|
assert.deepEqual( visibility, {} );
|
|
|
|
eventsFired++;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
widget.filterParameters( '' );
|
2021-08-25 15:08:34 +00:00
|
|
|
assert.ok( widget.infoWidget.isVisible() );
|
2021-08-25 09:29:23 +00:00
|
|
|
assert.strictEqual( eventsFired, 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'filterParameters() considers everything from the spec', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
template = ve.dm.MWTemplateModel.newFromData( transclusion, {
|
2021-10-07 11:06:03 +00:00
|
|
|
target: { wt: '' },
|
2021-08-25 09:29:23 +00:00
|
|
|
params: { a: {}, b: {}, c: {}, d: {}, e: {} }
|
|
|
|
} ),
|
|
|
|
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
|
|
|
|
template.getSpec().setTemplateData( {
|
|
|
|
params: {
|
|
|
|
c: { label: 'Contains a' },
|
|
|
|
d: { description: 'Contains a' },
|
|
|
|
e: { aliases: [ 'Contains a' ] },
|
|
|
|
f: { label: 'Also contains a, but is not used in the template' }
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
let eventsFired = 0;
|
|
|
|
widget.connect( this, {
|
2021-08-31 08:05:25 +00:00
|
|
|
filterParametersById: ( visibility ) => {
|
2021-08-25 09:29:23 +00:00
|
|
|
assert.deepEqual( visibility, {
|
|
|
|
'part_0/a': true,
|
|
|
|
'part_0/b': false,
|
|
|
|
'part_0/c': true,
|
|
|
|
'part_0/d': true,
|
|
|
|
'part_0/e': true
|
|
|
|
} );
|
|
|
|
eventsFired++;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-08-25 15:08:34 +00:00
|
|
|
assert.ok( widget.searchWidget.isVisible() );
|
2021-08-25 09:29:23 +00:00
|
|
|
widget.filterParameters( ' A ' );
|
2021-08-25 15:08:34 +00:00
|
|
|
assert.notOk( widget.infoWidget.isVisible() );
|
2021-08-25 09:29:23 +00:00
|
|
|
assert.strictEqual( eventsFired, 1 );
|
|
|
|
} );
|