mediawiki-extensions-Visual.../modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js
Thiemo Kreuz e56b4e82f5 Add test for ve.ui.MWParameterCheckboxInputWidget
This is not a file we created recently, but one we care about.
This is also a nice start to get in the mood to write tests.

Bug: T289560
Change-Id: I6475b00508cfa9188ab0d78c2bfd31bab8aed6ed
2021-08-24 15:44:43 +00:00

34 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' );
} ) );