mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
5e7c14c868
Introduced the ve.AnnotationSet class to manage sets of annotations. This is a generalization of ve.OrderedHashSet, a class that manages a set using an array and an object keyed by hash. Converted everything that stores, tracks or passes around annotations to use ve.AnnotationSet. In particular, this means the linear model now contains AnnotationSets instead of hash-keyed objects. This allows us to maintain the order of annotations in the linear model, and will help fix bugs with annotation ordering and splitting. Change-Id: I50975b0a95f4cc33017a0b59fdede9ed1eff0124
63 lines
1.6 KiB
JavaScript
63 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', 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', 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', 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', 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
|
|
);
|
|
}
|
|
} );
|