From c54000ed86665284b363ad96b251080cbbd99d5b Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Mon, 29 Jul 2024 11:33:34 +0200 Subject: [PATCH] Test MWDocumentReferences on subref doc Change-Id: I8fb9bee9f0f1447b38d6d67033c42c05934d1e12 --- .../ve.dm.MWDocumentReferences.test.js | 24 ++++++++- tests/qunit/ve-cite/ve.dm.citeExample.js | 51 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js b/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js index 0b7fcae1d..20bc58782 100644 --- a/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js +++ b/tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js @@ -9,8 +9,6 @@ QUnit.test( 'first simple test', ( assert ) => { 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 ); @@ -22,3 +20,25 @@ QUnit.test( 'first simple test', ( assert ) => { assert.strictEqual( docRefs.getIndexNumber( '', firstListKey ), '1' ); assert.strictEqual( docRefs.getIndexNumber( 'foo', fooGroupListKey ), '1' ); } ); + +QUnit.test( 'extends test', ( assert ) => { + const doc = ve.dm.citeExample.createExampleDocument( 'extends' ); + const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc ); + + const groupedRefs = docRefs.getGroupRefsByParents( 'mwReference/' ); + + assert.strictEqual( Object.keys( groupedRefs ).length, 2 ); + + assert.strictEqual( groupedRefs[ '' ].length, 2 ); + 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.getIndexNumber( '', firstListKey ), '1' ); + + const subrefListKey = groupedRefs[ 'literal/ldr' ][ 0 ].getAttribute( 'listKey' ); + assert.strictEqual( subrefListKey, 'auto/0' ); + // FIXME: Documents incorrect behavior, should be '1.1'. + assert.strictEqual( docRefs.getIndexNumber( '', subrefListKey ), '2.1' ); +} ); diff --git a/tests/qunit/ve-cite/ve.dm.citeExample.js b/tests/qunit/ve-cite/ve.dm.citeExample.js index e5df38edd..01fab60f2 100644 --- a/tests/qunit/ve-cite/ve.dm.citeExample.js +++ b/tests/qunit/ve-cite/ve.dm.citeExample.js @@ -994,3 +994,54 @@ ve.dm.citeExample.complexInternalData.internalItems = [ ]; ve.dm.citeExample.complexInternalData.internalListNextUniqueNumber = 1; + +ve.dm.citeExample.extends = [ + { type: 'paragraph' }, + { type: 'mwReference', attributes: { + extendsRef: 'literal/ldr', + listIndex: 0, + listGroup: 'mwReference/', + listKey: 'auto/0', + refGroup: '' + } }, + { type: '/mwReference' }, + { type: 'mwReference', attributes: { + listIndex: 1, + listGroup: 'mwReference/', + listKey: 'auto/1', + refGroup: '' + } }, + { type: '/mwReference' }, + { type: '/paragraph' }, + { type: 'mwReferencesList', attributes: { + listGroup: 'mwReference/', + refGroup: '' + } }, + { type: 'paragraph' }, + { type: 'mwReference', attributes: { + listIndex: 2, + listGroup: 'mwReference/', + listKey: 'literal/ldr', + refGroup: '' + } }, + { type: '/mwReference' }, + { type: '/paragraph' }, + { type: '/mwReferencesList' }, + { type: 'internalList' }, + { type: 'internalItem' }, + { type: 'paragraph' }, + 'S', 'u', 'b', 'r', 'e', 'f', + { type: '/paragraph' }, + { type: '/internalItem' }, + { type: 'internalItem' }, + { type: 'paragraph' }, + 'O', 't', 'h', 'e', 'r', + { type: '/paragraph' }, + { type: '/internalItem' }, + { type: 'internalItem' }, + { type: 'paragraph' }, + 'L', 'i', 's', 't', '-', 'd', 'e', 'f', 'i', 'n', 'e', 'd', + { type: '/paragraph' }, + { type: '/internalItem' }, + { type: '/internalList' } +];