mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
22d1908bd4
The easy part is getting the correct numbers from the InternalList and generating the ordered list HTML. The tricky part is connecting up the events to make sure the renumberings/list generations are triggered when required. InternalList can emit an update event on document transaction, which triggers the renumbering/relisting if any references have been added or deleted during that transaction. ve.ce.MWReferenceListNode also listens to changes on the InternalListNode (i.e. changes to the contents of the references) and always triggers a rebuild. Change-Id: I1b48ef5240e433c3b314259aa68cde13841ea98b
119 lines
3.4 KiB
JavaScript
119 lines
3.4 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel Converter tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.dm.Converter' );
|
|
|
|
/* Tests */
|
|
|
|
// TODO rewrite to test getDataElementOrAnnotationFromDomElement
|
|
/*
|
|
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( 'getDomElementsFromDataElement', 20, function ( assert ) {
|
|
var msg, conversion, doc;
|
|
|
|
for ( msg in ve.dm.example.conversions ) {
|
|
conversion = ve.dm.example.conversions[msg];
|
|
doc = conversion.domElement.ownerDocument;
|
|
assert.equalDomElement(
|
|
ve.dm.converter.getDomElementsFromDataElement( conversion.dataElement, doc )[0],
|
|
conversion.domElement,
|
|
msg
|
|
);
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'getDataFromDom', function ( assert ) {
|
|
var msg, doc, store, internalList, i, length, hash, n = 0,
|
|
cases = ve.copyObject( ve.dm.example.domToDataCases );
|
|
|
|
// TODO: this is a hack to make normal heading/preformatted
|
|
// nodes the most recently registered, instead of the MW versions
|
|
ve.dm.modelRegistry.register( ve.dm.HeadingNode );
|
|
ve.dm.modelRegistry.register( ve.dm.PreformattedNode );
|
|
|
|
for ( msg in cases ) {
|
|
if ( cases[msg].html !== null ) {
|
|
n++;
|
|
if ( cases[msg].storeItems ) {
|
|
n += cases[msg].storeItems.length;
|
|
}
|
|
}
|
|
}
|
|
QUnit.expect( n );
|
|
|
|
for ( msg in cases ) {
|
|
if ( cases[msg].html !== null ) {
|
|
doc = new ve.dm.Document( [] );
|
|
store = doc.getStore();
|
|
internalList = doc.getInternalList();
|
|
ve.dm.example.preprocessAnnotations( cases[msg].data, store );
|
|
assert.deepEqualWithDomElements(
|
|
ve.dm.converter.getDataFromDom(
|
|
ve.createDocumentFromHtml( cases[msg].html ), store, internalList
|
|
).getData(),
|
|
cases[msg].data,
|
|
msg
|
|
);
|
|
// check storeItems have been added to store
|
|
if ( cases[msg].storeItems ) {
|
|
for ( i = 0, length = cases[msg].storeItems.length; i < length; i++ ) {
|
|
hash = cases[msg].storeItems[i].hash || ve.getHash( cases[msg].storeItems[i].value );
|
|
assert.deepEqualWithDomElements(
|
|
store.value( store.indexOfHash( hash ) ),
|
|
cases[msg].storeItems[i].value,
|
|
msg + ': store item ' + i + ' found'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'getDomFromData', function ( assert ) {
|
|
var msg, originalData, doc, store, i, length, n = 0,
|
|
cases = ve.copyObject( ve.dm.example.domToDataCases );
|
|
|
|
for ( msg in cases ) {
|
|
n++;
|
|
}
|
|
QUnit.expect( 2*n );
|
|
|
|
for ( msg in cases ) {
|
|
store = new ve.dm.IndexValueStore();
|
|
// load storeItems into store
|
|
if ( cases[msg].storeItems ) {
|
|
for ( i = 0, length = cases[msg].storeItems.length; i < length; i++ ) {
|
|
store.index( cases[msg].storeItems[i].value, cases[msg].storeItems[i].hash );
|
|
}
|
|
}
|
|
if ( cases[msg].modify ) {
|
|
cases[msg].modify( cases[msg].data );
|
|
}
|
|
doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[msg].data, store ) );
|
|
originalData = ve.copyArray( doc.getFullData() );
|
|
assert.equalDomElement(
|
|
ve.dm.converter.getDomFromData( doc.getFullData(), doc.getStore(), doc.getInternalList() ),
|
|
ve.createDocumentFromHtml( cases[msg].normalizedHtml || cases[msg].html ),
|
|
msg
|
|
);
|
|
assert.deepEqualWithDomElements( doc.getFullData(), originalData, msg + ' (data hasn\'t changed)' );
|
|
}
|
|
} );
|