mediawiki-extensions-Visual.../modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js
Timo Tijhof 6cbedbf9d2 tests: Adopt QUnit.test.each() and native async-await in a few places
* Remove need for manual hacking of sub groups via "msg" strings
  carefully prepended to every assertion.

* Improve CI details, by reporting the specific case that failed,
  and local dev via ability to re-run each case, and reporting names
  directly in the HTML Reporter and CLI summary.

* Reduce need for assert.async() and tracking of callbacks, especially
  to improve failure details in case of Promise rejection.
  Current logic was likely to cause a confusing timeout instead of a
  clear failure if the promise ends up rejected.

  QUnit propagates these as part of awaiting and asserting the test
  closure's promise value (as async fn) automatically.

  This approach also avoids the pitfal of a falsely passing test
  when an assertion inside a done() handler was never reached.

* Use modern for-of where possible to remove need for closures and
  arrow functions. Thus reducing complexity of test code, where
  complexity should be kept lowest to avoid false confidence.

* Use plain for-in instead of overly complex Object.keys().forEach().

Change-Id: I934a266e75e64371081f104cfb867fb2c282c84a
2024-05-01 19:01:19 +01:00

52 lines
1.6 KiB
JavaScript

/*!
* VisualEditor MediaWiki-specific ContentEditable ContentBranchNode tests.
*
* @copyright See AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce.ContentBranchNode (MW)' );
/* Tests */
// FIXME runner copypasted from core, use data provider
QUnit.test.each( 'getRenderedContents', {
'Annotation spanning text and inline nodes': {
data: [
{ type: 'paragraph' },
'a',
[ 'b', [ { type: 'textStyle/bold' } ] ],
{
type: 'mwEntity',
attributes: { character: 'c' },
annotations: [ { type: 'textStyle/bold' } ]
},
{ type: '/mwEntity' },
[ 'd', [ { type: 'textStyle/bold' } ] ],
{
type: 'alienInline',
originalDomElements: $.parseHTML( '<span rel="ve:Alien">e</span>' ),
annotations: [ { type: 'textStyle/bold' } ]
},
{ type: '/alienInline' },
{ type: '/paragraph' }
],
html: ve.dm.example.singleLine`
a
<b>
b
<span class="ve-ce-leafNode ve-ce-mwEntityNode" contenteditable="false">c</span>
d
<span rel="ve:Alien" class="ve-ce-focusableNode ve-ce-leafNode" contenteditable="false">e</span>
</b>
`
}
}, ( assert, { data, html } ) => {
const doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( data ) );
const $wrapper = $( new ve.ce.ParagraphNode( doc.getDocumentNode().getChildren()[ 0 ] ).getRenderedContents() );
// HACK strip out all the class="ve-ce-textStyleAnnotation ve-ce-textStyleBoldAnnotation" crap
$wrapper.find( '.ve-ce-textStyleAnnotation' ).removeAttr( 'class' );
assert.equalDomElement( $wrapper[ 0 ], $( '<div>' ).html( html )[ 0 ] );
} );