mediawiki-extensions-Visual.../modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js
libraryupgrader 702677220d build: Updating eslint-config-wikimedia to 0.28.0
The following rules are failing and were disabled:
* modules/ve-mw/tests:
  * implicit-arrow-linebreak

Change-Id: If857233c0de24c8cf619dbb1347ebb375f3ab1ba
2024-06-04 03:40:00 +00:00

36 lines
1.1 KiB
JavaScript

QUnit.module( 've.ui.MWParameterCheckboxInputWidget' );
QUnit.test( 'Constructor passes config to parent', ( assert ) => {
const widget = new ve.ui.MWParameterCheckboxInputWidget( { selected: true } );
assert.strictEqual( widget.getValue(), '1' );
assert.strictEqual( widget.isSelected(), true );
} );
[
[ '1', true, '"1"' ],
[ '0', false, '"0"' ],
[ '', false, 'empty string' ],
[ '2', false, 'unexpected string' ],
[ true, false, 'unexpected type' ]
].forEach( ( [ value, expected, message ] ) => QUnit.test( `setValue( ${ message } )`, ( assert ) => {
const widget = new ve.ui.MWParameterCheckboxInputWidget();
widget.setValue( value );
assert.strictEqual( widget.isSelected(), expected );
assert.strictEqual( widget.getValue(), expected ? '1' : '0' );
} )
);
[
true,
false
].forEach( ( value ) => QUnit.test( `setSelected( ${ value } )`, ( assert ) => {
const widget = new ve.ui.MWParameterCheckboxInputWidget();
widget.setSelected( value );
assert.strictEqual( widget.isSelected(), value );
assert.strictEqual( widget.getValue(), value ? '1' : '0' );
} )
);