mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js
WMDE-Fisch f9b9c7aa9b Add basic QUnit test for MWDocumentReferences
Change-Id: I40a62ceecc4ab5d0b4b6154bd934ccf4ae6a2774
2024-07-29 09:33:23 +02:00

25 lines
1,009 B
JavaScript

'use strict';
QUnit.module( 've.dm.MWDocumentReferences (Cite)', ve.test.utils.newMwEnvironment() );
QUnit.test( 'first simple test', ( assert ) => {
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
const mainNodes = docRefs.getGroupRefsByParents( 'mwReference/' );
const fooNodes = docRefs.getGroupRefsByParents( 'mwReference/foo' );
assert.strictEqual( Object.keys( docRefs.getGroupRefsByParents() ).length, 0 );
assert.strictEqual( mainNodes[ '' ].length, 4 );
assert.strictEqual( fooNodes[ '' ].length, 1 );
const firstListKey = mainNodes[ '' ][ 0 ].getAttribute( 'listKey' );
const fooGroupListKey = fooNodes[ '' ][ 0 ].getAttribute( 'listKey' );
assert.strictEqual( firstListKey, 'auto/0' );
assert.strictEqual( fooGroupListKey, 'auto/2' );
assert.strictEqual( docRefs.getIndexNumber( '', firstListKey ), '1' );
assert.strictEqual( docRefs.getIndexNumber( 'foo', fooGroupListKey ), '1' );
} );