mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Added test for replaceDomWrapper and onSplice in ve.ce.BranchNode
* Also fixed calls to addListenerMethod * Also routed adding children in the constructor of ve.dm.BranchNode to the splice method * Renamed types of ve.dm stub nodes to avoid collisions (since we have to register ce nodes by the same names for them to be generated by onSplice) Change-Id: Ia2e75cf0a62186cc0e214683feb25c619590318a
This commit is contained in:
parent
8bd0d385eb
commit
fd28fff50f
|
@ -14,7 +14,7 @@ ve.ce.HeadingNode = function( model ) {
|
||||||
this.currentLevel = model.getAttribute( 'level' );
|
this.currentLevel = model.getAttribute( 'level' );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( 'update', this, 'onUpdate' );
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Static Members */
|
/* Static Members */
|
||||||
|
|
|
@ -14,7 +14,7 @@ ve.ce.ImageNode = function( model ) {
|
||||||
this.currentSource = model.getAttribute( 'html/src' );
|
this.currentSource = model.getAttribute( 'html/src' );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( 'update', this, 'onUpdate' );
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Static Members */
|
/* Static Members */
|
||||||
|
|
|
@ -14,7 +14,7 @@ ve.ce.ListItemNode = function( model ) {
|
||||||
this.currentStyle = model.getAttribute( 'style' );
|
this.currentStyle = model.getAttribute( 'style' );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( 'update', this, 'onUpdate' );
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Static Members */
|
/* Static Members */
|
||||||
|
|
|
@ -14,7 +14,7 @@ ve.ce.ListNode = function( model ) {
|
||||||
this.currentStyle = model.getAttribute( 'style' );
|
this.currentStyle = model.getAttribute( 'style' );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( 'update', this, 'onUpdate' );
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Static Members */
|
/* Static Members */
|
||||||
|
|
|
@ -15,10 +15,12 @@ ve.ce.BranchNode = function( model, $element ) {
|
||||||
ve.ce.Node.call( this, model, $element );
|
ve.ce.Node.call( this, model, $element );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.model.addListenerMethod( 'splice', this, 'onSplice' );
|
this.model.addListenerMethod( this, 'splice', 'onSplice' );
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
this.onSplice.apply( this, [0, 0].concat( model.getChildren() ) );
|
if ( model.getChildren().length ) {
|
||||||
|
this.onSplice.apply( this, [0, 0].concat( model.getChildren() ) );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
@ -41,7 +43,7 @@ ve.ce.BranchNode.prototype.onSplice = function( index, howmany ) {
|
||||||
// Convert models to views and attach them to this node
|
// Convert models to views and attach them to this node
|
||||||
if ( args.length >= 3 ) {
|
if ( args.length >= 3 ) {
|
||||||
for ( i = 2, length = args.length; i < length; i++ ) {
|
for ( i = 2, length = args.length; i < length; i++ ) {
|
||||||
args[i] = args[i].createView();
|
args[i] = ve.ce.factory.createNode( args[i].getType(), args[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var removals = this.children.splice.apply( this.children, args );
|
var removals = this.children.splice.apply( this.children, args );
|
||||||
|
|
|
@ -16,9 +16,7 @@ ve.dm.BranchNode = function( type, children, attributes ) {
|
||||||
ve.BranchNode.call( this );
|
ve.BranchNode.call( this );
|
||||||
|
|
||||||
if ( ve.isArray( children ) && children.length ) {
|
if ( ve.isArray( children ) && children.length ) {
|
||||||
for ( var i = 0; i < children.length; i++ ) {
|
this.splice.apply( this, [0, 0].concat( children ) );
|
||||||
this.push( children[i] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,29 @@ ve.ce.BranchNodeStub = function( model, $element ) {
|
||||||
|
|
||||||
ve.extendClass( ve.ce.BranchNodeStub, ve.ce.BranchNode );
|
ve.extendClass( ve.ce.BranchNodeStub, ve.ce.BranchNode );
|
||||||
|
|
||||||
|
ve.ce.factory.register( 'branch-stub', ve.ce.BranchNodeStub );
|
||||||
|
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
/*
|
test( 'replaceDomWrapper', 4, function() {
|
||||||
test( '', 1, function() {
|
var $oldWrapper = $( '<h1 class="test">hello</h1>' ),
|
||||||
//
|
$newWrapper = $( '<h2></h2>' ),
|
||||||
|
node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub(), $oldWrapper );
|
||||||
|
equal( node.$, $oldWrapper, 'this.$ references wrapper given to constructor' );
|
||||||
|
node.replaceDomWrapper( $newWrapper );
|
||||||
|
equal( node.$, $newWrapper, 'this.$ references new wrapper after replaceDomWrapper is called' );
|
||||||
|
equal( node.$.attr( 'class' ), 'test', 'old classes are added to new wrapper' );
|
||||||
|
equal( node.$.text(), 'hello', 'contents are added to new wrapper' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
test( 'onSplice', 3, function() {
|
||||||
|
var modelA = new ve.dm.BranchNodeStub(),
|
||||||
|
modelB = new ve.dm.BranchNodeStub(),
|
||||||
|
modelC = new ve.dm.BranchNodeStub(),
|
||||||
|
viewA = new ve.ce.BranchNodeStub( modelA );
|
||||||
|
|
||||||
|
modelA.splice( 0, 0, modelB, modelC );
|
||||||
|
equal( viewA.getChildren().length, 2 );
|
||||||
|
deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
||||||
|
deepEqual( viewA.getChildren()[1].getModel(), modelC );
|
||||||
} );
|
} );
|
||||||
*/
|
|
|
@ -9,6 +9,8 @@ ve.ce.LeafNodeStub = function( model ) {
|
||||||
|
|
||||||
ve.extendClass( ve.ce.LeafNodeStub, ve.ce.LeafNode );
|
ve.extendClass( ve.ce.LeafNodeStub, ve.ce.LeafNode );
|
||||||
|
|
||||||
|
ve.ce.factory.register( 'leaf-stub', ve.ce.BranchNodeStub );
|
||||||
|
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4,7 +4,7 @@ module( 've.dm.BranchNode' );
|
||||||
|
|
||||||
ve.dm.BranchNodeStub = function( children ) {
|
ve.dm.BranchNodeStub = function( children ) {
|
||||||
// Inheritance
|
// Inheritance
|
||||||
ve.dm.BranchNode.call( this, 'stub', children );
|
ve.dm.BranchNode.call( this, 'branch-stub', children );
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.extendClass( ve.dm.BranchNodeStub, ve.dm.BranchNode );
|
ve.extendClass( ve.dm.BranchNodeStub, ve.dm.BranchNode );
|
||||||
|
|
|
@ -4,7 +4,7 @@ module( 've.dm.LeafNode' );
|
||||||
|
|
||||||
ve.dm.LeafNodeStub = function() {
|
ve.dm.LeafNodeStub = function() {
|
||||||
// Inheritance
|
// Inheritance
|
||||||
ve.dm.LeafNode.call( this, 'stub' );
|
ve.dm.LeafNode.call( this, 'leaf-stub' );
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.extendClass( ve.dm.LeafNodeStub, ve.dm.LeafNode );
|
ve.extendClass( ve.dm.LeafNodeStub, ve.dm.LeafNode );
|
||||||
|
|
Loading…
Reference in a new issue