More robust and thorough numbering test

Check all refs, and only check outputs without coupling to class
internals.

Bug: T372871
Change-Id: I99187b09b0d93e1fb19fedf80a8e4fe64fe4e7ac
This commit is contained in:
Adam Wight 2024-08-21 15:19:32 +02:00
parent dfa08cbb03
commit 99c4c9856a

View file

@ -6,48 +6,20 @@ QUnit.test( 'first simple test', ( assert ) => {
const doc = ve.dm.citeExample.createExampleDocument( 'references' ); const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc ); const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
const mainNodes = docRefs.getGroupRefsByParents( 'mwReference/' ); assert.strictEqual( docRefs.getIndexLabel( '', 'auto/0' ), '1' );
const fooNodes = docRefs.getGroupRefsByParents( 'mwReference/foo' ); assert.strictEqual( docRefs.getIndexLabel( '', 'literal/bar' ), '2' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/:3' ), '3' );
assert.strictEqual( mainNodes[ '' ].length, 4 ); assert.strictEqual( docRefs.getIndexLabel( '', 'auto/1' ), '4' );
assert.strictEqual( fooNodes[ '' ].length, 1 ); assert.strictEqual( docRefs.getIndexLabel( 'foo', 'auto/2' ), '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.getIndexLabel( '', firstListKey ), '1' );
assert.strictEqual( docRefs.getIndexLabel( 'foo', fooGroupListKey ), '1' );
} ); } );
QUnit.test( 'extends test', ( assert ) => { QUnit.test( 'extends test', ( assert ) => {
const doc = ve.dm.citeExample.createExampleDocument( 'extends' ); const doc = ve.dm.citeExample.createExampleDocument( 'extends' );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc ); const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
const groupedRefs = docRefs.getGroupRefsByParents( 'mwReference/' ); // FIXME: Shows that the class doesn't handle orphans correctly
assert.strictEqual( docRefs.getIndexLabel( '', 'auto/0' ), '3.1' );
assert.strictEqual( Object.keys( groupedRefs ).length, 2 ); assert.strictEqual( docRefs.getIndexLabel( '', 'auto/1' ), '1' );
assert.strictEqual( docRefs.getIndexLabel( '', 'literal/orphaned' ), '2' );
assert.strictEqual( groupedRefs[ '' ].length, 3 ); assert.strictEqual( docRefs.getIndexLabel( '', 'literal/ldr' ), '3' );
assert.strictEqual( groupedRefs[ 'literal/ldr' ].length, 1 );
const firstListKey = groupedRefs[ '' ][ 0 ].getAttribute( 'listKey' );
assert.strictEqual( firstListKey, 'auto/1' );
// FIXME: Documents incorrect behavior, should be '2'.
assert.strictEqual( docRefs.getIndexLabel( '', firstListKey ), '1' );
const secondListKey = groupedRefs[ '' ][ 1 ].getAttribute( 'listKey' );
assert.strictEqual( secondListKey, 'literal/orphaned' );
assert.strictEqual( docRefs.getIndexLabel( '', secondListKey ), '2' );
const thirdListKey = groupedRefs[ '' ][ 2 ].getAttribute( 'listKey' );
assert.strictEqual( thirdListKey, 'literal/ldr' );
// FIXME: Documents incorrect behavior, should be '1'.
assert.strictEqual( docRefs.getIndexLabel( '', thirdListKey ), '3' );
const subrefListKey = groupedRefs[ 'literal/ldr' ][ 0 ].getAttribute( 'listKey' );
assert.strictEqual( subrefListKey, 'auto/0' );
// FIXME: Documents incorrect behavior, should be '1.1'.
assert.strictEqual( docRefs.getIndexLabel( '', subrefListKey ), '3.1' );
} ); } );