mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Added more tests for selectNodes
Change-Id: Ibd9672fb9b6ce682905d20f9346fada6fb47b380
This commit is contained in:
parent
4d9299b808
commit
123c64cbd5
|
@ -70,7 +70,7 @@ ve.dm.Document.prototype.rebuildNodes = function( parent, index, numNodes, offse
|
|||
*
|
||||
* @method
|
||||
* @param {ve.Range} range Range within document to select nodes
|
||||
* @param {String} [mode='leaves'] Type of selection to perform, currently only 'leaves' is supported
|
||||
* @param {String} [mode='leaves'] Type of selection to perform
|
||||
* 'leaves': Return all leaf nodes in the given range
|
||||
* @returns {Array} List of objects describing nodes in the selection and the ranges therein
|
||||
* @throws 'Invalid start offset' if range.start is out of range
|
||||
|
|
|
@ -32,30 +32,38 @@ test( 'rebuildNodes', function() {
|
|||
ve.dm.example.nodeTreeEqual( documentNode, tree );
|
||||
} );
|
||||
|
||||
test( 'selectNodes', 14, function() {
|
||||
test( 'selectNodes', 17, 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 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 ) }
|
||||
]
|
||||
);
|
||||
// Test count: ( 1 test + ( 2 tests x 2 results ) ) = 5
|
||||
ve.dm.example.nodeSelectionEqual(
|
||||
doc.selectNodes( new ve.Range( 0, 10 ), 'leaves' ),
|
||||
[
|
||||
// heading/text
|
||||
// heading/text - tests full coverage leaf nodes do not have ranges
|
||||
{ 'node': lookup( documentNode, 0, 0 ) },
|
||||
// table/tableRow/tableCell/paragraph/text
|
||||
// table/tableRow/tableCell/paragraph/text - tests leaf nodes from different levels
|
||||
{ 'node': lookup( documentNode, 1, 0, 0, 0, 0 ) }
|
||||
]
|
||||
);
|
||||
// Test count: ( 1 test + ( 2 tests x 4 results ) ) = 9
|
||||
ve.dm.example.nodeSelectionEqual(
|
||||
doc.selectNodes( new ve.Range( 28, 41 ) ),
|
||||
doc.selectNodes( new ve.Range( 28, 41 ), 'leaves' ),
|
||||
[
|
||||
// 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
|
||||
// preformatted/image - tests leaf nodes that are not text nodes
|
||||
{ 'node': lookup( documentNode, 2, 1 ) },
|
||||
// preformatted/text
|
||||
{ 'node': lookup( documentNode, 2, 2 ) }
|
||||
|
|
Loading…
Reference in a new issue