Adding some QUnit tests for MWGroupReferences

Bug: T373854
Change-Id: Ie1ea1016e6e67429b109989bc7995b6dd532f314
This commit is contained in:
WMDE-Fisch 2024-09-03 14:03:13 +02:00
parent 4d8cb0d18a
commit f133ad3ead
2 changed files with 116 additions and 0 deletions

View file

@ -246,6 +246,7 @@
"tests/qunit/ve-cite/ve.dm.citeExample.js",
"tests/qunit/ve-cite/ve.dm.Converter.test.js",
"tests/qunit/ve-cite/ve.dm.MWDocumentReferences.test.js",
"tests/qunit/ve-cite/ve.dm.MWGroupReferences.test.js",
"tests/qunit/ve-cite/ve.dm.InternalList.test.js",
"tests/qunit/ve-cite/ve.dm.MWReferenceModel.test.js",
"tests/qunit/ve-cite/ve.dm.MWReferenceNode.test.js",

View file

@ -0,0 +1,115 @@
'use strict';
( function () {
QUnit.module( 've.dm.MWGroupReferences (Cite)', ve.test.utils.newMwEnvironment() );
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
const plainGroupRefs = docRefs.getGroupRefs( '' );
const fooGroupRefs = docRefs.getGroupRefs( 'foo' );
const emptyGroupRefs = docRefs.getGroupRefs( 'doenotexist' );
QUnit.test( 'isEmpty', ( assert ) => {
assert.false( plainGroupRefs.isEmpty() );
assert.false( fooGroupRefs.isEmpty() );
assert.true( emptyGroupRefs.isEmpty() );
} );
QUnit.test( 'getAllRefsInDocumentOrder', ( assert ) => {
assert.deepEqual(
plainGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'auto/0',
'literal/bar',
'literal/:3',
'auto/1'
]
);
assert.deepEqual(
fooGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'auto/2'
]
);
assert.deepEqual( emptyGroupRefs.getAllRefsInDocumentOrder(), [] );
} );
QUnit.test( 'getTopLevelKeysInReflistOrder', ( assert ) => {
assert.deepEqual(
plainGroupRefs.getTopLevelKeysInReflistOrder(),
[
'auto/0',
'literal/bar',
'literal/:3',
'auto/1'
]
);
assert.deepEqual(
fooGroupRefs.getTopLevelKeysInReflistOrder(),
[
'auto/2'
]
);
assert.deepEqual( emptyGroupRefs.getTopLevelKeysInReflistOrder(), [] );
} );
QUnit.test( 'getRefNode', ( assert ) => {
assert.strictEqual( plainGroupRefs.getRefNode( 'auto/0' ).getAttribute( 'listKey' ), 'auto/0' );
assert.strictEqual( plainGroupRefs.getRefNode( 'doenotexist' ), undefined );
} );
QUnit.test( 'getInternalModelNode', ( assert ) => {
// TODO: assert something that makes sense
// assert.strictEqual( plainGroupRefs.getInternalModelNode( 'auto/0' ), undefined );
assert.strictEqual( plainGroupRefs.getInternalModelNode( 'doenotexist' ), undefined );
} );
QUnit.test( 'getRefUsages', ( assert ) => {
assert.deepEqual(
plainGroupRefs.getRefUsages( 'literal/bar' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'literal/bar',
'literal/bar'
]
);
assert.deepEqual( plainGroupRefs.getRefUsages( 'doenotexist' ), [] );
} );
QUnit.test( 'sub-references', ( assert ) => {
const extendsDoc = ve.dm.citeExample.createExampleDocument( 'extends' );
const extendsGroupRefs = ve.dm.MWDocumentReferences.static.refsForDoc( extendsDoc ).getGroupRefs( '' );
assert.deepEqual(
extendsGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'literal/ldr',
'auto/0',
'auto/1',
'literal/orphaned'
]
);
assert.deepEqual(
extendsGroupRefs.getTopLevelKeysInReflistOrder(),
[
'literal/ldr',
'auto/1',
'literal/nonexistent'
]
);
assert.deepEqual(
extendsGroupRefs.getRefUsages( 'auto/0' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'auto/0'
]
);
assert.deepEqual(
extendsGroupRefs.getSubrefs( 'literal/ldr' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
[
'auto/0'
]
);
} );
}() );