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-07 23:25:39 +00:00
|
|
|
test( 'rebuildNodes', function() {
|
2012-05-08 00:03:14 +00:00
|
|
|
var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ),
|
2012-04-30 20:42:32 +00:00
|
|
|
documentNode = doc.getDocumentNode();
|
2012-05-07 23:18:24 +00:00
|
|
|
|
|
|
|
// Rebuild without changes
|
2012-04-30 20:42:32 +00:00
|
|
|
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-05-07 23:25:39 +00:00
|
|
|
|
|
|
|
// Create a copy of the example tree
|
|
|
|
var tree = new ve.dm.DocumentNode( ve.dm.example.tree.getChildren() );
|
|
|
|
// Remove table from linear model
|
|
|
|
doc.data.splice( 5, 30, { 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' } );
|
|
|
|
// Remove table from tree model
|
|
|
|
tree.splice( 1, 1, new ve.dm.ParagraphNode( [new ve.dm.TextNode( 3 )] ) );
|
|
|
|
// Rebuild with changes
|
|
|
|
doc.rebuildNodes( documentNode, 1, 1, 5, 5 );
|
|
|
|
// Test count:
|
|
|
|
ve.dm.example.nodeTreeEqual( documentNode, tree );
|
2012-04-27 21:59:52 +00:00
|
|
|
} );
|
2012-05-07 22:14:37 +00:00
|
|
|
|
2012-05-08 02:03:59 +00:00
|
|
|
test( 'selectNodes', 17, 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;
|
|
|
|
|
2012-05-08 02:03:59 +00:00
|
|
|
// Test count: ( 1 test + ( 2 tests x 1 results ) ) = 3
|
|
|
|
ve.dm.example.nodeSelectionEqual(
|
|
|
|
doc.selectNodes( new ve.Range( 0, 3 ), 'leaves' ),
|
|
|
|
[
|
|
|
|
// heading/text - tests partial leaf results have ranges with global offsets
|
|
|
|
{ 'node': lookup( documentNode, 0, 0 ), 'range': new ve.Range( 1, 3 ) }
|
|
|
|
]
|
|
|
|
);
|
2012-05-07 23:18:24 +00:00
|
|
|
// Test count: ( 1 test + ( 2 tests x 2 results ) ) = 5
|
2012-05-07 22:14:37 +00:00
|
|
|
ve.dm.example.nodeSelectionEqual(
|
2012-05-07 23:04:19 +00:00
|
|
|
doc.selectNodes( new ve.Range( 0, 10 ), 'leaves' ),
|
2012-05-07 22:14:37 +00:00
|
|
|
[
|
2012-05-08 02:03:59 +00:00
|
|
|
// heading/text - tests full coverage leaf nodes do not have ranges
|
2012-05-07 22:50:11 +00:00
|
|
|
{ 'node': lookup( documentNode, 0, 0 ) },
|
2012-05-08 02:03:59 +00:00
|
|
|
// table/tableRow/tableCell/paragraph/text - tests leaf nodes from different levels
|
2012-05-07 23:57:56 +00:00
|
|
|
{ 'node': lookup( documentNode, 1, 0, 0, 0, 0 ) }
|
2012-05-07 22:14:37 +00:00
|
|
|
]
|
|
|
|
);
|
2012-05-07 23:18:24 +00:00
|
|
|
// Test count: ( 1 test + ( 2 tests x 4 results ) ) = 9
|
2012-05-07 23:05:40 +00:00
|
|
|
ve.dm.example.nodeSelectionEqual(
|
2012-05-08 02:03:59 +00:00
|
|
|
doc.selectNodes( new ve.Range( 28, 41 ), 'leaves' ),
|
2012-05-07 23:05:40 +00:00
|
|
|
[
|
|
|
|
// table/tableRow/tableCell/list/listItem/paragraph/text
|
|
|
|
{ 'node': lookup( documentNode, 1, 0, 0, 2, 0, 0, 0 ) },
|
|
|
|
// preformatted/text
|
|
|
|
{ 'node': lookup( documentNode, 2, 0 ) },
|
2012-05-08 02:03:59 +00:00
|
|
|
// preformatted/image - tests leaf nodes that are not text nodes
|
2012-05-07 23:05:40 +00:00
|
|
|
{ 'node': lookup( documentNode, 2, 1 ) },
|
|
|
|
// preformatted/text
|
|
|
|
{ 'node': lookup( documentNode, 2, 2 ) }
|
|
|
|
]
|
|
|
|
);
|
2012-05-07 22:14:37 +00:00
|
|
|
} );
|