2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor content editable BranchNode 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.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-07-10 19:46:08 +00:00
|
|
|
test( 'canBeSplit', 1, function( assert ) {
|
2012-05-22 00:39:03 +00:00
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( node.canBeSplit(), true );
|
2012-05-22 00:39:03 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'canHaveChildren', 1, function( assert ) {
|
2012-05-05 00:50:54 +00:00
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( node.canHaveChildren(), true );
|
2012-05-05 00:50:54 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'canHaveGrandchildren', 1, function( assert ) {
|
2012-05-05 00:50:54 +00:00
|
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( node.canHaveGrandchildren(), true );
|
2012-05-05 00:50:54 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'updateDomWrapper', 3, function( assert ) {
|
2012-05-04 20:31:14 +00:00
|
|
|
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' );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( node.$.get( 0 ).nodeName.toLowerCase(), 'b', 'DOM element type gets converted' );
|
|
|
|
assert.equal( node.$.hasClass( 'test' ), true, 'old classes are added to new wrapper' );
|
|
|
|
assert.equal( node.$.text(), 'hello', 'contents are added to new wrapper' );
|
2012-05-02 20:58:50 +00:00
|
|
|
} );
|
|
|
|
|
2012-07-10 19:46:08 +00:00
|
|
|
test( 'onSplice', 7, function( assert ) {
|
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 );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( viewA.getChildren().length, 2 );
|
|
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
|
|
|
assert.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 );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( viewA.getChildren().length, 1 );
|
|
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelC );
|
2012-05-02 21:59:07 +00:00
|
|
|
// Removal and insertion tests
|
|
|
|
modelA.splice( 0, 1, modelB );
|
2012-07-10 19:46:08 +00:00
|
|
|
assert.equal( viewA.getChildren().length, 1 );
|
|
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
2012-05-01 00:04:49 +00:00
|
|
|
} );
|