mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.ui.MWReferenceSearchWidget.test.js
thiemowmde b02028b671 Move ve-cite QUnit tests to top-level tests/ directory
It's just hard to find and confusing when hidden in that
sub-directory.

Bug: T358851
Change-Id: I19ffe73b79fa9add52af12f477afe7abbc6db836
2024-04-03 12:03:33 +02:00

51 lines
1.6 KiB
JavaScript

'use strict';
QUnit.module( 've.ui.MWReferenceSearchWidget (Cite)', ve.test.utils.newMwEnvironment() );
QUnit.test( 'buildIndex', function ( assert ) {
const widget = new ve.ui.MWReferenceSearchWidget();
widget.internalList = { getNodeGroups: () => ( {} ) };
assert.false( widget.built );
widget.buildIndex();
assert.true( widget.built );
assert.deepEqual( widget.index, [] );
widget.onInternalListUpdate( [ 'mwReference/' ] );
assert.false( widget.built );
assert.deepEqual( widget.index, [] );
widget.buildIndex();
assert.true( widget.built );
assert.deepEqual( widget.index, [] );
widget.onListNodeUpdate();
assert.false( widget.built );
assert.deepEqual( widget.index, [] );
} );
QUnit.test( 'isIndexEmpty', function ( assert ) {
const widget = new ve.ui.MWReferenceSearchWidget();
assert.true( widget.isIndexEmpty() );
// XXX: This is a regression test with a fragile setup. Please feel free to delete this test
// when you feel like it doesn't make sense to update it.
const internalList = {
connect: () => null,
getListNode: () => ( { connect: () => null } ),
getNodeGroups: () => ( { 'mwReference/': { indexOrder: [ 0 ] } } )
};
widget.setInternalList( internalList );
assert.false( widget.isIndexEmpty() );
} );
QUnit.test( 'addResults', function ( assert ) {
const widget = new ve.ui.MWReferenceSearchWidget();
widget.getQuery().setValue( 'a' );
widget.index = [ { text: 'a' }, { text: 'b' } ];
assert.strictEqual( widget.getResults().getItemCount(), 0 );
widget.addResults();
assert.strictEqual( widget.getResults().getItemCount(), 1 );
} );