mediawiki-extensions-Discus.../tests/qunit/utils.test.js
Bartosz Dziewoński 8f42c74985 Fix skipping to the end of paragraph, now it considers nested tags
Add yet another tree walking utility: CommentUtils::linearWalk().
Unlike TreeWalker, it allows handling the beginnings and ends of nodes
separately – kind of like parsing a XML token stream, or kind of like
VisualEditor's linear model.

(Add unit tests for this utility. The simple.html test case is copied
from [VisualEditor/VisualEditor]/demos/ve/pages/simple.html.)

Use this utility to stop skipping when we reach either a closing or
opening block node tag. Previously we'd skip over such tags inside
nested "transparent" nodes (like <a>, <del>, or apparently <font>).

Bug: T271385
Change-Id: I201a942eb3a56335e84d94e150ec2c33f8b4f4e0
2021-01-18 18:20:20 +00:00

26 lines
813 B
JavaScript

var
testUtils = require( './testUtils.js' ),
utils = require( 'ext.discussionTools.init' ).utils;
QUnit.module( 'mw.dt.utils', testUtils.newEnvironment() );
QUnit.test( '#linearWalk', function ( assert ) {
var cases = require( '../cases/linearWalk.json' );
cases.forEach( function ( caseItem ) {
var
$dom = mw.template.get( 'test.DiscussionTools', caseItem.dom ).render(),
expected = require( caseItem.expected ),
actual = [];
utils.linearWalk( $dom[ 0 ].parentNode, function ( event, node ) {
actual.push( event + ' ' + node.nodeName.toLowerCase() + '(' + node.nodeType + ')' );
} );
assert.deepEqual( actual, expected, caseItem.name );
// Uncomment this to get updated content for the JSON files, for copy/paste:
// console.log( JSON.stringify( actual, null, 2 ) );
} );
} );