| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
QUnit.module( 've.dm.NodeFactory' ); |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
ve.dm.NodeFactoryNodeStub = function VeDmNodeFactoryNodeStub() {}; |
| 12 |
|
| 13 |
OO.inheritClass( ve.dm.NodeFactoryNodeStub, ve.dm.LeafNode ); |
| 14 |
|
| 15 |
ve.dm.NodeFactoryNodeStub.static.name = 'node-factory-node-stub'; |
| 16 |
|
| 17 |
ve.dm.NodeFactoryNodeStub.static.isContent = true; |
| 18 |
|
| 19 |
ve.dm.NodeFactoryNodeStub.static.matchTagNames = []; |
| 20 |
|
| 21 |
ve.dm.NodeFactoryNodeStub.static.disallowedAnnotationTypes = [ 'link', 'textStyle/italic' ]; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
QUnit.test( 'getChildNodeTypes', ( assert ) => { |
| 26 |
const factory = new ve.dm.NodeFactory(); |
| 27 |
assert.throws( |
| 28 |
() => { |
| 29 |
factory.getChildNodeTypes( 'node-factory-node-stub', 23, { bar: 'baz' } ); |
| 30 |
}, |
| 31 |
Error, |
| 32 |
'throws an exception when getting allowed child nodes of a node of an unregistered type' |
| 33 |
); |
| 34 |
factory.register( ve.dm.NodeFactoryNodeStub ); |
| 35 |
assert.deepEqual( |
| 36 |
factory.getChildNodeTypes( 'node-factory-node-stub' ), |
| 37 |
[], |
| 38 |
'gets child type rules for registered nodes' |
| 39 |
); |
| 40 |
} ); |
| 41 |
|
| 42 |
QUnit.test( 'getParentNodeTypes', ( assert ) => { |
| 43 |
const factory = new ve.dm.NodeFactory(); |
| 44 |
assert.throws( |
| 45 |
() => { |
| 46 |
factory.getParentNodeTypes( 'node-factory-node-stub', 23, { bar: 'baz' } ); |
| 47 |
}, |
| 48 |
Error, |
| 49 |
'throws an exception when getting allowed parent nodes of a node of an unregistered type' |
| 50 |
); |
| 51 |
factory.register( ve.dm.NodeFactoryNodeStub ); |
| 52 |
assert.strictEqual( |
| 53 |
factory.getParentNodeTypes( 'node-factory-node-stub' ), |
| 54 |
null, |
| 55 |
'gets parent type rules for registered nodes' |
| 56 |
); |
| 57 |
} ); |
| 58 |
|
| 59 |
QUnit.test( 'canNodeHaveChildren', ( assert ) => { |
| 60 |
const factory = new ve.dm.NodeFactory(); |
| 61 |
assert.throws( |
| 62 |
() => { |
| 63 |
factory.canNodeHaveChildren( 'node-factory-node-stub', 23, { bar: 'baz' } ); |
| 64 |
}, |
| 65 |
Error, |
| 66 |
'throws an exception when checking if a node of an unregistered type can have children' |
| 67 |
); |
| 68 |
factory.register( ve.dm.NodeFactoryNodeStub ); |
| 69 |
assert.strictEqual( |
| 70 |
factory.canNodeHaveChildren( 'node-factory-node-stub' ), |
| 71 |
false, |
| 72 |
'gets child rules for registered nodes' |
| 73 |
); |
| 74 |
} ); |
| 75 |
|
| 76 |
QUnit.test( 'canNodeTakeAnnotation', ( assert ) => { |
| 77 |
const factory = new ve.dm.NodeFactory(); |
| 78 |
assert.throws( |
| 79 |
() => { |
| 80 |
factory.canNodeTakeAnnotation( 'node-factory-node-stub', 23, { bar: 'baz' } ); |
| 81 |
}, |
| 82 |
Error, |
| 83 |
'throws an exception when checking if a node of an unregistered type can have children' |
| 84 |
); |
| 85 |
factory.register( ve.dm.NodeFactoryNodeStub ); |
| 86 |
assert.strictEqual( |
| 87 |
factory.canNodeTakeAnnotation( 'node-factory-node-stub', new ve.dm.LinkAnnotation() ), |
| 88 |
false, |
| 89 |
'can\'t take link annotation' |
| 90 |
); |
| 91 |
assert.strictEqual( |
| 92 |
factory.canNodeTakeAnnotation( 'node-factory-node-stub', new ve.dm.ItalicAnnotation() ), |
| 93 |
false, |
| 94 |
'can\'t take italic annotation' |
| 95 |
); |
| 96 |
assert.strictEqual( |
| 97 |
factory.canNodeTakeAnnotation( 'node-factory-node-stub', new ve.dm.BoldAnnotation() ), |
| 98 |
true, |
| 99 |
'can take bold annotation' |
| 100 |
); |
| 101 |
} ); |
| 102 |
|
| 103 |
QUnit.test( 'canNodeHaveChildrenNotContent', ( assert ) => { |
| 104 |
const factory = new ve.dm.NodeFactory(); |
| 105 |
assert.throws( |
| 106 |
() => { |
| 107 |
factory.canNodeHaveChildrenNotContent( 'node-factory-node-stub', 23, { bar: 'baz' } ); |
| 108 |
}, |
| 109 |
Error, |
| 110 |
'throws an exception when checking if a node of an unregistered type can have grandchildren' |
| 111 |
); |
| 112 |
factory.register( ve.dm.NodeFactoryNodeStub ); |
| 113 |
assert.strictEqual( |
| 114 |
factory.canNodeHaveChildrenNotContent( 'node-factory-node-stub' ), |
| 115 |
false, |
| 116 |
'gets grandchild rules for registered nodes' |
| 117 |
); |
| 118 |
} ); |
| 119 |
|
| 120 |
QUnit.test( 'initialization', ( assert ) => { |
| 121 |
assert.true( ve.dm.nodeFactory instanceof ve.dm.NodeFactory, 'factory is initialized at ve.dm.nodeFactory' ); |
| 122 |
} ); |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|