mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-01 03:26:28 +00:00
7c3e583bec
Change-Id: I72de463d5a878e555eeed0e7ce2772e1d3a46f06
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
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 );
|
|
|
|
var actual = [];
|
|
utils.linearWalk( $dom[ 0 ].parentNode, function ( event, node ) {
|
|
actual.push( event + ' ' + node.nodeName.toLowerCase() + '(' + node.nodeType + ')' );
|
|
} );
|
|
|
|
var actualBackwards = [];
|
|
utils.linearWalkBackwards( $dom[ 0 ].parentNode, function ( event, node ) {
|
|
actualBackwards.push( event + ' ' + node.nodeName.toLowerCase() + '(' + node.nodeType + ')' );
|
|
} );
|
|
|
|
assert.deepEqual( actual, expected, caseItem.name );
|
|
|
|
var expectedBackwards = expected.slice().reverse().map( function ( a ) {
|
|
return ( a.slice( 0, 5 ) === 'enter' ? 'leave' : 'enter' ) + a.slice( 5 );
|
|
} );
|
|
assert.deepEqual( actualBackwards, expectedBackwards, caseItem.name + ' (backwards)' );
|
|
|
|
// Uncomment this to get updated content for the JSON files, for copy/paste:
|
|
// console.log( JSON.stringify( actual, null, 2 ) );
|
|
} );
|
|
} );
|