mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
361283a332
We originally used 'templates' because it seemed like an obvious choice for HTML files, and because 'packageFiles' requires extra code to include anything that isn't a .js or .json file. However, the templates are expected to be HTML fragments rather than whole documents, and they are parsed in a particular way that takes a lot of code to clean up (which we needed to do, because we use the same test files for testing PHP code). I tried doing it in the 'packageFiles' way, and the extra code doesn't seem that bad in comparison after all. Moreover, the 'templates' mechanism (when used the intended way) feels vaguely deprecated in favor of Vue.js, and I'd rather move away from it. This makes the tests faster too (probably mostly thanks to the removal of the clean up code) – on my machine they go from 1800ms to 1500ms. (Simplify linearWalk tests, as we no longer need to do weird things with document fragments to get consistent outputs in PHP and JS.) Change-Id: I39f9b994ce5636d70fea2e935a7c87c7d56dcb26
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
var utils = require( 'ext.discussionTools.init' ).utils;
|
|
|
|
QUnit.module( 'mw.dt.utils', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( '#linearWalk', function ( assert ) {
|
|
var cases = require( '../cases/linearWalk.json' );
|
|
|
|
cases.forEach( function ( caseItem ) {
|
|
var
|
|
doc = ve.createDocumentFromHtml( require( '../' + caseItem.dom ) ),
|
|
expected = require( caseItem.expected );
|
|
|
|
var actual = [];
|
|
utils.linearWalk( doc, function ( event, node ) {
|
|
actual.push( event + ' ' + node.nodeName.toLowerCase() + '(' + node.nodeType + ')' );
|
|
} );
|
|
|
|
var actualBackwards = [];
|
|
utils.linearWalkBackwards( doc, 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 ) );
|
|
} );
|
|
} );
|