mediawiki-extensions-Visual.../tests/ve2/dm/ve.dm.Document.test.js
Trevor Parscal 1798a478e7 Massive refactor of node trees, generalizing lots of previously dm only stuff
Change-Id: I9dbb7094f86338ea2e725ad29f66e9e4ca2b52ed
2012-05-09 21:11:09 -07:00

39 lines
1.3 KiB
JavaScript

module( 've.dm.Document' );
/* Tests */
test( 'getOuterLength', 1, function() {
var doc = new ve.dm.Document( ve.dm.example.data );
strictEqual(
doc.getDocumentNode().getOuterLength(),
ve.dm.example.data.length,
'document does not have elements around it'
);
} );
test( 'rebuildNodes', function() {
var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ),
documentNode = doc.getDocumentNode();
// Rebuild without changes
doc.rebuildNodes( documentNode, 1, 1, 5, 30 );
ve.example.nodeTreeEqual( documentNode, ve.dm.example.tree );
// XXX: Create a new document node tree from the old one
var tree = new ve.dm.DocumentNode( ve.dm.example.tree.getChildren() );
// Replace table with paragraph
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 );
ve.example.nodeTreeEqual( documentNode, tree );
} );
test( 'selectNodes', function() {
var doc = new ve.dm.Document( ve.dm.example.data ),
cases = ve.example.getSelectNodesCases( doc );
for ( var i = 0; i < cases.length; i++ ) {
ve.example.nodeSelectionEqual( cases[i].actual, cases[i].expected );
}
} );