Add tests for new ve.ui.MWAddParameterPage

The class was added via Ic5dcd36 just a few days ago.

Bug: T289560
Change-Id: I3f729fb6c5d7c28a221d88294d5547809f10a17d
This commit is contained in:
Thiemo Kreuz 2021-08-30 12:58:32 +02:00 committed by Thiemo Kreuz (WMDE)
parent 544bd5688c
commit e9bd350f68
3 changed files with 45 additions and 1 deletions

View file

@ -2813,6 +2813,7 @@
"modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js",
"lib/ve/tests/ui/inspectors/ve.ui.FragmentInspector.test.js",
"modules/ve-mw/tests/ui/inspectors/ve.ui.FragmentInspector.test.js",
"modules/ve-mw/tests/ui/pages/ve.ui.MWAddParameterPage.test.js",
"modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js",
"modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterSearchWidget.test.js",
"modules/ve-mw/tests/ui/widgets/ve.ui.MWTemplateTitleInputWidget.test.js",

View file

@ -0,0 +1,43 @@
QUnit.module( 've.ui.MWAddParameterPage' );
QUnit.test( 'Input event handler', ( assert ) => {
const transclusion = new ve.dm.MWTransclusionModel(),
template = new ve.dm.MWTemplateModel( transclusion, {} ),
parameter = new ve.dm.MWParameterModel( template ),
page = new ve.ui.MWAddParameterPage( parameter );
page.paramInputField.setValue( ' ' );
page.onParameterInput();
assert.deepEqual( template.getParameters(), {}, 'empty input is ignored' );
page.paramInputField.setValue( ' p1 ' );
page.onParameterInput();
assert.ok( template.hasParameter( 'p1' ), 'input is trimmed and parameter added' );
template.getParameter( 'p1' ).setValue( 'not empty' );
page.paramInputField.setValue( 'p1' );
page.onParameterInput();
assert.ok( template.getParameter( 'p1' ).getValue(), 'existing parameter is not replaced' );
template.getSpec().setTemplateData( { params: { documented: {} } } );
page.paramInputField.setValue( 'documented' );
page.onParameterInput();
assert.notOk( template.hasParameter( 'documented' ), 'documented parameter is not added' );
} );
QUnit.test( 'Outline item initialization', ( assert ) => {
const transclusion = new ve.dm.MWTransclusionModel(),
template = new ve.dm.MWTemplateModel( transclusion, {} ),
parameter = new ve.dm.MWParameterModel( template ),
page = new ve.ui.MWAddParameterPage( parameter );
page.setOutlineItem( new OO.ui.OutlineOptionWidget() );
const outlineItem = page.getOutlineItem();
assert.notOk( outlineItem.$element.children().length,
'Outline item should be empty' );
// eslint-disable-next-line no-jquery/no-class-state
assert.notOk( outlineItem.$element.hasClass( 'oo-ui-outlineOptionWidget' ),
'Outline item should not be styled' );
} );

View file

@ -112,6 +112,6 @@ ve.ui.MWAddParameterPage.prototype.setOutlineItem = function () {
if ( this.outlineItem ) {
// This page should not be shown in the (BookletLayout-based) sidebar
this.outlineItem.$element.empty().removeClass();
this.outlineItem.$element.empty().removeAttr( 'class' );
}
};