mediawiki-extensions-Visual.../modules/ve/test/dm/ve.dm.Surface.test.js
Christian Williams 9787166bab Fixing Pre-Annotations
AnnotationAction and SurfaceFragment now use insertAnnotations.

ve.dm.Surface.test
* Removed test for annotate method (not needed anymore)

ve.dm.SurfaceFragment
* Now using getInsertionAnnotations method
* Added support for modifying insertion annotations when annotating a zero-length selection

ve.dm.Surface
* Moved in insertion annotations state from document model
* Added insertion annotation interface (enable, disable, areEnabled, get, set, add, and remove)
* Simplified handling of annotations on change
* Removed annotate method (not used anymore)

ve.dm.Document
* Removed insertion annotations (moved it to surface model)

ve.ce.Surface
* Cleaned up handleInsertion and changed it to use the insertion annotations interface on the surface model

ve.AnnotationAction
* Moved insertion annotation handling out of here since it's now included in the surface fragment

Change-Id: I047d656acf7fa1c63f726ca2b0801e1476f84f96
2012-11-19 17:09:08 -08:00

60 lines
1.6 KiB
JavaScript

/**
* VisualEditor data model Surface tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.Surface' );
ve.dm.SurfaceStub = function VeDmSurfaceStub( data ) {
if ( data !== undefined ) {
this.dm = new ve.dm.Document( data );
} else {
this.dm = new ve.dm.Document( [{ 'type': 'paragraph' }, 'h', 'i', { 'type': '/paragraph' }] );
}
// Inheritance
ve.dm.Surface.call( this, this.dm );
};
ve.inheritClass( ve.dm.SurfaceStub, ve.dm.Surface );
// Tests
QUnit.test( 'getDocument', 1, function ( assert ) {
var surface = new ve.dm.SurfaceStub();
assert.strictEqual( surface.getDocument(), surface.documentModel );
} );
QUnit.test( 'getSelection', 1, function ( assert ) {
var surface = new ve.dm.SurfaceStub();
assert.strictEqual( surface.getSelection(), surface.selection );
} );
QUnit.test( 'change', 3, function ( assert ) {
var surface = new ve.dm.SurfaceStub(),
tx = new ve.dm.Transaction(),
events = {
'transact': 0,
'select': 0,
'change': 0
};
surface.on( 'transact', function () {
events.transact++;
} );
surface.on( 'select', function () {
events.select++;
} );
surface.on( 'change', function () {
events.change++;
} );
surface.change( tx );
assert.deepEqual( events, { 'transact': 1, 'select': 0, 'change': 1 } );
surface.change( null, new ve.Range( 1, 1 ) );
assert.deepEqual( events, { 'transact': 1, 'select': 1, 'change': 2 } );
surface.change( tx, new ve.Range( 2, 2 ) );
assert.deepEqual( events, { 'transact': 2, 'select': 2, 'change': 3 } );
} );