2012-05-01 00:04:49 +00:00
|
|
|
module( 've.ce.BranchNode' );
|
|
|
|
|
|
|
|
/* Stubs */
|
|
|
|
|
|
|
|
ve.ce.BranchNodeStub = function( model, $element ) {
|
|
|
|
// Inheritance
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.ce.BranchNode.call( this, 'branch-stub', model, $element );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ce.BranchNodeStub.rules = {
|
2012-05-22 00:39:03 +00:00
|
|
|
'canBeSplit': true
|
2012-05-01 00:04:49 +00:00
|
|
|
};
|
|
|
|
|
2012-05-04 20:31:14 +00:00
|
|
|
ve.ce.BranchNodeStub.domWrapperElementTypes = {
|
|
|
|
'a': 'a',
|
|
|
|
'b': 'b'
|
|
|
|
};
|
|
|
|
|
2012-05-01 00:04:49 +00:00
|
|
|
ve.extendClass( ve.ce.BranchNodeStub, ve.ce.BranchNode );
|
|
|
|
|
2012-05-31 22:20:58 +00:00
|
|
|
ve.ce.nodeFactory.register( 'branch-stub', ve.ce.BranchNodeStub );
|
2012-05-02 20:58:50 +00:00
|
|
|
|
2012-05-01 00:04:49 +00:00
|
|
|
/* Tests */
|
|
|
|
|
2012-05-22 00:39:03 +00:00
|
|
|
test( 'canBeSplit', 1, function() {
|
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
equal( node.canBeSplit(), true );
|
|
|
|
} );
|
|
|
|
|
2012-05-05 00:50:54 +00:00
|
|
|
test( 'canHaveChildren', 1, function() {
|
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
equal( node.canHaveChildren(), true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'canHaveGrandchildren', 1, function() {
|
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
equal( node.canHaveGrandchildren(), true );
|
|
|
|
} );
|
|
|
|
|
2012-05-04 20:31:14 +00:00
|
|
|
test( 'updateDomWrapper', 3, function() {
|
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub( [], { 'type': 'a' } ) );
|
|
|
|
// Add classes and content to the node
|
2012-05-10 21:55:13 +00:00
|
|
|
node.$.attr( 'class', 'test' ).text( 'hello' );
|
2012-05-04 20:31:14 +00:00
|
|
|
// Modify attribute
|
|
|
|
node.getModel().attributes.type = 'b';
|
|
|
|
node.updateDomWrapper( 'type' );
|
|
|
|
equal( node.$.get( 0 ).nodeName.toLowerCase(), 'b', 'DOM element type gets converted' );
|
2012-05-10 23:58:29 +00:00
|
|
|
equal( node.$.hasClass( 'test' ), true, 'old classes are added to new wrapper' );
|
2012-05-02 20:58:50 +00:00
|
|
|
equal( node.$.text(), 'hello', 'contents are added to new wrapper' );
|
|
|
|
} );
|
|
|
|
|
2012-05-02 21:59:07 +00:00
|
|
|
test( 'onSplice', 7, function() {
|
2012-05-02 20:58:50 +00:00
|
|
|
var modelA = new ve.dm.BranchNodeStub(),
|
|
|
|
modelB = new ve.dm.BranchNodeStub(),
|
|
|
|
modelC = new ve.dm.BranchNodeStub(),
|
|
|
|
viewA = new ve.ce.BranchNodeStub( modelA );
|
2012-05-02 21:59:07 +00:00
|
|
|
// Insertion tests
|
2012-05-02 20:58:50 +00:00
|
|
|
modelA.splice( 0, 0, modelB, modelC );
|
|
|
|
equal( viewA.getChildren().length, 2 );
|
|
|
|
deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
|
|
|
deepEqual( viewA.getChildren()[1].getModel(), modelC );
|
2012-05-02 21:59:07 +00:00
|
|
|
// Removal tests
|
2012-05-02 21:50:28 +00:00
|
|
|
modelA.splice( 0, 1 );
|
|
|
|
equal( viewA.getChildren().length, 1 );
|
|
|
|
deepEqual( viewA.getChildren()[0].getModel(), modelC );
|
2012-05-02 21:59:07 +00:00
|
|
|
// Removal and insertion tests
|
|
|
|
modelA.splice( 0, 1, modelB );
|
|
|
|
equal( viewA.getChildren().length, 1 );
|
|
|
|
deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
2012-05-01 00:04:49 +00:00
|
|
|
} );
|