mediawiki-extensions-Visual.../modules/ve/test/ce/ve.ce.NodeFactory.test.js
Catrope 131b83831f Make stub nodes inherit correctly
Some of these stubs didn't inherit Node at all. Made them all inherit
LeafNode because their rules specify they can't have children.

Change-Id: If4afc8de350f67ee78a41307c426ec2aceeb884f
2013-01-11 20:18:10 -08:00

46 lines
1.1 KiB
JavaScript

/*!
* VisualEditor content editable NodeFactory tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.ce.NodeFactory' );
/* Stubs */
ve.ce.NodeFactoryNodeStub = function VeCeNodeFactoryNodeStub( a, b ) {
this.a = a;
this.b = b;
};
ve.inheritClass( ve.ce.NodeFactoryNodeStub, ve.ce.LeafNode );
ve.ce.NodeFactoryNodeStub.rules = {
'canBeSplit': false
};
/* Tests */
QUnit.test( 'canNodeBeSplit', 2, function ( assert ) {
var factory = new ve.ce.NodeFactory();
assert.throws( function () {
factory.canNodeBeSplit( 'node-factory-node-stub' );
},
Error,
'throws an exception when getting split rules for a node of an unregistered type'
);
factory.register( 'node-factory-node-stub', ve.ce.NodeFactoryNodeStub );
assert.strictEqual(
factory.canNodeBeSplit( 'node-factory-node-stub' ),
false,
'gets split rules for registered nodes'
);
} );
QUnit.test( 'initialization', 1, function ( assert ) {
assert.ok( ve.ce.nodeFactory instanceof ve.ce.NodeFactory, 'factory is initialized at ve.ce.nodeFactory' );
} );