Debian Codegraph @

extensions/Cite/tests/qunit/ve-cite/ve.dm.MWGroupReferences.test.js

raw symbols SCIP
1 'use strict';
2
3 ( function () {
4 QUnit.module( 've.dm.MWGroupReferences (Cite)', ve.test.utils.newMwEnvironment() );
5
6 const doc = ve.dm.citeExample.createExampleDocument( 'references' );
7 const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( doc );
8 const plainGroupRefs = docRefs.getGroupRefs( '' );
9 const fooGroupRefs = docRefs.getGroupRefs( 'foo' );
10 const emptyGroupRefs = docRefs.getGroupRefs( 'doesnotexist' );
11
12 QUnit.test( 'isEmpty', ( assert ) => {
13 assert.false( plainGroupRefs.isEmpty() );
14 assert.false( fooGroupRefs.isEmpty() );
15 assert.true( emptyGroupRefs.isEmpty() );
16 } );
17
18 QUnit.test( 'getAllRefsInDocumentOrder', ( assert ) => {
19 assert.deepEqual(
20 plainGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
21 [
22 'auto/0',
23 'literal/bar',
24 'literal/:3',
25 'auto/1'
26 ]
27 );
28 assert.deepEqual(
29 fooGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
30 [
31 'auto/2'
32 ]
33 );
34 assert.deepEqual( emptyGroupRefs.getAllRefsInDocumentOrder(), [] );
35 } );
36
37 QUnit.test( 'getTopLevelKeysInReflistOrder', ( assert ) => {
38 assert.deepEqual(
39 plainGroupRefs.getTopLevelKeysInReflistOrder(),
40 [
41 'auto/0',
42 'literal/bar',
43 'literal/:3',
44 'auto/1'
45 ]
46 );
47 assert.deepEqual(
48 fooGroupRefs.getTopLevelKeysInReflistOrder(),
49 [
50 'auto/2'
51 ]
52 );
53 assert.deepEqual( emptyGroupRefs.getTopLevelKeysInReflistOrder(), [] );
54 } );
55
56 QUnit.test( 'getRefNode', ( assert ) => {
57 assert.strictEqual( plainGroupRefs.getRefNode( 'auto/0' ).getAttribute( 'listKey' ), 'auto/0' );
58 assert.strictEqual( plainGroupRefs.getRefNode( 'doesnotexist' ), undefined );
59 } );
60
61 QUnit.test( 'getInternalModelNode', ( assert ) => {
62 // TODO: assert something that makes sense
63 // assert.strictEqual( plainGroupRefs.getInternalModelNode( 'auto/0' ), undefined );
64 assert.strictEqual( plainGroupRefs.getInternalModelNode( 'doesnotexist' ), undefined );
65 } );
66
67 QUnit.test( 'getRefUsages', ( assert ) => {
68 assert.deepEqual(
69 plainGroupRefs.getRefUsages( 'literal/bar' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
70 [
71 'literal/bar',
72 'literal/bar'
73 ]
74 );
75 assert.deepEqual( plainGroupRefs.getRefUsages( 'doesnotexist' ), [] );
76 } );
77
78 QUnit.test( 'getTotalUsageCount', ( assert ) => {
79 const mockListKey = 'literal/bar';
80
81 // The total usage count should be the sum of main refs and subrefs
82 assert.strictEqual(
83 plainGroupRefs.getTotalUsageCount( mockListKey ),
84 plainGroupRefs.getRefUsages( mockListKey ).length +
85 plainGroupRefs.getSubrefs( mockListKey ).length
86 );
87 } );
88
89 QUnit.test( 'sub-references', ( assert ) => {
90 const extendsDoc = ve.dm.citeExample.createExampleDocument( 'extends' );
91 const extendsGroupRefs = ve.dm.MWDocumentReferences.static.refsForDoc( extendsDoc ).getGroupRefs( '' );
92
93 assert.deepEqual(
94 extendsGroupRefs.getAllRefsInDocumentOrder().map( ( node ) => node.getAttribute( 'listKey' ) ),
95 [
96 'literal/ldr',
97 'auto/0',
98 'auto/1',
99 'literal/orphaned'
100 ]
101 );
102
103 assert.deepEqual(
104 extendsGroupRefs.getTopLevelKeysInReflistOrder(),
105 [
106 'literal/ldr',
107 'auto/1',
108 'literal/nonexistent'
109 ]
110 );
111
112 assert.deepEqual(
113 extendsGroupRefs.getRefUsages( 'auto/0' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
114 [
115 'auto/0'
116 ]
117 );
118
119 assert.deepEqual(
120 extendsGroupRefs.getSubrefs( 'literal/ldr' ).map( ( node ) => node.getAttribute( 'listKey' ) ),
121 [
122 'auto/0'
123 ]
124 );
125 } );
126 }() );