2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor content editable Node 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-01 00:04:49 +00:00
|
|
|
module( 've.ce.Node' );
|
|
|
|
|
|
|
|
/* Stubs */
|
|
|
|
|
|
|
|
ve.ce.NodeStub = function( model ) {
|
|
|
|
// Inheritance
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.ce.Node.call( this, 'stub', model );
|
2012-05-01 00:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.extendClass( ve.ce.NodeStub, ve.ce.Node );
|
|
|
|
|
2012-05-31 22:20:58 +00:00
|
|
|
ve.ce.nodeFactory.register( 'stub', ve.ce.NodeStub );
|
2012-05-05 00:50:54 +00:00
|
|
|
|
2012-05-01 00:04:49 +00:00
|
|
|
/* Tests */
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'getModel', 1, function( assert ) {
|
2012-05-04 00:06:23 +00:00
|
|
|
var model = new ve.dm.NodeStub( 'stub', 0 ),
|
|
|
|
view = new ve.ce.NodeStub( model );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( view.getModel(), model, 'returns reference to model given to constructor' );
|
2012-05-04 00:06:23 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'getParent', 1, function( assert ) {
|
2012-05-04 00:06:23 +00:00
|
|
|
var a = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( a.getParent(), null, 'returns null if not attached' );
|
2012-05-04 00:06:23 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'attach', 2, function( assert ) {
|
2012-05-04 00:06:23 +00:00
|
|
|
var a = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) ),
|
|
|
|
b = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) );
|
|
|
|
a.on( 'attach', function( parent ) {
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( parent, b, 'attach event is called with parent as first argument' );
|
2012-05-04 00:06:23 +00:00
|
|
|
} );
|
|
|
|
a.attach( b );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( a.getParent(), b, 'parent is set to given object after attach' );
|
2012-05-04 00:06:23 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'detach', 2, function( assert ) {
|
2012-05-04 00:06:23 +00:00
|
|
|
var a = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) ),
|
|
|
|
b = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) );
|
|
|
|
a.attach( b );
|
|
|
|
a.on( 'detach', function( parent ) {
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( parent, b, 'detach event is called with parent as first argument' );
|
2012-05-04 00:06:23 +00:00
|
|
|
} );
|
|
|
|
a.detach();
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.strictEqual( a.getParent(), null, 'parent is set null after detach' );
|
2012-05-01 00:04:49 +00:00
|
|
|
} );
|