mediawiki-extensions-Visual.../modules/ve/test/ce/ve.ce.BranchNode.test.js
Trevor Parscal 8d33a3de0d Major Documentation Cleanup
* Made method descriptions imperative: "Do this" rather than "Does this"
* Changed use of "this object" to "the object" in method documentation
* Added missing documentation
* Fixed incorrect documentation
* Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console)
* Normalized use of package names throughout
* Normalized class descriptions
* Removed incorrect @abstract tags
* Added missing @method tags
* Lots of other minor cleanup

Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
2013-01-16 15:37:59 -08:00

93 lines
2.6 KiB
JavaScript

/*!
* VisualEditor ContentEditable BranchNode tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce.BranchNode' );
/* Stubs */
ve.ce.BranchNodeStub = function VeCeBranchNodeStub( model, $element ) {
// Parent constructor
ve.ce.BranchNode.call( this, 'branch-stub', model, $element );
};
ve.inheritClass( ve.ce.BranchNodeStub, ve.ce.BranchNode );
ve.ce.BranchNodeStub.rules = {
'canBeSplit': true
};
ve.ce.BranchNodeStub.domWrapperElementTypes = {
'a': 'a',
'b': 'b'
};
ve.ce.nodeFactory.register( 'branch-stub', ve.ce.BranchNodeStub );
/* Tests */
QUnit.test( 'canBeSplit', 1, function ( assert ) {
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
assert.equal( node.canBeSplit(), true );
} );
QUnit.test( 'canHaveChildren', 1, function ( assert ) {
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
assert.equal( node.canHaveChildren(), true );
} );
QUnit.test( 'canHaveGrandchildren', 1, function ( assert ) {
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
assert.equal( node.canHaveGrandchildren(), true );
} );
QUnit.test( 'updateDomWrapper', 3, function ( assert ) {
var attributes = { 'style': 'a' },
node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub( [], {
'type': 'branch-stub', 'attributes': attributes
} ) );
// Add classes and content to the node
node.$.addClass( 'test' ).text( 'hello' );
// Modify attribute
attributes.style = 'b';
node.updateDomWrapper( 'style' );
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' );
} );
QUnit.test( 'onSplice', 7, function ( assert ) {
var modelA = new ve.dm.BranchNodeStub(),
modelB = new ve.dm.BranchNodeStub(),
modelC = new ve.dm.BranchNodeStub(),
viewA = new ve.ce.BranchNodeStub( modelA );
// Insertion tests
modelA.splice( 0, 0, modelB, modelC );
assert.equal( viewA.getChildren().length, 2 );
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
assert.deepEqual( viewA.getChildren()[1].getModel(), modelC );
// Removal tests
modelA.splice( 0, 1 );
assert.equal( viewA.getChildren().length, 1 );
assert.deepEqual( viewA.getChildren()[0].getModel(), modelC );
// Removal and insertion tests
modelA.splice( 0, 1, modelB );
assert.equal( viewA.getChildren().length, 1 );
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
} );