mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
82114467f1
199 files touched. Whee! Change-Id: Id82ce4a32f833406db4a1cc585674f2bdb39ba0d
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel Surface tests.
|
|
*
|
|
* @copyright 2011-2013 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 } );
|
|
} );
|