Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/ce/ve.ce.AnnotationFactory.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable AnnotationFactory tests.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 QUnit.module( 've.ce.AnnotationFactory' );
8
9 /* Stubs */
10
11 ve.ce.AnnotationFactoryAnnotationStub = function VeCeAnnotationFactoryNodeStub() {};
12
13 OO.inheritClass( ve.ce.AnnotationFactoryAnnotationStub, ve.ce.Annotation );
14
15 ve.ce.AnnotationFactoryAnnotationStub.static.name = 'annotation-factory-annotation-stub';
16
17 ve.ce.AnnotationFactoryAnnotationStub.static.canBeActive = true;
18
19 ve.ce.AnnotationFactoryAnnotationStub.static.getDescription = function () {
20 return 'description';
21 };
22
23 ve.dm.AnnotationFactoryAnnotationStub = function VeDmAnnotationFactoryNodeStub() {};
24
25 OO.inheritClass( ve.dm.AnnotationFactoryAnnotationStub, ve.dm.Annotation );
26
27 ve.dm.AnnotationFactoryAnnotationStub.static.name = 'annotation-factory-annotation-stub';
28
29 /* Tests */
30
31 QUnit.test( 'canAnnotationBeActive/getDescription', ( assert ) => {
32 const factory = new ve.ce.AnnotationFactory();
33
34 assert.throws(
35 () => {
36 factory.canAnnotationBeActive( 'annotation-factory-annotation-stub' );
37 },
38 Error,
39 'throws an exception when calling canAnnotationBeActive on an unregistered type'
40 );
41
42 assert.throws(
43 () => {
44 factory.getDescription( new ve.dm.AnnotationFactoryAnnotationStub() );
45 },
46 Error,
47 'throws an exception when calling getDescription on an unregistered type'
48 );
49
50 factory.register( ve.ce.AnnotationFactoryAnnotationStub );
51
52 assert.strictEqual(
53 factory.canAnnotationBeActive( 'annotation-factory-annotation-stub' ),
54 true,
55 'canAnnotationBeActive'
56 );
57
58 assert.strictEqual(
59 factory.getDescription( new ve.dm.AnnotationFactoryAnnotationStub() ),
60 'description',
61 'getDescription'
62 );
63 } );
64
65 QUnit.test( 'initialization', ( assert ) => {
66 assert.true( ve.ce.annotationFactory instanceof ve.ce.AnnotationFactory, 'factory is initialized at ve.ce.annotationFactory' );
67 } );