diff --git a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.test.js b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.test.js index f18a1ea86e..c6b24344cb 100644 --- a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.test.js +++ b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineContainerWidget.test.js @@ -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. diff --git a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterWidget.test.js b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterWidget.test.js index 10930a9645..fabea0a1fd 100644 --- a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterWidget.test.js +++ b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineParameterWidget.test.js @@ -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 ); } ); diff --git a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.test.js b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.test.js index 7228256a69..79a389474a 100644 --- a/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.test.js +++ b/modules/ve-mw/tests/ui/widgets/ve.ui.MWTransclusionOutlineTemplateWidget.test.js @@ -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 ); +} );