Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable Node tests.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 QUnit.module( 've.ce.Node' );
8
9 /* Stubs */
10
11 ve.ce.NodeStub = function VeCeNodeStub() {
12 // Parent constructor
13 ve.ce.NodeStub.super.apply( this, arguments );
14 };
15
16 OO.inheritClass( ve.ce.NodeStub, ve.ce.Node );
17
18 ve.ce.NodeStub.static.name = 'stub';
19
20 ve.ce.nodeFactory.register( ve.ce.NodeStub );
21
22 /* Tests */
23
24 QUnit.test( 'getModel', ( assert ) => {
25 const model = new ve.dm.NodeStub(),
26 view = new ve.ce.NodeStub( model );
27 assert.strictEqual( view.getModel(), model, 'returns reference to model given to constructor' );
28 } );
29
30 QUnit.test( 'getParent', ( assert ) => {
31 const a = new ve.ce.NodeStub( new ve.dm.NodeStub() );
32 assert.strictEqual( a.getParent(), null, 'returns null if not attached' );
33 } );
34
35 QUnit.test( 'attach', ( assert ) => {
36 const a = new ve.ce.NodeStub( new ve.dm.NodeStub() ),
37 b = new ve.ce.NodeStub( new ve.dm.NodeStub() );
38 a.on( 'attach', ( parent ) => {
39 assert.strictEqual( parent, b, 'attach event is called with parent as first argument' );
40 } );
41 a.attach( b );
42 assert.strictEqual( a.getParent(), b, 'parent is set to given object after attach' );
43 } );
44
45 QUnit.test( 'detach', ( assert ) => {
46 const a = new ve.ce.NodeStub( new ve.dm.NodeStub() ),
47 b = new ve.ce.NodeStub( new ve.dm.NodeStub() );
48 a.attach( b );
49 a.on( 'detach', ( parent ) => {
50 assert.strictEqual( parent, b, 'detach event is called with parent as first argument' );
51 } );
52 a.detach();
53 assert.strictEqual( a.getParent(), null, 'parent is set null after detach' );
54 } );