mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
e123a39b4e
Was broken both on the way in and on the way out. * Move alien restoration (data->DOM) out of the main getDomFromData() function and into getDomElementFromDataElement(). This means the comment about District 9 is gone (sniff), but moving this here ensures all code paths hit it (previously, it was assumed annotated nodes could never be aliens). * In the DOM->data converter, add annotation application to getDataElementFromDomElement() (for content nodes) and createAlien() (for aliens). Previously, these nodes would not get annotations. ** ve.AnnotationSet doesn't have a constructor that takes an array, we should fix that. Change-Id: I65f8e9a322111ca3af275bf9997b0b1e7ee93769
67 lines
1.6 KiB
JavaScript
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', 42, 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', 46, 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
|
|
);
|
|
}
|
|
} );
|