mediawiki-extensions-Visual.../tests/ve2/dm/ve.dm.Document.test.js
Trevor Parscal f4fcf9663e Added documentation and tests for ve.dm.Document.selectNodes
Also:
* Broke node lookup method out into ve.dm.example.lookupNode
* Added ve.dm.example.nodeSelectionEqual

Change-Id: I437cdd3f3154d10782f03f78df6d5c457ecfc845
2012-05-07 15:15:21 -07:00

38 lines
1.1 KiB
JavaScript

module( 've.dm.Document' );
/* Tests */
test( 'getOuterLength', 1, function() {
var fragment = new ve.dm.DocumentFragment( ve.dm.example.data );
strictEqual(
fragment.getDocumentNode().getOuterLength(),
ve.dm.example.data.length,
'document does not have elements around it'
);
} );
test( 'rebuildNodes', 114, function() {
var doc = new ve.dm.Document( ve.dm.example.data ),
documentNode = doc.getDocumentNode();
doc.rebuildNodes( documentNode, 1, 1, 5, 30 );
// Test count: ( ( 4 tests x 21 branch nodes ) + ( 3 tests x 10 leaf nodes ) ) = 114
ve.dm.example.nodeTreeEqual( documentNode, ve.dm.example.tree );
} );
test( 'selectNodes', 7, function() {
var doc = new ve.dm.Document( ve.dm.example.data ),
documentNode = doc.getDocumentNode(),
lookup = ve.dm.example.lookupNode;
// Test count: ( 1 test + ( 2 tests x 2 results ) + ( 2 test + 1 result with range ) ) = 7
ve.dm.example.nodeSelectionEqual(
doc.selectNodes( new ve.Range( 0, 10 ) ),
[
// heading
{ 'node': lookup( documentNode, 0 ) },
// table/row/cell/paragraph/text
{ 'node': lookup( documentNode, 1, 0, 0, 0, 0 ), 'range': new ve.Range( 9, 10 ) }
]
);
} );