2021-09-01 13:46:25 +00:00
|
|
|
QUnit.module( 've.ui.MWAddParameterPage', ve.test.utils.mwEnvironment );
|
2021-08-30 10:58:32 +00:00
|
|
|
|
2021-09-27 16:22:10 +00:00
|
|
|
QUnit.test( 'Input event handlers', ( assert ) => {
|
2021-08-30 10:58:32 +00:00
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
template = new ve.dm.MWTemplateModel( transclusion, {} ),
|
|
|
|
parameter = new ve.dm.MWParameterModel( template ),
|
|
|
|
page = new ve.ui.MWAddParameterPage( parameter );
|
|
|
|
|
2021-12-06 17:00:27 +00:00
|
|
|
page.togglePlaceholder( true );
|
|
|
|
|
2021-08-30 10:58:32 +00:00
|
|
|
page.paramInputField.setValue( ' ' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.saveButton.isDisabled(), true, 'cannot click' );
|
2021-09-07 06:56:45 +00:00
|
|
|
page.onParameterNameSubmitted();
|
2021-08-30 10:58:32 +00:00
|
|
|
assert.deepEqual( template.getParameters(), {}, 'empty input is ignored' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.paramInputField.getValue(), ' ', 'bad input is not cleared' );
|
2021-08-30 10:58:32 +00:00
|
|
|
|
|
|
|
page.paramInputField.setValue( ' p1 ' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.saveButton.isDisabled(), false, 'can click' );
|
2021-09-07 06:56:45 +00:00
|
|
|
page.onParameterNameSubmitted();
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.true( template.hasParameter( 'p1' ), 'input is trimmed and parameter added' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.paramInputField.getValue(), '', 'accepted input is cleared' );
|
2021-08-30 10:58:32 +00:00
|
|
|
|
|
|
|
template.getParameter( 'p1' ).setValue( 'not empty' );
|
|
|
|
page.paramInputField.setValue( 'p1' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.saveButton.isDisabled(), true, 'cannot click' );
|
2021-09-07 06:56:45 +00:00
|
|
|
page.onParameterNameSubmitted();
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( template.getParameter( 'p1' ).getValue(), 'not empty',
|
|
|
|
'existing parameter is not replaced' );
|
2021-08-30 10:58:32 +00:00
|
|
|
|
|
|
|
template.getSpec().setTemplateData( { params: { documented: {} } } );
|
|
|
|
page.paramInputField.setValue( 'documented' );
|
2021-09-07 06:56:45 +00:00
|
|
|
page.onParameterNameSubmitted();
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.false( template.hasParameter( 'documented' ), 'documented parameter is not added' );
|
2021-09-27 16:22:10 +00:00
|
|
|
assert.strictEqual( page.paramInputField.getValue(), 'documented', 'bad input is not cleared' );
|
2021-08-30 10:58:32 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.strictEqual( outlineItem.$element.children().length, 0,
|
2021-08-30 10:58:32 +00:00
|
|
|
'Outline item should be empty' );
|
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.false( outlineItem.$element.hasClass( 'oo-ui-outlineOptionWidget' ),
|
2021-08-30 10:58:32 +00:00
|
|
|
'Outline item should not be styled' );
|
|
|
|
} );
|
2021-08-31 16:01:11 +00:00
|
|
|
|
|
|
|
[
|
|
|
|
[ '', 0 ],
|
|
|
|
[ 'a', 0 ],
|
2021-09-03 15:37:30 +00:00
|
|
|
[ 'a=b', '(visualeditor-dialog-transclusion-add-param-error-forbidden-char: =)' ],
|
|
|
|
[ 'x|a=b', '(visualeditor-dialog-transclusion-add-param-error-forbidden-char: |)' ],
|
2021-08-31 16:01:11 +00:00
|
|
|
[ 'used', '(visualeditor-dialog-transclusion-add-param-error-exists-selected: used, used)' ],
|
|
|
|
[ 'unused', '(visualeditor-dialog-transclusion-add-param-error-exists-unselected: unused, unused)' ],
|
2021-09-03 14:26:43 +00:00
|
|
|
[ 'usedAlias', '(visualeditor-dialog-transclusion-add-param-error-alias: usedAlias, xLabel)' ],
|
2021-08-31 16:01:11 +00:00
|
|
|
[ 'unusedAlias', '(visualeditor-dialog-transclusion-add-param-error-alias: unusedAlias, y)' ],
|
2021-09-03 14:26:43 +00:00
|
|
|
[ 'usedAliasNoLabel', '(visualeditor-dialog-transclusion-add-param-error-alias: usedAliasNoLabel, usedAliasNoLabel)' ],
|
2021-08-31 16:01:11 +00:00
|
|
|
[ 'usedDeprecated', '(visualeditor-dialog-transclusion-add-param-error-exists-selected: usedDeprecated, usedDeprecated)' ],
|
|
|
|
[ 'unusedDeprecated', '(visualeditor-dialog-transclusion-add-param-error-deprecated: unusedDeprecated, unusedDeprecated)' ]
|
|
|
|
].forEach( ( [ input, expected ] ) =>
|
|
|
|
QUnit.test( 'getValidationErrors: ' + input, ( assert ) => {
|
|
|
|
const data = {
|
|
|
|
target: {},
|
|
|
|
params: {
|
|
|
|
used: {},
|
|
|
|
usedAlias: {},
|
2021-09-03 14:26:43 +00:00
|
|
|
usedAliasNoLabel: {},
|
2021-08-31 16:01:11 +00:00
|
|
|
usedDeprecated: {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
template = ve.dm.MWTemplateModel.newFromData( transclusion, data ),
|
|
|
|
parameter = new ve.dm.MWParameterModel( template ),
|
|
|
|
page = new ve.ui.MWAddParameterPage( parameter );
|
|
|
|
|
|
|
|
template.getSpec().setTemplateData( { params: {
|
|
|
|
used: {},
|
|
|
|
unused: {},
|
2021-09-03 14:26:43 +00:00
|
|
|
x: { aliases: [ 'usedAlias' ], label: 'xLabel' },
|
2021-08-31 16:01:11 +00:00
|
|
|
y: { aliases: [ 'unusedAlias' ] },
|
2021-09-03 14:26:43 +00:00
|
|
|
z: { aliases: [ 'usedAliasNoLabel' ] },
|
2021-08-31 16:01:11 +00:00
|
|
|
usedDeprecated: { deprecated: true },
|
|
|
|
unusedDeprecated: { deprecated: true }
|
|
|
|
} } );
|
|
|
|
template.addParameter( parameter );
|
|
|
|
|
|
|
|
const errors = page.getValidationErrors( input );
|
|
|
|
assert.strictEqual( errors.length, expected ? 1 : 0 );
|
|
|
|
if ( expected ) {
|
|
|
|
assert.strictEqual( errors[ 0 ].text(), expected );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
);
|