mediawiki-extensions-Visual.../modules/ve/test/dm/ve.dm.Converter.test.js
Catrope 7bcf35e0e8 (bug 43056) Inline tags like <span> are block-alienated sometimes
This happens when the <span> is the start of unwrapped content. The
converter logic to look at the tag name in wrapping mode doesn't kick in
because we're not yet in wrapping mode at that point.

The core issue was that previously, we relied on the document
structure/state to choose between alienBlock and alienInline, and only
used the tag name where the document structure was ambiguous (wrapping).
Changed this to be the other way around: we now rely primarily on the
tag name, and if that doesn't match what we expect based on the document
structure, we work around that if possible. Specifically:
* inline tag in our wrapper --> inline alien
* block tag in our wrapper --> close wrapper, block alien
* inline tag in wrapper that's not ours --> inline alien
* block tag in wrapper that's not ours --> *inline* alien
* inline tag in structural location --> open wrapper, inline alien
* block tag in structural location --> block alien
* inline tag in content location --> inline alien
* block tag in content location --> *inline* alien
only in the fourth and the last case do we need to use the "wrong" alien type to
preserve document validity, and it will always be inline where block was
expected, which should reduce UI issues.

The condensed version of the above, which is used in the code, is:
* If in a non-wrapper content location, use inline
* If in a wrapper that's not ours, use inline
* Otherwise, decide based on tag name
* Open or close wrapper if needed

ve.dm.Converter:
* Replace isInline logic in createAlien() with the above
* Factor out code to start wrapping (was duplicated) into startWrapping()
* Call startWrapping() if createAlien() returns an alienInline and we're
  in a structural location

Tests:
* Add test cases with aliens at the start and end of unwrapped content
** The first one failed prior to these changes and now passes, the
   second one was already passing
* Fix about group test case, was exhibiting the bug that this commit fixes

Change-Id: I657aa0ff5bc2b57cd48ef8a99c8ca930936c03b8
2012-12-22 12:27:11 +01:00

67 lines
1.6 KiB
JavaScript

/**
* VisualEditor data model Converter tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.Converter' );
/* Tests */
QUnit.test( 'getDataElementFromDomElement', 20, function ( assert ) {
var msg, conversion;
for ( msg in ve.dm.example.conversions ) {
conversion = ve.dm.example.conversions[msg];
assert.deepEqual(
ve.dm.converter.getDataElementFromDomElement( conversion.domElement ),
conversion.dataElement,
msg
);
}
} );
QUnit.test( 'getDomElementFromDataElement', 20, function ( assert ) {
var msg, conversion;
for ( msg in ve.dm.example.conversions ) {
conversion = ve.dm.example.conversions[msg];
assert.equalDomElement(
ve.dm.converter.getDomElementFromDataElement( conversion.dataElement ),
conversion.domElement,
msg
);
}
} );
QUnit.test( 'getDataFromDom', 48, function ( assert ) {
var msg,
cases = ve.dm.example.domToDataCases;
for ( msg in cases ) {
if ( cases[msg].html !== null ) {
ve.dm.example.preprocessAnnotations( cases[msg].data );
assert.deepEqual(
ve.dm.converter.getDataFromDom( $( '<div>' ).html( cases[msg].html )[0] ),
cases[msg].data,
msg
);
}
}
} );
QUnit.test( 'getDomFromData', 52, function ( assert ) {
var msg,
cases = ve.dm.example.domToDataCases;
for ( msg in cases ) {
ve.dm.example.preprocessAnnotations( cases[msg].data );
assert.equalDomElement(
ve.dm.converter.getDomFromData( cases[msg].data ),
$( '<div>' ).html( cases[msg].normalizedHtml || cases[msg].html )[0],
msg
);
}
} );