mediawiki-extensions-Visual.../tests/ve2/ce/ve.ce.Node.test.js
Trevor Parscal f6864b0c04 Changed use of "factory" to "nodeFactory" to make way for other kinds of factories
Change-Id: I96db0f28bb220f1c3b23990824e9523278cb8f9b
2012-05-31 15:20:58 -07:00

47 lines
1.4 KiB
JavaScript

module( 've.ce.Node' );
/* Stubs */
ve.ce.NodeStub = function( model ) {
// Inheritance
ve.ce.Node.call( this, 'stub', model );
};
ve.extendClass( ve.ce.NodeStub, ve.ce.Node );
ve.ce.nodeFactory.register( 'stub', ve.ce.NodeStub );
/* Tests */
test( 'getModel', 1, function() {
var model = new ve.dm.NodeStub( 'stub', 0 ),
view = new ve.ce.NodeStub( model );
strictEqual( view.getModel(), model, 'returns reference to model given to constructor' );
} );
test( 'getParent', 1, function() {
var a = new ve.ce.NodeStub( new ve.dm.NodeStub( 'stub', 0 ) );
strictEqual( a.getParent(), null, 'returns null if not attached' );
} );
test( 'attach', 2, function() {
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 ) {
strictEqual( parent, b, 'attach event is called with parent as first argument' );
} );
a.attach( b );
strictEqual( a.getParent(), b, 'parent is set to given object after attach' );
} );
test( 'detach', 2, function() {
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 ) {
strictEqual( parent, b, 'detach event is called with parent as first argument' );
} );
a.detach();
strictEqual( a.getParent(), null, 'parent is set null after detach' );
} );