mediawiki-extensions-Cite/modules/ve-cite/tests/ve.ui.MWReferenceGroupInputWidget.test.js
thiemowmde d6a58cfa8d Add initial QUnit tests relevant for reference re-use in VE
Note these are more meant as regression test to better cover what's
done in other patches. Everybody should feel free to delete a test
when it gets in the way. I marked a few especially fragile places
with respective comments.

Bug: T358652
Change-Id: I7844907fe3ef4f3439717381b4ecdac9e2d0a825
2024-03-21 09:37:26 +01:00

29 lines
965 B
JavaScript

'use strict';
QUnit.module( 've.ui.MWReferenceGroupInputWidget (Cite)', ve.test.utils.newMwEnvironment() );
QUnit.test( 'Constructor', function ( assert ) {
const widget = new ve.ui.MWReferenceGroupInputWidget( {
emptyGroupName: '—'
} );
assert.strictEqual( widget.emptyGroupName, '—' );
assert.strictEqual( widget.getMenu().getItemCount(), 0 );
} );
QUnit.test( 'populateMenu', function ( assert ) {
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const widget = new ve.ui.MWReferenceGroupInputWidget( {
emptyGroupName: 'empty'
} );
widget.populateMenu( doc.getInternalList() );
assert.strictEqual( widget.getMenu().getItemCount(), 2 );
assert.strictEqual( widget.getMenu().items[ 0 ].getData(), '' );
assert.strictEqual( widget.getMenu().items[ 0 ].getLabel(), 'empty' );
assert.strictEqual( widget.getMenu().items[ 1 ].getData(), 'foo' );
assert.strictEqual( widget.getMenu().items[ 1 ].getLabel(), 'foo' );
} );