mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 19:09:29 +00:00
1f19d85ea8
Contains: * Full test coverage (I believe) for the filter functionality in …OutlineTemplateWidget. Also some TODOs for missing tests I believe are critical. Bug: T289560 Change-Id: I2ac5add8e189d501d3558bbd4854cb92155bcb96
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
QUnit.module( 've.ui.MWTransclusionOutlineTemplateWidget' );
|
|
|
|
QUnit.test( 'Constructor', ( assert ) => {
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
template = new ve.dm.MWTemplateModel( transclusion, { wt: 'Example' } ),
|
|
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
assert.strictEqual( widget.getData(), 'part_0' );
|
|
assert.strictEqual(
|
|
widget.$element.find( '.ve-ui-mwTransclusionOutlineButtonWidget' ).text(),
|
|
'Example'
|
|
);
|
|
} );
|
|
|
|
// TODO: insertCheckboxAtCanonicalPosition() is complex and fragile and must be tested.
|
|
|
|
QUnit.test( 'filterParameters() on an empty template', ( assert ) => {
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
template = new ve.dm.MWTemplateModel( transclusion, {} ),
|
|
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
|
|
|
|
let eventsFired = 0;
|
|
widget.connect( this, {
|
|
filterParameters: ( visibility ) => {
|
|
assert.deepEqual( visibility, {} );
|
|
eventsFired++;
|
|
}
|
|
} );
|
|
|
|
widget.filterParameters( '' );
|
|
assert.strictEqual( widget.infoWidget.isVisible(), true );
|
|
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, {
|
|
target: {},
|
|
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, {
|
|
filterParameters: ( visibility ) => {
|
|
assert.deepEqual( visibility, {
|
|
'part_0/a': true,
|
|
'part_0/b': false,
|
|
'part_0/c': true,
|
|
'part_0/d': true,
|
|
'part_0/e': true
|
|
} );
|
|
eventsFired++;
|
|
}
|
|
} );
|
|
|
|
widget.filterParameters( ' A ' );
|
|
assert.strictEqual( widget.infoWidget.isVisible(), false );
|
|
assert.strictEqual( eventsFired, 1 );
|
|
} );
|