mediawiki-extensions-Visual.../tests/ve2/dm/ve.dm.NodeFactory.test.js
Trevor Parscal dc27d8acb4 Refactored dom wrapper functionality in ce nodes
* Moved implementation of getting and updating a DOM wrapper to ve.ce.BranchNode
* Updated ve.ce.BranchNode tests
* Renamed ve.NodeFactory.createNode to ve.NodeFactory.create
* Added  ve.NodeFactory.lookup which gets the constructor of a type
* Added attribute pass-through to ve.dm.BranchNodeStub

Change-Id: I8f5b7d3d3ae616cc5f39828b24b655163d782ae5
2012-05-04 13:31:14 -07:00

52 lines
1.3 KiB
JavaScript

module( 've.dm.NodeFactory' );
/* Stubs */
ve.dm.NodeFactoryNodeStub = function( a, b ) {
this.a = a;
this.b = b;
};
ve.dm.NodeFactoryNodeStub.rules = {
'childNodeTypes': ['a', 'b'],
'parentNodeTypes': ['c', 'd']
};
/* Tests */
test( 'getChildNodeTypes', 2, function() {
var factory = new ve.dm.NodeFactory();
raises( function() {
factory.create( 'stub', 23, { 'bar': 'baz' } );
},
/^Unknown node type: stub$/,
'throws an exception when getting allowed child nodes of a node of an unregistered type'
);
factory.register( 'stub', ve.dm.NodeFactoryNodeStub );
deepEqual(
factory.getChildNodeTypes( 'stub' ),
['a', 'b'],
'gets child type rules for registered nodes'
);
} );
test( 'getParentNodeTypes', 2, function() {
var factory = new ve.dm.NodeFactory();
raises( function() {
factory.create( 'stub', 23, { 'bar': 'baz' } );
},
/^Unknown node type: stub$/,
'throws an exception when getting allowed parent nodes of a node of an unregistered type'
);
factory.register( 'stub', ve.dm.NodeFactoryNodeStub );
deepEqual(
factory.getParentNodeTypes( 'stub' ),
['c', 'd'],
'gets parent type rules for registered nodes'
);
} );
test( 'initialization', 1, function() {
ok( ve.dm.factory instanceof ve.dm.NodeFactory, 'factory is initialized at ve.dm.factory' );
} );