This repository was archived by the owner on Dec 3, 2020. It is now read-only.
forked from evilfer/react-phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-init-adapter-test.js
More file actions
126 lines (99 loc) · 4.5 KB
/
node-init-adapter-test.js
File metadata and controls
126 lines (99 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"use strict";
var chai = require("chai");
var sinon = require("sinon");
var sinonChai = require("sinon-chai");
var expect = chai.expect;
chai.use(sinonChai);
var createInitmpl = require('../../src/node-management/node-init-adapter');
var createTreeImpl = require('../../src/node-management/node-tree-adapter');
describe('node init adapter', function () {
var nodeTypes, impl, treeImpl;
beforeEach(function () {
nodeTypes = {
a: {
init: sinon.spy(),
onChildrenInit: sinon.spy()
},
b: {
init: sinon.spy(),
onChildrenInit: sinon.spy()
},
c: {
init: sinon.spy(),
onChildrenInit: sinon.spy()
}
};
impl = createInitmpl(nodeTypes);
treeImpl = createTreeImpl(impl);
});
it('should invoke node init by default', function () {
var a = treeImpl.components.mount(1, 'a', {}, null);
expect(nodeTypes.a.init).to.have.been.calledOnce;
expect(nodeTypes.a.init).to.have.been.calledWith(a);
});
it('should invoke node init on children by default', function () {
var a = treeImpl.components.mount(1, 'a', {}, null),
b = treeImpl.components.mount(2, 'a', {}, a);
expect(nodeTypes.a.init).to.have.been.calledTwice;
expect(nodeTypes.a.init.getCall(0)).to.have.been.calledWith(a);
expect(nodeTypes.a.init.getCall(1)).to.have.been.calledWith(b);
});
it('should invoke mount children', function () {
var a = treeImpl.components.mount(1, 'a', {}, null),
b = treeImpl.components.mount(2, 'a', {}, a);
treeImpl.components.childrenMount(a);
expect(nodeTypes.a.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.a.onChildrenInit.getCall(0)).to.have.been.calledWith(a);
});
it('should not init children for deferred parents', function () {
nodeTypes.a.deferredInit = true;
var a = treeImpl.components.mount(1, 'a', {}, null),
b = treeImpl.components.mount(2, 'b', {}, a);
treeImpl.components.childrenMount(a);
expect(nodeTypes.a.init).not.to.have.been.calledOnce;
expect(nodeTypes.a.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.b.init).not.to.have.been.called;
});
it('should not init children for deferred parents', function () {
nodeTypes.a.deferredInit = true;
var a = treeImpl.components.mount(1, 'a', {}, null),
b = treeImpl.components.mount(2, 'b', {}, a);
treeImpl.components.childrenMount(a);
expect(nodeTypes.a.init).not.to.have.been.calledOnce;
expect(nodeTypes.a.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.b.init).not.to.have.been.called;
expect(a.initialized).to.equal(true);
expect(b.initialized).to.equal(false);
});
it('should init children for deferred parents on request', function () {
nodeTypes.a.deferredInit = true;
nodeTypes.a.onChildrenInit = sinon.spy(function (node, tree, implMethods) {
implMethods.initChildren(node, tree);
});
var a = treeImpl.components.mount(1, 'a', {}, null),
b = treeImpl.components.mount(2, 'b', {}, a);
treeImpl.components.childrenMount(a);
expect(nodeTypes.a.init).not.to.have.been.calledOnce;
expect(nodeTypes.a.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.b.init).to.have.been.calledOnce;
});
it('should not init nested children by default, when deferred', function () {
nodeTypes.a.deferredInit = true;
nodeTypes.a.onChildrenInit = sinon.spy(function (node, tree, implMethods) {
implMethods.initChildren(node, tree);
});
nodeTypes.b.deferredInit = true;
nodeTypes.b.onChildrenInit = sinon.spy(function (node, tree, implMethods) {
});
var a1 = treeImpl.components.mount(1, 'a', {}, null),
a2 = treeImpl.components.mount(2, 'b', {}, a1),
b = treeImpl.components.mount(3, 'c', {}, a2);
treeImpl.components.childrenMount(a1);
expect(nodeTypes.a.init).not.to.have.been.called;
expect(nodeTypes.a.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.b.init).not.to.have.been.called;
expect(nodeTypes.b.onChildrenInit).to.have.been.calledOnce;
expect(nodeTypes.b.init).not.to.have.been.calledOnce;
});
it('should filter children on deferred init children');
});