Merge "More test cases for more complex template dialog functionality"

This commit is contained in:
jenkins-bot 2021-08-30 08:54:19 +00:00 committed by Gerrit Code Review
commit fdea0c5357
3 changed files with 74 additions and 12 deletions

View file

@ -40,3 +40,6 @@ QUnit.test( 'Basic functionality', ( assert ) => {
widget.clear();
assert.deepEqual( widget.partWidgets, {} );
} );
// TODO: addPartWidget() with different positions.
// TODO: onTransclusionModelChange() is complex and fragile and must be tested.

View file

@ -1,25 +1,28 @@
QUnit.module( 've.ui.MWTransclusionOutlineParameterWidget' );
QUnit.test( 'interprets param with no attributes', ( assert ) => {
const layout = new ve.ui.MWTransclusionOutlineParameterWidget( {} );
const widget = new ve.ui.MWTransclusionOutlineParameterWidget( {} );
assert.strictEqual( layout.checkbox.isDisabled(), false );
assert.strictEqual( layout.checkbox.isSelected(), false );
assert.strictEqual( layout.checkbox.getTitle(), null );
assert.strictEqual( widget.checkbox.isDisabled(), false );
assert.strictEqual( widget.checkbox.isSelected(), false );
assert.strictEqual( widget.checkbox.getTitle(), null );
} );
QUnit.test( 'interprets required param', ( assert ) => {
const layout = new ve.ui.MWTransclusionOutlineParameterWidget( { required: true } );
const widget = new ve.ui.MWTransclusionOutlineParameterWidget( { required: true } );
assert.strictEqual( layout.checkbox.isDisabled(), true );
assert.strictEqual( layout.checkbox.isSelected(), true );
assert.notStrictEqual( layout.checkbox.getTitle(), null );
assert.strictEqual( widget.checkbox.isDisabled(), true );
assert.strictEqual( widget.checkbox.isSelected(), true );
assert.strictEqual(
widget.checkbox.getTitle(),
'visualeditor-dialog-transclusion-required-parameter'
);
} );
QUnit.test( 'interprets selected param', ( assert ) => {
const layout = new ve.ui.MWTransclusionOutlineParameterWidget( { selected: true } );
const widget = new ve.ui.MWTransclusionOutlineParameterWidget( { selected: true } );
assert.strictEqual( layout.checkbox.isDisabled(), false );
assert.strictEqual( layout.checkbox.isSelected(), true );
assert.strictEqual( layout.checkbox.getTitle(), null );
assert.strictEqual( widget.checkbox.isDisabled(), false );
assert.strictEqual( widget.checkbox.isSelected(), true );
assert.strictEqual( widget.checkbox.getTitle(), null );
} );

View file

@ -11,3 +11,59 @@ QUnit.test( 'Constructor', ( assert ) => {
'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 );
} );