2012-04-30 22:42:36 +00:00
|
|
|
module( 've.dm.NodeFactory' );
|
|
|
|
|
|
|
|
/* Stubs */
|
|
|
|
|
|
|
|
ve.dm.NodeFactoryNodeStub = function( a, b ) {
|
|
|
|
this.a = a;
|
|
|
|
this.b = b;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.NodeFactoryNodeStub.rules = {
|
2012-05-22 00:39:03 +00:00
|
|
|
'isContent': true,
|
|
|
|
'canContainContent': false,
|
2012-05-10 04:11:09 +00:00
|
|
|
'isWrapped': true,
|
2012-05-22 00:39:03 +00:00
|
|
|
'childNodeTypes': [],
|
|
|
|
'parentNodeTypes': null
|
2012-04-30 22:42:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
|
|
|
test( 'getChildNodeTypes', 2, function() {
|
|
|
|
var factory = new ve.dm.NodeFactory();
|
|
|
|
raises( function() {
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.create( 'node-factory-node-stub', 23, { 'bar': 'baz' } );
|
2012-04-30 22:42:36 +00:00
|
|
|
},
|
2012-05-22 00:39:03 +00:00
|
|
|
/^Unknown node type: node-factory-node-stub$/,
|
2012-04-30 22:42:36 +00:00
|
|
|
'throws an exception when getting allowed child nodes of a node of an unregistered type'
|
|
|
|
);
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.register( 'node-factory-node-stub', ve.dm.NodeFactoryNodeStub );
|
2012-04-30 22:42:36 +00:00
|
|
|
deepEqual(
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.getChildNodeTypes( 'node-factory-node-stub' ),
|
|
|
|
[],
|
2012-04-30 22:42:36 +00:00
|
|
|
'gets child type rules for registered nodes'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'getParentNodeTypes', 2, function() {
|
|
|
|
var factory = new ve.dm.NodeFactory();
|
|
|
|
raises( function() {
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.create( 'node-factory-node-stub', 23, { 'bar': 'baz' } );
|
2012-04-30 22:42:36 +00:00
|
|
|
},
|
2012-05-22 00:39:03 +00:00
|
|
|
/^Unknown node type: node-factory-node-stub$/,
|
2012-04-30 22:42:36 +00:00
|
|
|
'throws an exception when getting allowed parent nodes of a node of an unregistered type'
|
|
|
|
);
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.register( 'node-factory-node-stub', ve.dm.NodeFactoryNodeStub );
|
2012-04-30 22:42:36 +00:00
|
|
|
deepEqual(
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.getParentNodeTypes( 'node-factory-node-stub' ),
|
|
|
|
null,
|
2012-04-30 22:42:36 +00:00
|
|
|
'gets parent type rules for registered nodes'
|
|
|
|
);
|
|
|
|
} );
|
2012-04-30 23:36:02 +00:00
|
|
|
|
2012-05-10 04:11:09 +00:00
|
|
|
test( 'canNodeHaveChildren', 2, function() {
|
|
|
|
var factory = new ve.dm.NodeFactory();
|
|
|
|
raises( function() {
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.create( 'node-factory-node-stub', 23, { 'bar': 'baz' } );
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
2012-05-22 00:39:03 +00:00
|
|
|
/^Unknown node type: node-factory-node-stub$/,
|
2012-05-10 04:11:09 +00:00
|
|
|
'throws an exception when checking if a node of an unregistered type can have children'
|
|
|
|
);
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.register( 'node-factory-node-stub', ve.dm.NodeFactoryNodeStub );
|
2012-05-10 04:11:09 +00:00
|
|
|
strictEqual(
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.canNodeHaveChildren( 'node-factory-node-stub' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
false,
|
|
|
|
'gets child rules for registered nodes'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'canNodeHaveGrandchildren', 2, function() {
|
|
|
|
var factory = new ve.dm.NodeFactory();
|
|
|
|
raises( function() {
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.create( 'node-factory-node-stub', 23, { 'bar': 'baz' } );
|
2012-05-10 04:11:09 +00:00
|
|
|
},
|
2012-05-22 00:39:03 +00:00
|
|
|
/^Unknown node type: node-factory-node-stub$/,
|
2012-05-10 04:11:09 +00:00
|
|
|
'throws an exception when checking if a node of an unregistered type can have grandchildren'
|
|
|
|
);
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.register( 'node-factory-node-stub', ve.dm.NodeFactoryNodeStub );
|
2012-05-10 04:11:09 +00:00
|
|
|
strictEqual(
|
2012-05-22 00:39:03 +00:00
|
|
|
factory.canNodeHaveGrandchildren( 'node-factory-node-stub' ),
|
2012-05-10 04:11:09 +00:00
|
|
|
false,
|
|
|
|
'gets grandchild rules for registered nodes'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2012-04-30 23:36:02 +00:00
|
|
|
test( 'initialization', 1, function() {
|
2012-05-31 22:20:58 +00:00
|
|
|
ok( ve.dm.nodeFactory instanceof ve.dm.NodeFactory, 'factory is initialized at ve.dm.nodeFactory' );
|
2012-04-30 23:36:02 +00:00
|
|
|
} );
|