2012-04-27 21:59:52 +00:00
|
|
|
module( 've.dm.Document' );
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2012-04-30 20:48:20 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2012-05-04 18:56:32 +00:00
|
|
|
test( 'rebuildNodes', 114, function() {
|
2012-04-30 20:42:32 +00:00
|
|
|
var doc = new ve.dm.Document( ve.dm.example.data ),
|
|
|
|
documentNode = doc.getDocumentNode();
|
|
|
|
doc.rebuildNodes( documentNode, 1, 1, 5, 30 );
|
2012-05-04 18:56:32 +00:00
|
|
|
// Test count: ( ( 4 tests x 21 branch nodes ) + ( 3 tests x 10 leaf nodes ) ) = 114
|
2012-04-30 20:42:32 +00:00
|
|
|
ve.dm.example.nodeTreeEqual( documentNode, ve.dm.example.tree );
|
2012-04-27 21:59:52 +00:00
|
|
|
} );
|
2012-05-07 22:14:37 +00:00
|
|
|
|
2012-05-07 23:05:40 +00:00
|
|
|
test( 'selectNodes', 16, function() {
|
2012-05-07 22:14:37 +00:00
|
|
|
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 ) ),
|
|
|
|
[
|
2012-05-07 22:50:11 +00:00
|
|
|
// heading/text
|
|
|
|
{ 'node': lookup( documentNode, 0, 0 ) },
|
2012-05-07 23:05:40 +00:00
|
|
|
// table/tableRow/tableCell/paragraph/text
|
2012-05-07 22:14:37 +00:00
|
|
|
{ 'node': lookup( documentNode, 1, 0, 0, 0, 0 ), 'range': new ve.Range( 9, 10 ) }
|
|
|
|
]
|
|
|
|
);
|
2012-05-07 23:05:40 +00:00
|
|
|
// Test count: ( 1 test + ( 2 tests x 4 results ) + ( 2 test + 0 result with range ) ) = 9
|
|
|
|
ve.dm.example.nodeSelectionEqual(
|
|
|
|
doc.selectNodes( new ve.Range( 28, 41 ) ),
|
|
|
|
[
|
|
|
|
// table/tableRow/tableCell/list/listItem/paragraph/text
|
|
|
|
{ 'node': lookup( documentNode, 1, 0, 0, 2, 0, 0, 0 ) },
|
|
|
|
// preformatted/text
|
|
|
|
{ 'node': lookup( documentNode, 2, 0 ) },
|
|
|
|
// preformatted/image
|
|
|
|
{ 'node': lookup( documentNode, 2, 1 ) },
|
|
|
|
// preformatted/text
|
|
|
|
{ 'node': lookup( documentNode, 2, 2 ) }
|
|
|
|
]
|
|
|
|
);
|
2012-05-07 22:14:37 +00:00
|
|
|
} );
|