2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor data model DocumentSynchronizer tests.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-10 00:13:55 +00:00
|
|
|
module( 've.dm.DocumentSynchronizer' );
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'getDocument', 1, function( assert ) {
|
2012-05-10 00:13:55 +00:00
|
|
|
var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ),
|
|
|
|
ds = new ve.dm.DocumentSynchronizer( doc );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( ds.getDocument(), doc );
|
2012-05-10 00:13:55 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'synchronize', 2, function( assert ) {
|
2012-05-10 01:31:09 +00:00
|
|
|
var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ),
|
|
|
|
ds = new ve.dm.DocumentSynchronizer( doc );
|
|
|
|
|
|
|
|
// Annotate "a" with bold formatting
|
|
|
|
doc.data[1] = ['a', { '{"type":"bold"}': { 'type': 'bold' } }];
|
|
|
|
ds.pushAnnotation( new ve.Range( 1, 2 ) );
|
|
|
|
doc.getDocumentNode().getChildren()[0].getChildren()[0].on( 'update', function() {
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.ok( true, 'annotations trigger update events' );
|
2012-05-10 01:31:09 +00:00
|
|
|
} );
|
|
|
|
doc.getDocumentNode().getChildren()[0].getChildren()[0].on( 'annotation', function() {
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.ok( true, 'annotations trigger annotation events' );
|
2012-05-10 01:31:09 +00:00
|
|
|
} );
|
|
|
|
ds.synchronize();
|
|
|
|
} );
|