@@ -58,7 +58,7 @@ describe('DataSources/ReferenceProperty', function() {
58
58
var collection = new EntityCollection ( ) ;
59
59
collection . add ( testObject ) ;
60
60
61
- //Basic property resolution
61
+ // Basic property resolution
62
62
var property = ReferenceProperty . fromString ( collection , 'testId#billboard.scale' ) ;
63
63
expect ( property . referenceFrame ) . toBeUndefined ( ) ;
64
64
expect ( property . isConstant ) . toEqual ( true ) ;
@@ -68,37 +68,37 @@ describe('DataSources/ReferenceProperty', function() {
68
68
var listener = jasmine . createSpy ( 'listener' ) ;
69
69
property . definitionChanged . addEventListener ( listener ) ;
70
70
71
- //Change to exist target property is reflected in reference.
71
+ // A change to exist target property is reflected in reference.
72
72
testObject . billboard . scale . setValue ( 6 ) ;
73
73
expect ( listener ) . toHaveBeenCalledWith ( property ) ;
74
74
expect ( property . isConstant ) . toEqual ( true ) ;
75
75
expect ( property . getValue ( time ) ) . toEqual ( 6 ) ;
76
76
listener . calls . reset ( ) ;
77
77
78
- //Assignment of new leaf property to existing target is reflected in reference.
78
+ // Assignment of new leaf property to existing target is reflected in reference.
79
79
testObject . billboard . scale = new ConstantProperty ( 7 ) ;
80
80
expect ( listener ) . toHaveBeenCalledWith ( property ) ;
81
81
expect ( property . isConstant ) . toEqual ( true ) ;
82
82
expect ( property . getValue ( time ) ) . toEqual ( 7 ) ;
83
83
listener . calls . reset ( ) ;
84
84
85
- //Assignment of non-leaf property to existing target is reflected in reference.
85
+ // Assignment of non-leaf property to existing target is reflected in reference.
86
86
testObject . billboard = new BillboardGraphics ( ) ;
87
87
testObject . billboard . scale = new ConstantProperty ( 8 ) ;
88
88
expect ( listener ) . toHaveBeenCalledWith ( property ) ;
89
89
expect ( property . isConstant ) . toEqual ( true ) ;
90
90
expect ( property . getValue ( time ) ) . toEqual ( 8 ) ;
91
91
listener . calls . reset ( ) ;
92
92
93
- //Removing an object should cause the reference to be severed but maintain last value
93
+ // Removing an object should cause the reference to be severed.
94
94
collection . remove ( testObject ) ;
95
95
96
- expect ( listener ) . not . toHaveBeenCalledWith ( ) ;
96
+ expect ( listener ) . not . toHaveBeenCalled ( ) ;
97
97
expect ( property . isConstant ) . toEqual ( true ) ;
98
- expect ( property . getValue ( time ) ) . toEqual ( 8 ) ;
98
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
99
99
listener . calls . reset ( ) ;
100
100
101
- //adding a new object should re-wire the reference.
101
+ // Adding a new object should re-wire the reference.
102
102
var testObject2 = new Entity ( {
103
103
id : 'testId'
104
104
} ) ;
@@ -108,6 +108,18 @@ describe('DataSources/ReferenceProperty', function() {
108
108
expect ( listener ) . toHaveBeenCalledWith ( property ) ;
109
109
expect ( property . isConstant ) . toEqual ( true ) ;
110
110
expect ( property . getValue ( time ) ) . toEqual ( 9 ) ;
111
+
112
+ // setting the target property to undefined should cause the reference to be severed.
113
+ testObject2 . billboard . scale = undefined ;
114
+ expect ( listener ) . toHaveBeenCalledWith ( property ) ;
115
+ expect ( property . isConstant ) . toEqual ( true ) ;
116
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
117
+
118
+ // Assigning a valid property should re-connect the reference.
119
+ testObject2 . billboard . scale = new ConstantProperty ( 10 ) ;
120
+ expect ( listener ) . toHaveBeenCalledWith ( property ) ;
121
+ expect ( property . isConstant ) . toEqual ( true ) ;
122
+ expect ( property . getValue ( time ) ) . toEqual ( 10 ) ;
111
123
} ) ;
112
124
113
125
it ( 'works with position properties' , function ( ) {
@@ -119,12 +131,18 @@ describe('DataSources/ReferenceProperty', function() {
119
131
var collection = new EntityCollection ( ) ;
120
132
collection . add ( testObject ) ;
121
133
122
- //Basic property resolution
134
+ // Basic property resolution
123
135
var property = ReferenceProperty . fromString ( collection , 'testId#position' ) ;
124
136
expect ( property . isConstant ) . toEqual ( true ) ;
125
137
expect ( property . referenceFrame ) . toEqual ( ReferenceFrame . FIXED ) ;
126
138
expect ( property . getValue ( time ) ) . toEqual ( testObject . position . getValue ( time ) ) ;
127
139
expect ( property . getValueInReferenceFrame ( time , ReferenceFrame . INERTIAL ) ) . toEqual ( testObject . position . getValueInReferenceFrame ( time , ReferenceFrame . INERTIAL ) ) ;
140
+
141
+ property = ReferenceProperty . fromString ( collection , 'nonExistent#position' ) ;
142
+ expect ( property . isConstant ) . toEqual ( true ) ;
143
+ expect ( property . referenceFrame ) . toBeUndefined ( ) ;
144
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
145
+ expect ( property . getValueInReferenceFrame ( time , ReferenceFrame . INERTIAL ) ) . toBeUndefined ( ) ;
128
146
} ) ;
129
147
130
148
it ( 'works with material properties' , function ( ) {
@@ -137,11 +155,17 @@ describe('DataSources/ReferenceProperty', function() {
137
155
var collection = new EntityCollection ( ) ;
138
156
collection . add ( testObject ) ;
139
157
140
- //Basic property resolution
158
+ // Basic property resolution
141
159
var property = ReferenceProperty . fromString ( collection , 'testId#testMaterial' ) ;
142
160
expect ( property . isConstant ) . toEqual ( true ) ;
143
161
expect ( property . getType ( time ) ) . toEqual ( testObject . testMaterial . getType ( time ) ) ;
144
162
expect ( property . getValue ( time ) ) . toEqual ( testObject . testMaterial . getValue ( time ) ) ;
163
+
164
+ property = ReferenceProperty . fromString ( collection , 'nonExistent#testMaterial' ) ;
165
+ expect ( property . isConstant ) . toEqual ( true ) ;
166
+ expect ( property . referenceFrame ) . toBeUndefined ( ) ;
167
+ expect ( property . getType ( time ) ) . toBeUndefined ( ) ;
168
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
145
169
} ) ;
146
170
147
171
it ( 'equals works' , function ( ) {
@@ -151,19 +175,19 @@ describe('DataSources/ReferenceProperty', function() {
151
175
var right = ReferenceProperty . fromString ( entityCollection , 'objectId#foo.bar' ) ;
152
176
expect ( left . equals ( right ) ) . toEqual ( true ) ;
153
177
154
- //collection differs
178
+ // collection differs
155
179
right = ReferenceProperty . fromString ( new EntityCollection ( ) , 'objectId#foo.bar' ) ;
156
180
expect ( left . equals ( right ) ) . toEqual ( false ) ;
157
181
158
- //target id differs
182
+ // target id differs
159
183
right = ReferenceProperty . fromString ( entityCollection , 'otherObjectId#foo.bar' ) ;
160
184
expect ( left . equals ( right ) ) . toEqual ( false ) ;
161
185
162
- //number of sub-properties differ
186
+ // number of sub-properties differ
163
187
right = ReferenceProperty . fromString ( entityCollection , 'objectId#foo' ) ;
164
188
expect ( left . equals ( right ) ) . toEqual ( false ) ;
165
189
166
- //sub-properties of same length differ
190
+ // sub-properties of same length differ
167
191
right = ReferenceProperty . fromString ( entityCollection , 'objectId#foo.baz' ) ;
168
192
expect ( left . equals ( right ) ) . toEqual ( false ) ;
169
193
} ) ;
@@ -195,6 +219,34 @@ describe('DataSources/ReferenceProperty', function() {
195
219
expect ( listener ) . not . toHaveBeenCalled ( ) ;
196
220
} ) ;
197
221
222
+ it ( 'attaches to a target entity created later' , function ( ) {
223
+ var collection = new EntityCollection ( ) ;
224
+
225
+ var property = ReferenceProperty . fromString ( collection , 'testId#billboard.scale' ) ;
226
+ expect ( property . resolvedProperty ) . toBeUndefined ( ) ;
227
+
228
+ var listener = jasmine . createSpy ( 'listener' ) ;
229
+ property . definitionChanged . addEventListener ( listener ) ;
230
+
231
+ var otherObject = new Entity ( {
232
+ id : 'other'
233
+ } ) ;
234
+ collection . add ( otherObject ) ;
235
+
236
+ expect ( listener ) . not . toHaveBeenCalled ( ) ;
237
+ expect ( property . resolvedProperty ) . toBeUndefined ( ) ;
238
+
239
+ var testObject = new Entity ( {
240
+ id : 'testId'
241
+ } ) ;
242
+ testObject . billboard = new BillboardGraphics ( ) ;
243
+ testObject . billboard . scale = new ConstantProperty ( 5 ) ;
244
+ collection . add ( testObject ) ;
245
+
246
+ expect ( listener ) . toHaveBeenCalledWith ( property ) ;
247
+ expect ( property . resolvedProperty ) . toBe ( testObject . billboard . scale ) ;
248
+ } ) ;
249
+
198
250
it ( 'constructor throws with undefined targetCollection' , function ( ) {
199
251
expect ( function ( ) {
200
252
return new ReferenceProperty ( undefined , 'objectid' , [ 'property' ] ) ;
@@ -251,15 +303,13 @@ describe('DataSources/ReferenceProperty', function() {
251
303
} ) . toThrowDeveloperError ( ) ;
252
304
} ) ;
253
305
254
- it ( 'throws RuntimeError if targetId can not be resolved' , function ( ) {
306
+ it ( 'getValue returns undefined if target entity can not be resolved' , function ( ) {
255
307
var collection = new EntityCollection ( ) ;
256
308
var property = ReferenceProperty . fromString ( collection , 'testId#foo.bar' ) ;
257
- expect ( function ( ) {
258
- property . getValue ( time ) ;
259
- } ) . toThrowRuntimeError ( ) ;
309
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
260
310
} ) ;
261
311
262
- it ( 'throws RuntimeError if property can not be resolved' , function ( ) {
312
+ it ( 'getValue returns undefined if target property can not be resolved' , function ( ) {
263
313
var collection = new EntityCollection ( ) ;
264
314
265
315
var testObject = new Entity ( {
@@ -268,12 +318,10 @@ describe('DataSources/ReferenceProperty', function() {
268
318
collection . add ( testObject ) ;
269
319
270
320
var property = ReferenceProperty . fromString ( collection , 'testId#billboard' ) ;
271
- expect ( function ( ) {
272
- property . getValue ( time ) ;
273
- } ) . toThrowRuntimeError ( ) ;
321
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
274
322
} ) ;
275
323
276
- it ( 'throws RuntimeError if sub-property can not be resolved' , function ( ) {
324
+ it ( 'getValue returns undefined if sub-property of target property can not be resolved' , function ( ) {
277
325
var collection = new EntityCollection ( ) ;
278
326
279
327
var testObject = new Entity ( {
@@ -283,8 +331,6 @@ describe('DataSources/ReferenceProperty', function() {
283
331
collection . add ( testObject ) ;
284
332
285
333
var property = ReferenceProperty . fromString ( collection , 'testId#billboard.foo' ) ;
286
- expect ( function ( ) {
287
- property . getValue ( time ) ;
288
- } ) . toThrowRuntimeError ( ) ;
334
+ expect ( property . getValue ( time ) ) . toBeUndefined ( ) ;
289
335
} ) ;
290
336
} ) ;
0 commit comments