@lightningjs/blits 1.30.0 → 1.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +7 -7
- package/.eslintignore +1 -1
- package/.eslintrc.cjs +65 -65
- package/.github/workflows/comment-lint-results.yml +124 -124
- package/.github/workflows/comment-test-results.yml +108 -108
- package/.github/workflows/deploy-docs.yml +27 -27
- package/.github/workflows/run-blits-tests.yml +141 -141
- package/.github/workflows/run-lint.yml +127 -127
- package/.husky/pre-commit +1 -1
- package/.vscode/extensions.json +7 -7
- package/.vscode/settings.json +9 -9
- package/CHANGELOG.md +1019 -1005
- package/COPYING +1 -0
- package/LICENSE +202 -202
- package/NOTICE +12 -12
- package/README.md +33 -33
- package/bin/index.js +8 -8
- package/blits.d.ts +6 -6
- package/docs/README.md +19 -19
- package/docs/_sidebar.md +37 -37
- package/docs/built-in/directives.md +50 -50
- package/docs/built-in/for-loop.md +203 -203
- package/docs/built-in/layout.md +168 -168
- package/docs/components/component_state.md +90 -90
- package/docs/components/computed_properties.md +45 -45
- package/docs/components/lifecycle_events.md +42 -42
- package/docs/components/methods.md +45 -45
- package/docs/components/props.md +56 -56
- package/docs/components/user_input.md +186 -186
- package/docs/components/utility_methods.md +320 -320
- package/docs/components/watchers.md +34 -34
- package/docs/essentials/application_root.md +19 -19
- package/docs/essentials/components.md +68 -68
- package/docs/essentials/displaying_images.md +67 -67
- package/docs/essentials/displaying_text.md +135 -135
- package/docs/essentials/element_attributes.md +195 -195
- package/docs/essentials/settings.md +117 -117
- package/docs/essentials/template_syntax.md +83 -83
- package/docs/getting_started/file_structure.md +58 -58
- package/docs/getting_started/getting_started.md +45 -45
- package/docs/getting_started/intro.md +20 -20
- package/docs/index.html +47 -47
- package/docs/performance/lazy-loading.md +161 -161
- package/docs/plugins/global_app_state.md +98 -98
- package/docs/plugins/language.md +172 -172
- package/docs/plugins/text-to-speech-announcer.md +119 -119
- package/docs/plugins/theme.md +176 -176
- package/docs/router/basics.md +175 -175
- package/docs/router/hooks.md +70 -70
- package/docs/router/transitions.md +146 -146
- package/docs/sidebar.json +171 -171
- package/docs/transitions_animations/transitions.md +150 -150
- package/index.d.ts +1099 -1099
- package/index.js +28 -28
- package/jsconfig.json +12 -12
- package/package.json +56 -56
- package/public/assets/fps_sprite.base64.js +1 -1
- package/scripts/postpublish.js +59 -59
- package/scripts/prepublishOnly.js +84 -84
- package/scripts/prepush.js +78 -78
- package/src/announcer/announcer.js +162 -162
- package/src/announcer/speechSynthesis.js +107 -107
- package/src/application.js +100 -100
- package/src/component/base/announcer.js +27 -27
- package/src/component/base/events.js +69 -69
- package/src/component/base/index.js +33 -33
- package/src/component/base/methods.js +244 -244
- package/src/component/base/router.js +41 -41
- package/src/component/base/timeouts_intervals.js +99 -99
- package/src/component/base/utils.js +72 -72
- package/src/component/setup/computed.js +48 -48
- package/src/component/setup/index.js +62 -62
- package/src/component/setup/input.js +30 -30
- package/src/component/setup/methods.js +37 -37
- package/src/component/setup/props.js +62 -62
- package/src/component/setup/props.test.js +238 -238
- package/src/component/setup/routes.js +42 -42
- package/src/component/setup/state.js +59 -59
- package/src/component/setup/watch.js +35 -35
- package/src/component.js +437 -437
- package/src/component.test.js +388 -388
- package/src/components/Circle.js +73 -73
- package/src/components/Circle.orig.js +31 -31
- package/src/components/FPScounter.js +1510 -1510
- package/src/components/FPScounter.orig.js +121 -121
- package/src/components/RouterView.js +81 -81
- package/src/components/RouterView.orig.js +54 -54
- package/src/components/Sprite.js +94 -94
- package/src/components/Sprite.orig.js +58 -58
- package/src/components/index.js +28 -28
- package/src/components/index.orig.js +28 -28
- package/src/constants.js +21 -21
- package/src/engine.js +1 -1
- package/src/engines/L3/element.js +744 -744
- package/src/engines/L3/element.test.js +579 -579
- package/src/engines/L3/fontLoader.js +38 -38
- package/src/engines/L3/index.js +7 -7
- package/src/engines/L3/launch.js +123 -123
- package/src/engines/L3/shaderLoader.js +12 -12
- package/src/engines/index.js +1 -1
- package/src/focus.js +90 -90
- package/src/helpers/deepEqualArray.js +50 -50
- package/src/helpers/deepEqualArray.test.js +127 -127
- package/src/helpers/fetchJson.js +34 -34
- package/src/helpers/sequence.js +26 -26
- package/src/launch.js +123 -123
- package/src/lib/blitsfileconverter/blitsfileconverter.js +52 -52
- package/src/lib/codegenerator/generator.js +788 -788
- package/src/lib/codegenerator/generator.test.js +3801 -3801
- package/src/lib/colors/colors.js +92 -92
- package/src/lib/colors/colors.test.js +290 -290
- package/src/lib/colors/htmlColors.js +168 -168
- package/src/lib/componentId.js +49 -49
- package/src/lib/componentId.test.js +84 -84
- package/src/lib/eventListeners.js +123 -123
- package/src/lib/eventListeners.test.js +236 -236
- package/src/lib/hooks.js +59 -59
- package/src/lib/lifecycle.js +85 -85
- package/src/lib/log.js +117 -117
- package/src/lib/precompiler/precompiler.js +73 -73
- package/src/lib/reactivity/effect.js +93 -93
- package/src/lib/reactivity/effect.test.js +35 -35
- package/src/lib/reactivity/reactive.js +208 -208
- package/src/lib/reactivity/reactive.test.js +27 -27
- package/src/lib/reactivityguard/computedprops.js +218 -218
- package/src/lib/symbols.js +108 -108
- package/src/lib/templateparser/parser.js +386 -386
- package/src/lib/templateparser/parser.test.js +1411 -1411
- package/src/lib/utils.js +27 -27
- package/src/plugin.js +27 -27
- package/src/plugins/appstate.js +26 -26
- package/src/plugins/index.js +20 -20
- package/src/plugins/language.js +152 -152
- package/src/plugins/log.js +25 -25
- package/src/plugins/theme.js +94 -94
- package/src/router/router.js +514 -514
- package/src/router/router.test.js +473 -473
- package/src/router/transitions/fadeIn.js +27 -27
- package/src/router/transitions/fadeInOut.js +33 -33
- package/src/router/transitions/index.js +21 -21
- package/src/router/transitions/slideIn.js +28 -28
- package/src/router/transitions/slideInOut.js +33 -33
- package/src/settings.js +40 -40
- package/vite/blitsFileConverter.js +67 -67
- package/vite/index.js +28 -28
- package/vite/msdfGenerator.js +269 -269
- package/vite/preCompiler.js +42 -42
- package/vite/reactivityGuard.js +45 -45
- package/vscode/data/template-attributes.json +589 -589
|
@@ -1,579 +1,579 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2023 Comcast Cable Communications Management, LLC
|
|
3
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License.
|
|
5
|
-
* You may obtain a copy of the License at
|
|
6
|
-
*
|
|
7
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
*
|
|
9
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
* See the License for the specific language governing permissions and
|
|
13
|
-
* limitations under the License.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import test from 'tape'
|
|
19
|
-
import element from './element.js'
|
|
20
|
-
import { renderer } from './launch.js'
|
|
21
|
-
import { EventEmitter } from 'node:events'
|
|
22
|
-
import { initLog } from '../../lib/log.js'
|
|
23
|
-
import symbols from '../../lib/symbols.js'
|
|
24
|
-
|
|
25
|
-
initLog()
|
|
26
|
-
|
|
27
|
-
let elementRef
|
|
28
|
-
|
|
29
|
-
test('Type', (assert) => {
|
|
30
|
-
assert.ok(element instanceof Function, 'Element should be a factory function')
|
|
31
|
-
assert.end()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('Destroy', (assert) => {
|
|
35
|
-
const el = element({}, {})
|
|
36
|
-
el.node = { destroy: () => {} }
|
|
37
|
-
const capture = assert.capture(el.node, 'destroy')
|
|
38
|
-
|
|
39
|
-
el.destroy()
|
|
40
|
-
|
|
41
|
-
const calls = capture()
|
|
42
|
-
assert.ok(calls.length > 0, 'Node destroy should be invoked')
|
|
43
|
-
assert.end()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('NodeId', (assert) => {
|
|
47
|
-
const el = element({}, {})
|
|
48
|
-
el.node = { id: 123 }
|
|
49
|
-
|
|
50
|
-
const result = el.nodeId
|
|
51
|
-
|
|
52
|
-
assert.equal(result, 123, 'NodeId should be correct')
|
|
53
|
-
assert.end()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('Ref', (assert) => {
|
|
57
|
-
const el = element({}, {})
|
|
58
|
-
el.props = { ref: 123 }
|
|
59
|
-
|
|
60
|
-
const result = el.ref
|
|
61
|
-
|
|
62
|
-
assert.equal(result, 123, 'Ref should be correct')
|
|
63
|
-
assert.end()
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('Parent', (assert) => {
|
|
67
|
-
const el = element({}, {})
|
|
68
|
-
el.node = { parent: 'foo' }
|
|
69
|
-
|
|
70
|
-
const result = el.parent
|
|
71
|
-
|
|
72
|
-
assert.equal(result, 'foo', 'Parent should be correct')
|
|
73
|
-
assert.end()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('Children', (assert) => {
|
|
77
|
-
const el = element({}, {})
|
|
78
|
-
el.node = 'foo'
|
|
79
|
-
el.component[symbols.getChildren] = () => [
|
|
80
|
-
{ id: 0, parent: 'bar' },
|
|
81
|
-
{ id: 1, parent: 'foo' },
|
|
82
|
-
{ id: 2, parent: undefined },
|
|
83
|
-
{ id: 3, parent: 0 },
|
|
84
|
-
{ id: 4, parent: 'foo' },
|
|
85
|
-
]
|
|
86
|
-
|
|
87
|
-
const result = el.children
|
|
88
|
-
|
|
89
|
-
assert.equal(result.length, 2, 'Children amount should be correct')
|
|
90
|
-
assert.deepEqual(
|
|
91
|
-
result.map((c) => c.id),
|
|
92
|
-
[1, 4],
|
|
93
|
-
'Children should be correct'
|
|
94
|
-
)
|
|
95
|
-
assert.end()
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test('Element - Set `w` property', (assert) => {
|
|
99
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
100
|
-
const el = createElement()
|
|
101
|
-
|
|
102
|
-
el.set('w', 100)
|
|
103
|
-
|
|
104
|
-
assert.equal(el.node['width'], 100, 'Node width parameter should be set')
|
|
105
|
-
assert.equal(el.props.props['width'], 100, 'Props width parameter should be set')
|
|
106
|
-
assert.equal(el.props.raw['w'], 100, "Props' raw map entry should be added")
|
|
107
|
-
assert.end()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
test('Element- Set `w` property in percentage', (assert) => {
|
|
111
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
112
|
-
const el = createElement()
|
|
113
|
-
|
|
114
|
-
el.set('w', '50%')
|
|
115
|
-
|
|
116
|
-
assert.equal(el.node['width'], 960, 'Node width parameter should be set to 960')
|
|
117
|
-
assert.equal(el.props.props['width'], 960, 'Props width parameter should be set')
|
|
118
|
-
assert.equal(el.props.raw['w'], '50%', "Props' raw map entry should be added")
|
|
119
|
-
|
|
120
|
-
assert.end()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('Element - Set `h` property', (assert) => {
|
|
124
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
125
|
-
const el = createElement()
|
|
126
|
-
|
|
127
|
-
el.set('h', 100)
|
|
128
|
-
|
|
129
|
-
assert.equal(el.node['height'], 100, 'Node height parameter should be set')
|
|
130
|
-
assert.equal(el.props.props['height'], 100, 'Props height parameter should be set')
|
|
131
|
-
assert.equal(el.props.raw['h'], 100, "Props' raw map entry should be added")
|
|
132
|
-
assert.end()
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('Element- Set `h` property in percentage', (assert) => {
|
|
136
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
137
|
-
const el = createElement()
|
|
138
|
-
|
|
139
|
-
el.set('h', '50%')
|
|
140
|
-
|
|
141
|
-
assert.equal(el.node['height'], 540, 'Node width parameter should be set to 540')
|
|
142
|
-
assert.equal(el.props.props['height'], 540, 'Props width parameter should be set')
|
|
143
|
-
assert.equal(el.props.raw['h'], '50%', "Props' raw map entry should be added")
|
|
144
|
-
|
|
145
|
-
assert.end()
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
test('Element - Set `x` property', (assert) => {
|
|
149
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
150
|
-
const el = createElement()
|
|
151
|
-
|
|
152
|
-
el.set('x', 100)
|
|
153
|
-
|
|
154
|
-
assert.equal(el.node['x'], 100, 'Node x parameter should be set')
|
|
155
|
-
assert.equal(el.props.props['x'], 100, 'Props x parameter should be set')
|
|
156
|
-
assert.equal(el.props.raw['x'], 100, "Props' raw map entry should be added")
|
|
157
|
-
assert.end()
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('Element- Set `x` property in percentage', (assert) => {
|
|
161
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
162
|
-
const el = createElement()
|
|
163
|
-
|
|
164
|
-
el.set('x', '50%')
|
|
165
|
-
|
|
166
|
-
assert.equal(el.node['x'], 960, 'Node x parameter should be set to 960')
|
|
167
|
-
assert.equal(el.props.props['x'], 960, 'Props x parameter should be set')
|
|
168
|
-
assert.equal(el.props.raw['x'], '50%', "Props' raw map entry should be added")
|
|
169
|
-
|
|
170
|
-
assert.end()
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
test('Element - Set `y` property', (assert) => {
|
|
174
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
175
|
-
const el = createElement()
|
|
176
|
-
|
|
177
|
-
el.set('y', 100)
|
|
178
|
-
|
|
179
|
-
assert.equal(el.node['y'], 100, 'Node y parameter should be set')
|
|
180
|
-
assert.equal(el.props.props['y'], 100, 'Props y parameter should be set')
|
|
181
|
-
assert.equal(el.props.raw['y'], 100, "Props' raw map entry should be added")
|
|
182
|
-
assert.end()
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
test('Element- Set `y` property in percentage', (assert) => {
|
|
186
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
187
|
-
const el = createElement()
|
|
188
|
-
|
|
189
|
-
el.set('y', '50%')
|
|
190
|
-
|
|
191
|
-
assert.equal(el.node['y'], 540, 'Node y parameter should be set to 540')
|
|
192
|
-
assert.equal(el.props.props['y'], 540, 'Props y parameter should be set')
|
|
193
|
-
assert.equal(el.props.raw['y'], '50%', "Props' raw map entry should be added")
|
|
194
|
-
|
|
195
|
-
assert.end()
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
test('Element - Set `mount` property', (assert) => {
|
|
199
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
200
|
-
const el = createElement()
|
|
201
|
-
const value = '{ x: 10, y: 20 }'
|
|
202
|
-
|
|
203
|
-
el.set('mount', value)
|
|
204
|
-
|
|
205
|
-
assert.equal(el.node['mountX'], 10, 'Node mountX parameter should be set')
|
|
206
|
-
assert.equal(el.node['mountY'], 20, 'Node mountY parameter should be set')
|
|
207
|
-
assert.equal(el.props.props['mountX'], 10, 'Props mountX parameter should be set')
|
|
208
|
-
assert.equal(el.props.props['mountY'], 20, 'Props mountY parameter should be set')
|
|
209
|
-
assert.equal(el.props.raw['mount'], value, "Props' raw map entry should be added")
|
|
210
|
-
assert.end()
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
test('Element - Set `color` property', (assert) => {
|
|
214
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
215
|
-
const el = createElement()
|
|
216
|
-
|
|
217
|
-
el.set('color', 'azure')
|
|
218
|
-
|
|
219
|
-
assert.equal(el.node['color'], '0xf0ffffff', 'Node color parameter should be set')
|
|
220
|
-
assert.equal(el.props.props['color'], '0xf0ffffff', 'Props color parameter should be set')
|
|
221
|
-
assert.equal(el.props.raw['color'], 'azure', "Props' raw map entry should be added")
|
|
222
|
-
assert.end()
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
test('Element - Set `src` property', (assert) => {
|
|
226
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
227
|
-
const el = createElement()
|
|
228
|
-
const value = 'file://foo.html'
|
|
229
|
-
|
|
230
|
-
el.set('src', value)
|
|
231
|
-
|
|
232
|
-
assert.equal(el.node['src'], value, 'Node src parameter should be set')
|
|
233
|
-
assert.equal(el.props.props['src'], value, 'Props src parameter should be set')
|
|
234
|
-
assert.equal(el.props.raw['src'], value, "Props' raw map entry should be added")
|
|
235
|
-
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
|
|
236
|
-
assert.end()
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
test('Element - Set `texture` property', (assert) => {
|
|
240
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
241
|
-
const el = createElement()
|
|
242
|
-
|
|
243
|
-
el.set('texture', 'foo')
|
|
244
|
-
|
|
245
|
-
assert.equal(el.node['texture'], 'foo', 'Node texture parameter should be set')
|
|
246
|
-
assert.equal(el.props.props['texture'], 'foo', 'Props texture parameter should be set')
|
|
247
|
-
assert.equal(el.props.raw['texture'], 'foo', "Props' raw map entry should be added")
|
|
248
|
-
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
|
|
249
|
-
assert.end()
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
test('Element - Set `fit` property with a string type value', (assert) => {
|
|
253
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
254
|
-
const el = createElement()
|
|
255
|
-
|
|
256
|
-
const fitVal = 'contain'
|
|
257
|
-
el.set('fit', fitVal)
|
|
258
|
-
|
|
259
|
-
assert.ok(el.node['textureOptions'] instanceof Object, 'textureOptions should be an object')
|
|
260
|
-
assert.ok(
|
|
261
|
-
el.node['textureOptions']['resizeMode'] instanceof Object,
|
|
262
|
-
'resizeMode should be an object'
|
|
263
|
-
)
|
|
264
|
-
assert.equal(
|
|
265
|
-
el.node['textureOptions']['resizeMode']['type'],
|
|
266
|
-
fitVal,
|
|
267
|
-
'Node resizeMode "type" parameter should be set'
|
|
268
|
-
)
|
|
269
|
-
assert.equal(
|
|
270
|
-
el.props.props['textureOptions']['resizeMode']['type'],
|
|
271
|
-
fitVal,
|
|
272
|
-
'Props textureOptions parameter should be set'
|
|
273
|
-
)
|
|
274
|
-
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
275
|
-
assert.end()
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
test('Element - Set `fit` property with an object type value', (assert) => {
|
|
279
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
280
|
-
const el = createElement()
|
|
281
|
-
|
|
282
|
-
const fitVal = "{type: 'cover', position: {x: 0, y:1}}"
|
|
283
|
-
el.set('fit', fitVal)
|
|
284
|
-
|
|
285
|
-
assert.equal(
|
|
286
|
-
el.node['textureOptions']['resizeMode']['type'],
|
|
287
|
-
'cover',
|
|
288
|
-
'Node resizeMode "type" parameter should be set'
|
|
289
|
-
)
|
|
290
|
-
assert.equal(
|
|
291
|
-
el.props.props['textureOptions']['resizeMode']['type'],
|
|
292
|
-
'cover',
|
|
293
|
-
'Props textureOptions parameter should be set'
|
|
294
|
-
)
|
|
295
|
-
assert.equal(
|
|
296
|
-
el.node['textureOptions']['resizeMode']['clipX'],
|
|
297
|
-
0,
|
|
298
|
-
'Node resizeMode "clipX" parameter should be set to correct value'
|
|
299
|
-
)
|
|
300
|
-
assert.equal(
|
|
301
|
-
el.node['textureOptions']['resizeMode']['clipY'],
|
|
302
|
-
1,
|
|
303
|
-
'Node resizeMode "clipY" parameter should be set to correct value'
|
|
304
|
-
)
|
|
305
|
-
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
306
|
-
assert.end()
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
test('Element - Set `fit` property with position key as a string type value', (assert) => {
|
|
310
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
311
|
-
const el = createElement()
|
|
312
|
-
|
|
313
|
-
const fitVal = "{type: 'cover', position: 1}"
|
|
314
|
-
el.set('fit', fitVal)
|
|
315
|
-
|
|
316
|
-
assert.equal(
|
|
317
|
-
el.node['textureOptions']['resizeMode']['type'],
|
|
318
|
-
'cover',
|
|
319
|
-
'Node resizeMode "type" parameter should be set'
|
|
320
|
-
)
|
|
321
|
-
assert.equal(
|
|
322
|
-
el.props.props['textureOptions']['resizeMode']['type'],
|
|
323
|
-
'cover',
|
|
324
|
-
'Props textureOptions parameter should be set'
|
|
325
|
-
)
|
|
326
|
-
assert.equal(
|
|
327
|
-
el.node['textureOptions']['resizeMode']['clipX'],
|
|
328
|
-
1,
|
|
329
|
-
'Node resizeMode "clipX" parameter should be set to correct value'
|
|
330
|
-
)
|
|
331
|
-
assert.equal(
|
|
332
|
-
el.node['textureOptions']['resizeMode']['clipY'],
|
|
333
|
-
1,
|
|
334
|
-
'Node resizeMode "clipY" parameter should be set to correct value'
|
|
335
|
-
)
|
|
336
|
-
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
337
|
-
assert.end()
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
test('Element - Set `fit` property should not set not required keys', (assert) => {
|
|
341
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
342
|
-
const el = createElement()
|
|
343
|
-
|
|
344
|
-
const fitVal = "{type: 'cover', dummy1: 0, dummy2: 0}"
|
|
345
|
-
el.set('fit', fitVal)
|
|
346
|
-
|
|
347
|
-
assert.equal(
|
|
348
|
-
el.node['textureOptions']['resizeMode']['type'],
|
|
349
|
-
'cover',
|
|
350
|
-
'Node resizeMode "type" parameter should be set'
|
|
351
|
-
)
|
|
352
|
-
assert.equal(
|
|
353
|
-
el.props.props['textureOptions']['resizeMode']['dummy1'],
|
|
354
|
-
undefined,
|
|
355
|
-
'Props resizeMode "dummy1" parameter should not be set'
|
|
356
|
-
)
|
|
357
|
-
assert.equal(
|
|
358
|
-
el.props.props['textureOptions']['resizeMode']['dummy2'],
|
|
359
|
-
undefined,
|
|
360
|
-
'Props resizeMode "dummy2" parameter should not be set'
|
|
361
|
-
)
|
|
362
|
-
assert.end()
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
test('Element - Set `placement` property with value `center`', (assert) => {
|
|
366
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
367
|
-
const el = createElement()
|
|
368
|
-
|
|
369
|
-
el.set('placement', 'center')
|
|
370
|
-
|
|
371
|
-
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
372
|
-
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
373
|
-
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
374
|
-
assert.equal(el.props.props['x'], 960, 'props x parameter should be set to 960')
|
|
375
|
-
assert.equal(
|
|
376
|
-
el.node['y'],
|
|
377
|
-
undefined,
|
|
378
|
-
'Node Y parameter should not be modified from default value'
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
assert.end()
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
test('Element - Set `placement` property with value `right`', (assert) => {
|
|
385
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
386
|
-
const el = createElement()
|
|
387
|
-
|
|
388
|
-
el.set('placement', 'right')
|
|
389
|
-
|
|
390
|
-
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
391
|
-
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
392
|
-
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
393
|
-
assert.equal(el.props.props['x'], 1920, 'props x parameter should be set to 1920')
|
|
394
|
-
assert.equal(
|
|
395
|
-
el.node['y'],
|
|
396
|
-
undefined,
|
|
397
|
-
'Node Y parameter should not be modified from default value'
|
|
398
|
-
)
|
|
399
|
-
|
|
400
|
-
assert.end()
|
|
401
|
-
})
|
|
402
|
-
|
|
403
|
-
test('Element - Set `placement` property with value `middle`', (assert) => {
|
|
404
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
405
|
-
const el = createElement()
|
|
406
|
-
|
|
407
|
-
el.set('placement', 'middle')
|
|
408
|
-
|
|
409
|
-
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
410
|
-
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
411
|
-
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
412
|
-
assert.equal(el.props.props['y'], 540, 'props Y parameter should be set to 540')
|
|
413
|
-
assert.equal(
|
|
414
|
-
el.node['x'],
|
|
415
|
-
undefined,
|
|
416
|
-
'Node X parameter should not be modified from default value'
|
|
417
|
-
)
|
|
418
|
-
|
|
419
|
-
assert.end()
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
test('Element - Set `placement` property with value `bottom`', (assert) => {
|
|
423
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
424
|
-
const el = createElement()
|
|
425
|
-
|
|
426
|
-
el.set('placement', 'bottom')
|
|
427
|
-
|
|
428
|
-
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
429
|
-
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
430
|
-
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height, 1080')
|
|
431
|
-
assert.equal(el.props.props['y'], 1080, 'props Y parameter should be set to 1080')
|
|
432
|
-
assert.equal(
|
|
433
|
-
el.node['x'],
|
|
434
|
-
undefined,
|
|
435
|
-
'Node X parameter should not be modified from default value'
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
assert.end()
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
test('Element - Set `placement` property with value `bottom` & x = 300', (assert) => {
|
|
442
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
443
|
-
const el = createElement()
|
|
444
|
-
|
|
445
|
-
el.set('placement', 'bottom')
|
|
446
|
-
|
|
447
|
-
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
448
|
-
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
449
|
-
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height, 1080')
|
|
450
|
-
assert.equal(el.props.props['y'], 1080, 'props Y parameter should be set to 1080')
|
|
451
|
-
|
|
452
|
-
el.set('x', 300)
|
|
453
|
-
|
|
454
|
-
assert.equal(el.node['x'], 300, 'Node x parameter should set custom value 300')
|
|
455
|
-
|
|
456
|
-
assert.end()
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
test('Element - Set `placement` property with object value `{x:"center", y:"middle"}`', (assert) => {
|
|
460
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
461
|
-
const el = createElement()
|
|
462
|
-
|
|
463
|
-
el.set('placement', "{x:'center', y:'middle'}")
|
|
464
|
-
|
|
465
|
-
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
466
|
-
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
467
|
-
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
468
|
-
|
|
469
|
-
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
470
|
-
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
471
|
-
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
472
|
-
|
|
473
|
-
assert.end()
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
test('Element - Set `placement` property with object value `{x:"center", y:"bottom"}`', (assert) => {
|
|
477
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
478
|
-
const el = createElement()
|
|
479
|
-
|
|
480
|
-
el.set('placement', "{x:'center', y:'bottom'}")
|
|
481
|
-
|
|
482
|
-
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
483
|
-
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
484
|
-
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
485
|
-
|
|
486
|
-
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
487
|
-
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
488
|
-
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height , 1080')
|
|
489
|
-
|
|
490
|
-
assert.end()
|
|
491
|
-
})
|
|
492
|
-
|
|
493
|
-
test('Element - Set `placement` property with object value `{x:"right", y:"middle"}`', (assert) => {
|
|
494
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
495
|
-
const el = createElement()
|
|
496
|
-
|
|
497
|
-
el.set('placement', "{x:'right', y:'middle'}")
|
|
498
|
-
|
|
499
|
-
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
500
|
-
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
501
|
-
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
502
|
-
|
|
503
|
-
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
504
|
-
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
505
|
-
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
506
|
-
|
|
507
|
-
assert.end()
|
|
508
|
-
})
|
|
509
|
-
|
|
510
|
-
test('Element - Set `placement` property with object value `{x:"right", y:"bottom"}`', (assert) => {
|
|
511
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
512
|
-
const el = createElement()
|
|
513
|
-
|
|
514
|
-
el.set('placement', "{x:'right', y:'bottom'}")
|
|
515
|
-
|
|
516
|
-
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
517
|
-
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
518
|
-
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
519
|
-
|
|
520
|
-
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
521
|
-
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
522
|
-
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node height, 1080')
|
|
523
|
-
|
|
524
|
-
assert.end()
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
test('Element - Set `float` property with value `unknown`', (assert) => {
|
|
528
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
529
|
-
const el = createElement()
|
|
530
|
-
|
|
531
|
-
el.set('float', 'unknown')
|
|
532
|
-
|
|
533
|
-
assert.equal(el.node['mountX'], undefined, 'Node mountX parameter should not be changed')
|
|
534
|
-
assert.equal(el.props.props['mountX'], undefined, 'Props mountX parameter should not be changed')
|
|
535
|
-
assert.equal(el.node['x'], undefined, 'Node x parameter should not get updated')
|
|
536
|
-
assert.equal(el.props.props['x'], undefined, 'props x parameter should not be changed')
|
|
537
|
-
|
|
538
|
-
assert.end()
|
|
539
|
-
})
|
|
540
|
-
|
|
541
|
-
test('Element - Set `show` property as false', (assert) => {
|
|
542
|
-
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
543
|
-
const el = createElement()
|
|
544
|
-
|
|
545
|
-
el.set('w', 960)
|
|
546
|
-
el.set('h', 540)
|
|
547
|
-
|
|
548
|
-
el.set('show', false)
|
|
549
|
-
|
|
550
|
-
elementRef = el
|
|
551
|
-
|
|
552
|
-
assert.equal(el.node['alpha'], 0, 'Node alpha parameter should set to 0')
|
|
553
|
-
assert.equal(el.props.props['alpha'], 0, 'Props alpha parameter should set')
|
|
554
|
-
|
|
555
|
-
assert.end()
|
|
556
|
-
})
|
|
557
|
-
|
|
558
|
-
test('Element - Set `show` property as false', (assert) => {
|
|
559
|
-
const el = elementRef
|
|
560
|
-
|
|
561
|
-
el.set('show', true)
|
|
562
|
-
|
|
563
|
-
assert.equal(el.node['alpha'], 1, 'Node alpha parameter should be set')
|
|
564
|
-
assert.equal(el.props.props['alpha'], 1, 'Props alpha parameter should be set')
|
|
565
|
-
assert.equal(el.node['width'], 960, 'Node width parameter should be set')
|
|
566
|
-
assert.equal(el.node['height'], 540, 'Node height parameter should be set')
|
|
567
|
-
|
|
568
|
-
assert.end()
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
function createElement() {
|
|
572
|
-
const el = element({ parent: { node: { width: 1920, height: 1080 } } }, {})
|
|
573
|
-
el.populate({
|
|
574
|
-
parent: {
|
|
575
|
-
node: new EventEmitter(),
|
|
576
|
-
},
|
|
577
|
-
})
|
|
578
|
-
return el
|
|
579
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import test from 'tape'
|
|
19
|
+
import element from './element.js'
|
|
20
|
+
import { renderer } from './launch.js'
|
|
21
|
+
import { EventEmitter } from 'node:events'
|
|
22
|
+
import { initLog } from '../../lib/log.js'
|
|
23
|
+
import symbols from '../../lib/symbols.js'
|
|
24
|
+
|
|
25
|
+
initLog()
|
|
26
|
+
|
|
27
|
+
let elementRef
|
|
28
|
+
|
|
29
|
+
test('Type', (assert) => {
|
|
30
|
+
assert.ok(element instanceof Function, 'Element should be a factory function')
|
|
31
|
+
assert.end()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('Destroy', (assert) => {
|
|
35
|
+
const el = element({}, {})
|
|
36
|
+
el.node = { destroy: () => {} }
|
|
37
|
+
const capture = assert.capture(el.node, 'destroy')
|
|
38
|
+
|
|
39
|
+
el.destroy()
|
|
40
|
+
|
|
41
|
+
const calls = capture()
|
|
42
|
+
assert.ok(calls.length > 0, 'Node destroy should be invoked')
|
|
43
|
+
assert.end()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('NodeId', (assert) => {
|
|
47
|
+
const el = element({}, {})
|
|
48
|
+
el.node = { id: 123 }
|
|
49
|
+
|
|
50
|
+
const result = el.nodeId
|
|
51
|
+
|
|
52
|
+
assert.equal(result, 123, 'NodeId should be correct')
|
|
53
|
+
assert.end()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('Ref', (assert) => {
|
|
57
|
+
const el = element({}, {})
|
|
58
|
+
el.props = { ref: 123 }
|
|
59
|
+
|
|
60
|
+
const result = el.ref
|
|
61
|
+
|
|
62
|
+
assert.equal(result, 123, 'Ref should be correct')
|
|
63
|
+
assert.end()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('Parent', (assert) => {
|
|
67
|
+
const el = element({}, {})
|
|
68
|
+
el.node = { parent: 'foo' }
|
|
69
|
+
|
|
70
|
+
const result = el.parent
|
|
71
|
+
|
|
72
|
+
assert.equal(result, 'foo', 'Parent should be correct')
|
|
73
|
+
assert.end()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('Children', (assert) => {
|
|
77
|
+
const el = element({}, {})
|
|
78
|
+
el.node = 'foo'
|
|
79
|
+
el.component[symbols.getChildren] = () => [
|
|
80
|
+
{ id: 0, parent: 'bar' },
|
|
81
|
+
{ id: 1, parent: 'foo' },
|
|
82
|
+
{ id: 2, parent: undefined },
|
|
83
|
+
{ id: 3, parent: 0 },
|
|
84
|
+
{ id: 4, parent: 'foo' },
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
const result = el.children
|
|
88
|
+
|
|
89
|
+
assert.equal(result.length, 2, 'Children amount should be correct')
|
|
90
|
+
assert.deepEqual(
|
|
91
|
+
result.map((c) => c.id),
|
|
92
|
+
[1, 4],
|
|
93
|
+
'Children should be correct'
|
|
94
|
+
)
|
|
95
|
+
assert.end()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('Element - Set `w` property', (assert) => {
|
|
99
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
100
|
+
const el = createElement()
|
|
101
|
+
|
|
102
|
+
el.set('w', 100)
|
|
103
|
+
|
|
104
|
+
assert.equal(el.node['width'], 100, 'Node width parameter should be set')
|
|
105
|
+
assert.equal(el.props.props['width'], 100, 'Props width parameter should be set')
|
|
106
|
+
assert.equal(el.props.raw['w'], 100, "Props' raw map entry should be added")
|
|
107
|
+
assert.end()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('Element- Set `w` property in percentage', (assert) => {
|
|
111
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
112
|
+
const el = createElement()
|
|
113
|
+
|
|
114
|
+
el.set('w', '50%')
|
|
115
|
+
|
|
116
|
+
assert.equal(el.node['width'], 960, 'Node width parameter should be set to 960')
|
|
117
|
+
assert.equal(el.props.props['width'], 960, 'Props width parameter should be set')
|
|
118
|
+
assert.equal(el.props.raw['w'], '50%', "Props' raw map entry should be added")
|
|
119
|
+
|
|
120
|
+
assert.end()
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('Element - Set `h` property', (assert) => {
|
|
124
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
125
|
+
const el = createElement()
|
|
126
|
+
|
|
127
|
+
el.set('h', 100)
|
|
128
|
+
|
|
129
|
+
assert.equal(el.node['height'], 100, 'Node height parameter should be set')
|
|
130
|
+
assert.equal(el.props.props['height'], 100, 'Props height parameter should be set')
|
|
131
|
+
assert.equal(el.props.raw['h'], 100, "Props' raw map entry should be added")
|
|
132
|
+
assert.end()
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('Element- Set `h` property in percentage', (assert) => {
|
|
136
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
137
|
+
const el = createElement()
|
|
138
|
+
|
|
139
|
+
el.set('h', '50%')
|
|
140
|
+
|
|
141
|
+
assert.equal(el.node['height'], 540, 'Node width parameter should be set to 540')
|
|
142
|
+
assert.equal(el.props.props['height'], 540, 'Props width parameter should be set')
|
|
143
|
+
assert.equal(el.props.raw['h'], '50%', "Props' raw map entry should be added")
|
|
144
|
+
|
|
145
|
+
assert.end()
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('Element - Set `x` property', (assert) => {
|
|
149
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
150
|
+
const el = createElement()
|
|
151
|
+
|
|
152
|
+
el.set('x', 100)
|
|
153
|
+
|
|
154
|
+
assert.equal(el.node['x'], 100, 'Node x parameter should be set')
|
|
155
|
+
assert.equal(el.props.props['x'], 100, 'Props x parameter should be set')
|
|
156
|
+
assert.equal(el.props.raw['x'], 100, "Props' raw map entry should be added")
|
|
157
|
+
assert.end()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('Element- Set `x` property in percentage', (assert) => {
|
|
161
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
162
|
+
const el = createElement()
|
|
163
|
+
|
|
164
|
+
el.set('x', '50%')
|
|
165
|
+
|
|
166
|
+
assert.equal(el.node['x'], 960, 'Node x parameter should be set to 960')
|
|
167
|
+
assert.equal(el.props.props['x'], 960, 'Props x parameter should be set')
|
|
168
|
+
assert.equal(el.props.raw['x'], '50%', "Props' raw map entry should be added")
|
|
169
|
+
|
|
170
|
+
assert.end()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('Element - Set `y` property', (assert) => {
|
|
174
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
175
|
+
const el = createElement()
|
|
176
|
+
|
|
177
|
+
el.set('y', 100)
|
|
178
|
+
|
|
179
|
+
assert.equal(el.node['y'], 100, 'Node y parameter should be set')
|
|
180
|
+
assert.equal(el.props.props['y'], 100, 'Props y parameter should be set')
|
|
181
|
+
assert.equal(el.props.raw['y'], 100, "Props' raw map entry should be added")
|
|
182
|
+
assert.end()
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('Element- Set `y` property in percentage', (assert) => {
|
|
186
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
187
|
+
const el = createElement()
|
|
188
|
+
|
|
189
|
+
el.set('y', '50%')
|
|
190
|
+
|
|
191
|
+
assert.equal(el.node['y'], 540, 'Node y parameter should be set to 540')
|
|
192
|
+
assert.equal(el.props.props['y'], 540, 'Props y parameter should be set')
|
|
193
|
+
assert.equal(el.props.raw['y'], '50%', "Props' raw map entry should be added")
|
|
194
|
+
|
|
195
|
+
assert.end()
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
test('Element - Set `mount` property', (assert) => {
|
|
199
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
200
|
+
const el = createElement()
|
|
201
|
+
const value = '{ x: 10, y: 20 }'
|
|
202
|
+
|
|
203
|
+
el.set('mount', value)
|
|
204
|
+
|
|
205
|
+
assert.equal(el.node['mountX'], 10, 'Node mountX parameter should be set')
|
|
206
|
+
assert.equal(el.node['mountY'], 20, 'Node mountY parameter should be set')
|
|
207
|
+
assert.equal(el.props.props['mountX'], 10, 'Props mountX parameter should be set')
|
|
208
|
+
assert.equal(el.props.props['mountY'], 20, 'Props mountY parameter should be set')
|
|
209
|
+
assert.equal(el.props.raw['mount'], value, "Props' raw map entry should be added")
|
|
210
|
+
assert.end()
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('Element - Set `color` property', (assert) => {
|
|
214
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
215
|
+
const el = createElement()
|
|
216
|
+
|
|
217
|
+
el.set('color', 'azure')
|
|
218
|
+
|
|
219
|
+
assert.equal(el.node['color'], '0xf0ffffff', 'Node color parameter should be set')
|
|
220
|
+
assert.equal(el.props.props['color'], '0xf0ffffff', 'Props color parameter should be set')
|
|
221
|
+
assert.equal(el.props.raw['color'], 'azure', "Props' raw map entry should be added")
|
|
222
|
+
assert.end()
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('Element - Set `src` property', (assert) => {
|
|
226
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
227
|
+
const el = createElement()
|
|
228
|
+
const value = 'file://foo.html'
|
|
229
|
+
|
|
230
|
+
el.set('src', value)
|
|
231
|
+
|
|
232
|
+
assert.equal(el.node['src'], value, 'Node src parameter should be set')
|
|
233
|
+
assert.equal(el.props.props['src'], value, 'Props src parameter should be set')
|
|
234
|
+
assert.equal(el.props.raw['src'], value, "Props' raw map entry should be added")
|
|
235
|
+
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
|
|
236
|
+
assert.end()
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('Element - Set `texture` property', (assert) => {
|
|
240
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
241
|
+
const el = createElement()
|
|
242
|
+
|
|
243
|
+
el.set('texture', 'foo')
|
|
244
|
+
|
|
245
|
+
assert.equal(el.node['texture'], 'foo', 'Node texture parameter should be set')
|
|
246
|
+
assert.equal(el.props.props['texture'], 'foo', 'Props texture parameter should be set')
|
|
247
|
+
assert.equal(el.props.raw['texture'], 'foo', "Props' raw map entry should be added")
|
|
248
|
+
assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
|
|
249
|
+
assert.end()
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test('Element - Set `fit` property with a string type value', (assert) => {
|
|
253
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
254
|
+
const el = createElement()
|
|
255
|
+
|
|
256
|
+
const fitVal = 'contain'
|
|
257
|
+
el.set('fit', fitVal)
|
|
258
|
+
|
|
259
|
+
assert.ok(el.node['textureOptions'] instanceof Object, 'textureOptions should be an object')
|
|
260
|
+
assert.ok(
|
|
261
|
+
el.node['textureOptions']['resizeMode'] instanceof Object,
|
|
262
|
+
'resizeMode should be an object'
|
|
263
|
+
)
|
|
264
|
+
assert.equal(
|
|
265
|
+
el.node['textureOptions']['resizeMode']['type'],
|
|
266
|
+
fitVal,
|
|
267
|
+
'Node resizeMode "type" parameter should be set'
|
|
268
|
+
)
|
|
269
|
+
assert.equal(
|
|
270
|
+
el.props.props['textureOptions']['resizeMode']['type'],
|
|
271
|
+
fitVal,
|
|
272
|
+
'Props textureOptions parameter should be set'
|
|
273
|
+
)
|
|
274
|
+
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
275
|
+
assert.end()
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('Element - Set `fit` property with an object type value', (assert) => {
|
|
279
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
280
|
+
const el = createElement()
|
|
281
|
+
|
|
282
|
+
const fitVal = "{type: 'cover', position: {x: 0, y:1}}"
|
|
283
|
+
el.set('fit', fitVal)
|
|
284
|
+
|
|
285
|
+
assert.equal(
|
|
286
|
+
el.node['textureOptions']['resizeMode']['type'],
|
|
287
|
+
'cover',
|
|
288
|
+
'Node resizeMode "type" parameter should be set'
|
|
289
|
+
)
|
|
290
|
+
assert.equal(
|
|
291
|
+
el.props.props['textureOptions']['resizeMode']['type'],
|
|
292
|
+
'cover',
|
|
293
|
+
'Props textureOptions parameter should be set'
|
|
294
|
+
)
|
|
295
|
+
assert.equal(
|
|
296
|
+
el.node['textureOptions']['resizeMode']['clipX'],
|
|
297
|
+
0,
|
|
298
|
+
'Node resizeMode "clipX" parameter should be set to correct value'
|
|
299
|
+
)
|
|
300
|
+
assert.equal(
|
|
301
|
+
el.node['textureOptions']['resizeMode']['clipY'],
|
|
302
|
+
1,
|
|
303
|
+
'Node resizeMode "clipY" parameter should be set to correct value'
|
|
304
|
+
)
|
|
305
|
+
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
306
|
+
assert.end()
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test('Element - Set `fit` property with position key as a string type value', (assert) => {
|
|
310
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
311
|
+
const el = createElement()
|
|
312
|
+
|
|
313
|
+
const fitVal = "{type: 'cover', position: 1}"
|
|
314
|
+
el.set('fit', fitVal)
|
|
315
|
+
|
|
316
|
+
assert.equal(
|
|
317
|
+
el.node['textureOptions']['resizeMode']['type'],
|
|
318
|
+
'cover',
|
|
319
|
+
'Node resizeMode "type" parameter should be set'
|
|
320
|
+
)
|
|
321
|
+
assert.equal(
|
|
322
|
+
el.props.props['textureOptions']['resizeMode']['type'],
|
|
323
|
+
'cover',
|
|
324
|
+
'Props textureOptions parameter should be set'
|
|
325
|
+
)
|
|
326
|
+
assert.equal(
|
|
327
|
+
el.node['textureOptions']['resizeMode']['clipX'],
|
|
328
|
+
1,
|
|
329
|
+
'Node resizeMode "clipX" parameter should be set to correct value'
|
|
330
|
+
)
|
|
331
|
+
assert.equal(
|
|
332
|
+
el.node['textureOptions']['resizeMode']['clipY'],
|
|
333
|
+
1,
|
|
334
|
+
'Node resizeMode "clipY" parameter should be set to correct value'
|
|
335
|
+
)
|
|
336
|
+
assert.equal(el.props.raw['fit'], fitVal, "Props' raw map entry should be added")
|
|
337
|
+
assert.end()
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
test('Element - Set `fit` property should not set not required keys', (assert) => {
|
|
341
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
342
|
+
const el = createElement()
|
|
343
|
+
|
|
344
|
+
const fitVal = "{type: 'cover', dummy1: 0, dummy2: 0}"
|
|
345
|
+
el.set('fit', fitVal)
|
|
346
|
+
|
|
347
|
+
assert.equal(
|
|
348
|
+
el.node['textureOptions']['resizeMode']['type'],
|
|
349
|
+
'cover',
|
|
350
|
+
'Node resizeMode "type" parameter should be set'
|
|
351
|
+
)
|
|
352
|
+
assert.equal(
|
|
353
|
+
el.props.props['textureOptions']['resizeMode']['dummy1'],
|
|
354
|
+
undefined,
|
|
355
|
+
'Props resizeMode "dummy1" parameter should not be set'
|
|
356
|
+
)
|
|
357
|
+
assert.equal(
|
|
358
|
+
el.props.props['textureOptions']['resizeMode']['dummy2'],
|
|
359
|
+
undefined,
|
|
360
|
+
'Props resizeMode "dummy2" parameter should not be set'
|
|
361
|
+
)
|
|
362
|
+
assert.end()
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
test('Element - Set `placement` property with value `center`', (assert) => {
|
|
366
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
367
|
+
const el = createElement()
|
|
368
|
+
|
|
369
|
+
el.set('placement', 'center')
|
|
370
|
+
|
|
371
|
+
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
372
|
+
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
373
|
+
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
374
|
+
assert.equal(el.props.props['x'], 960, 'props x parameter should be set to 960')
|
|
375
|
+
assert.equal(
|
|
376
|
+
el.node['y'],
|
|
377
|
+
undefined,
|
|
378
|
+
'Node Y parameter should not be modified from default value'
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
assert.end()
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('Element - Set `placement` property with value `right`', (assert) => {
|
|
385
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
386
|
+
const el = createElement()
|
|
387
|
+
|
|
388
|
+
el.set('placement', 'right')
|
|
389
|
+
|
|
390
|
+
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
391
|
+
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
392
|
+
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
393
|
+
assert.equal(el.props.props['x'], 1920, 'props x parameter should be set to 1920')
|
|
394
|
+
assert.equal(
|
|
395
|
+
el.node['y'],
|
|
396
|
+
undefined,
|
|
397
|
+
'Node Y parameter should not be modified from default value'
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
assert.end()
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
test('Element - Set `placement` property with value `middle`', (assert) => {
|
|
404
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
405
|
+
const el = createElement()
|
|
406
|
+
|
|
407
|
+
el.set('placement', 'middle')
|
|
408
|
+
|
|
409
|
+
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
410
|
+
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
411
|
+
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
412
|
+
assert.equal(el.props.props['y'], 540, 'props Y parameter should be set to 540')
|
|
413
|
+
assert.equal(
|
|
414
|
+
el.node['x'],
|
|
415
|
+
undefined,
|
|
416
|
+
'Node X parameter should not be modified from default value'
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
assert.end()
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
test('Element - Set `placement` property with value `bottom`', (assert) => {
|
|
423
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
424
|
+
const el = createElement()
|
|
425
|
+
|
|
426
|
+
el.set('placement', 'bottom')
|
|
427
|
+
|
|
428
|
+
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
429
|
+
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
430
|
+
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height, 1080')
|
|
431
|
+
assert.equal(el.props.props['y'], 1080, 'props Y parameter should be set to 1080')
|
|
432
|
+
assert.equal(
|
|
433
|
+
el.node['x'],
|
|
434
|
+
undefined,
|
|
435
|
+
'Node X parameter should not be modified from default value'
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
assert.end()
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
test('Element - Set `placement` property with value `bottom` & x = 300', (assert) => {
|
|
442
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
443
|
+
const el = createElement()
|
|
444
|
+
|
|
445
|
+
el.set('placement', 'bottom')
|
|
446
|
+
|
|
447
|
+
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
448
|
+
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
449
|
+
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height, 1080')
|
|
450
|
+
assert.equal(el.props.props['y'], 1080, 'props Y parameter should be set to 1080')
|
|
451
|
+
|
|
452
|
+
el.set('x', 300)
|
|
453
|
+
|
|
454
|
+
assert.equal(el.node['x'], 300, 'Node x parameter should set custom value 300')
|
|
455
|
+
|
|
456
|
+
assert.end()
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test('Element - Set `placement` property with object value `{x:"center", y:"middle"}`', (assert) => {
|
|
460
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
461
|
+
const el = createElement()
|
|
462
|
+
|
|
463
|
+
el.set('placement', "{x:'center', y:'middle'}")
|
|
464
|
+
|
|
465
|
+
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
466
|
+
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
467
|
+
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
468
|
+
|
|
469
|
+
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
470
|
+
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
471
|
+
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
472
|
+
|
|
473
|
+
assert.end()
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
test('Element - Set `placement` property with object value `{x:"center", y:"bottom"}`', (assert) => {
|
|
477
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
478
|
+
const el = createElement()
|
|
479
|
+
|
|
480
|
+
el.set('placement', "{x:'center', y:'bottom'}")
|
|
481
|
+
|
|
482
|
+
assert.equal(el.node['mountX'], 0.5, 'Node mountX parameter should set to 0.5')
|
|
483
|
+
assert.equal(el.props.props['mountX'], 0.5, 'Props mountX parameter should set to 0.5')
|
|
484
|
+
assert.equal(el.node['x'], 960, 'Node x parameter should set to half of parent node width, 960')
|
|
485
|
+
|
|
486
|
+
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
487
|
+
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
488
|
+
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node full height , 1080')
|
|
489
|
+
|
|
490
|
+
assert.end()
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
test('Element - Set `placement` property with object value `{x:"right", y:"middle"}`', (assert) => {
|
|
494
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
495
|
+
const el = createElement()
|
|
496
|
+
|
|
497
|
+
el.set('placement', "{x:'right', y:'middle'}")
|
|
498
|
+
|
|
499
|
+
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
500
|
+
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
501
|
+
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
502
|
+
|
|
503
|
+
assert.equal(el.node['mountY'], 0.5, 'Node mountY parameter should set to 0.5')
|
|
504
|
+
assert.equal(el.props.props['mountY'], 0.5, 'Props mountY parameter should set to 0.5')
|
|
505
|
+
assert.equal(el.node['y'], 540, 'Node Y parameter should set to half of parent node height, 540')
|
|
506
|
+
|
|
507
|
+
assert.end()
|
|
508
|
+
})
|
|
509
|
+
|
|
510
|
+
test('Element - Set `placement` property with object value `{x:"right", y:"bottom"}`', (assert) => {
|
|
511
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
512
|
+
const el = createElement()
|
|
513
|
+
|
|
514
|
+
el.set('placement', "{x:'right', y:'bottom'}")
|
|
515
|
+
|
|
516
|
+
assert.equal(el.node['mountX'], 1, 'Node mountX parameter should set to 1')
|
|
517
|
+
assert.equal(el.props.props['mountX'], 1, 'Props mountX parameter should set to 1')
|
|
518
|
+
assert.equal(el.node['x'], 1920, 'Node x parameter should set to parent node full width, 1920')
|
|
519
|
+
|
|
520
|
+
assert.equal(el.node['mountY'], 1, 'Node mountY parameter should set to 1')
|
|
521
|
+
assert.equal(el.props.props['mountY'], 1, 'Props mountY parameter should set to 1')
|
|
522
|
+
assert.equal(el.node['y'], 1080, 'Node Y parameter should set to parent node height, 1080')
|
|
523
|
+
|
|
524
|
+
assert.end()
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
test('Element - Set `float` property with value `unknown`', (assert) => {
|
|
528
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
529
|
+
const el = createElement()
|
|
530
|
+
|
|
531
|
+
el.set('float', 'unknown')
|
|
532
|
+
|
|
533
|
+
assert.equal(el.node['mountX'], undefined, 'Node mountX parameter should not be changed')
|
|
534
|
+
assert.equal(el.props.props['mountX'], undefined, 'Props mountX parameter should not be changed')
|
|
535
|
+
assert.equal(el.node['x'], undefined, 'Node x parameter should not get updated')
|
|
536
|
+
assert.equal(el.props.props['x'], undefined, 'props x parameter should not be changed')
|
|
537
|
+
|
|
538
|
+
assert.end()
|
|
539
|
+
})
|
|
540
|
+
|
|
541
|
+
test('Element - Set `show` property as false', (assert) => {
|
|
542
|
+
assert.capture(renderer, 'createNode', () => new EventEmitter())
|
|
543
|
+
const el = createElement()
|
|
544
|
+
|
|
545
|
+
el.set('w', 960)
|
|
546
|
+
el.set('h', 540)
|
|
547
|
+
|
|
548
|
+
el.set('show', false)
|
|
549
|
+
|
|
550
|
+
elementRef = el
|
|
551
|
+
|
|
552
|
+
assert.equal(el.node['alpha'], 0, 'Node alpha parameter should set to 0')
|
|
553
|
+
assert.equal(el.props.props['alpha'], 0, 'Props alpha parameter should set')
|
|
554
|
+
|
|
555
|
+
assert.end()
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
test('Element - Set `show` property as false', (assert) => {
|
|
559
|
+
const el = elementRef
|
|
560
|
+
|
|
561
|
+
el.set('show', true)
|
|
562
|
+
|
|
563
|
+
assert.equal(el.node['alpha'], 1, 'Node alpha parameter should be set')
|
|
564
|
+
assert.equal(el.props.props['alpha'], 1, 'Props alpha parameter should be set')
|
|
565
|
+
assert.equal(el.node['width'], 960, 'Node width parameter should be set')
|
|
566
|
+
assert.equal(el.node['height'], 540, 'Node height parameter should be set')
|
|
567
|
+
|
|
568
|
+
assert.end()
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
function createElement() {
|
|
572
|
+
const el = element({ parent: { node: { width: 1920, height: 1080 } } }, {})
|
|
573
|
+
el.populate({
|
|
574
|
+
parent: {
|
|
575
|
+
node: new EventEmitter(),
|
|
576
|
+
},
|
|
577
|
+
})
|
|
578
|
+
return el
|
|
579
|
+
}
|