mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 20:26:46 +00:00
a667425874
This is generally useful information, not only for dm Change-Id: I9511467285e9594b4a7aa659bf65bb0417da25a1
48 lines
1.2 KiB
JavaScript
48 lines
1.2 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.createNode( '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.createNode( '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'
|
|
);
|
|
} );
|