mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js
Adam Wight 6e03d2cafa Moving ref group knowledge into a dedicated data structure
Pushes per-group knowledge down into a structured object and give it
an interface, separated from the singleton cache across all groups.

Also changes the behavior of orphaned subrefs so that they're still
rendered as subrefs, with an error placeholder where the parent
should be.

Bug: T372871
Change-Id: I84e679a8365f3fbfabaf344d99f56f6d069c0776
2024-08-26 09:26:15 +00:00

25 lines
1.1 KiB
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 );
assert.strictEqual( docRefs.getIndexLabel( '', 'auto/0' ), '1' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/bar' ), '2' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/:3' ), '3' );
assert.strictEqual( docRefs.getIndexLabel( '', 'auto/1' ), '4' );
assert.strictEqual( docRefs.getIndexLabel( 'foo', 'auto/2' ), '1' );
} );
QUnit.test( 'extends test', ( assert ) => {
const doc = ve.dm.citeExample.createExampleDocument( 'extends' );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
assert.strictEqual( docRefs.getIndexLabel( '', 'auto/0' ), '1.1' );
assert.strictEqual( docRefs.getIndexLabel( '', 'auto/1' ), '2' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/orphaned' ), '3.1' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/ldr' ), '1' );
} );