@@ -161,7 +161,7 @@ define(
161
161
} ) ;
162
162
} ) ;
163
163
164
- describe ( 'Subscribes to new data ' , function ( ) {
164
+ describe ( 'when getting telemetry ' , function ( ) {
165
165
var mockComposition ,
166
166
mockTelemetryObject ,
167
167
mockChildren ,
@@ -173,9 +173,7 @@ define(
173
173
"load"
174
174
] ) ;
175
175
176
- mockTelemetryObject = jasmine . createSpyObj ( "mockTelemetryObject" , [
177
- "something"
178
- ] ) ;
176
+ mockTelemetryObject = { } ;
179
177
mockTelemetryObject . identifier = {
180
178
key : "mockTelemetryObject"
181
179
} ;
@@ -192,22 +190,41 @@ define(
192
190
} ) ;
193
191
194
192
done = false ;
193
+ } ) ;
194
+
195
+ it ( 'fetches historical data for the time period specified by the conductor bounds' , function ( ) {
195
196
controller . getData ( ) . then ( function ( ) {
196
197
done = true ;
197
198
} ) ;
199
+ waitsFor ( function ( ) {
200
+ return done ;
201
+ } , "getData to return" , 100 ) ;
202
+
203
+ runs ( function ( ) {
204
+ expect ( mockTelemetryAPI . request ) . toHaveBeenCalledWith ( mockTelemetryObject , mockBounds ) ;
205
+ } ) ;
198
206
} ) ;
199
207
200
- it ( 'fetches historical data' , function ( ) {
208
+ it ( 'unsubscribes on view destruction' , function ( ) {
209
+ controller . getData ( ) . then ( function ( ) {
210
+ done = true ;
211
+ } ) ;
212
+
201
213
waitsFor ( function ( ) {
202
214
return done ;
203
215
} , "getData to return" , 100 ) ;
204
216
205
217
runs ( function ( ) {
206
- expect ( mockTelemetryAPI . request ) . toHaveBeenCalledWith ( mockTelemetryObject , jasmine . any ( Object ) ) ;
218
+ var destroy = getCallback ( mockScope . $on , "$destroy" ) ;
219
+ destroy ( ) ;
220
+
221
+ expect ( unsubscribe ) . toHaveBeenCalled ( ) ;
207
222
} ) ;
208
223
} ) ;
209
-
210
224
it ( 'fetches historical data for the time period specified by the conductor bounds' , function ( ) {
225
+ controller . getData ( ) . then ( function ( ) {
226
+ done = true ;
227
+ } ) ;
211
228
waitsFor ( function ( ) {
212
229
return done ;
213
230
} , "getData to return" , 100 ) ;
@@ -217,26 +234,72 @@ define(
217
234
} ) ;
218
235
} ) ;
219
236
220
- it ( 'subscribes to new data' , function ( ) {
237
+ it ( 'fetches data for, and subscribes to parent object if it is a telemetry object' , function ( ) {
238
+ controller . getData ( ) . then ( function ( ) {
239
+ done = true ;
240
+ } ) ;
221
241
waitsFor ( function ( ) {
222
242
return done ;
223
243
} , "getData to return" , 100 ) ;
224
244
225
245
runs ( function ( ) {
226
246
expect ( mockTelemetryAPI . subscribe ) . toHaveBeenCalledWith ( mockTelemetryObject , jasmine . any ( Function ) , { } ) ;
247
+ expect ( mockTelemetryAPI . request ) . toHaveBeenCalledWith ( mockTelemetryObject , jasmine . any ( Object ) ) ;
227
248
} ) ;
249
+ } ) ;
250
+ it ( 'fetches data for, and subscribes to parent object if it is a telemetry object' , function ( ) {
251
+ controller . getData ( ) . then ( function ( ) {
252
+ done = true ;
253
+ } ) ;
254
+ waitsFor ( function ( ) {
255
+ return done ;
256
+ } , "getData to return" , 100 ) ;
228
257
258
+ runs ( function ( ) {
259
+ expect ( mockTelemetryAPI . subscribe ) . toHaveBeenCalledWith ( mockTelemetryObject , jasmine . any ( Function ) , { } ) ;
260
+ expect ( mockTelemetryAPI . request ) . toHaveBeenCalledWith ( mockTelemetryObject , jasmine . any ( Object ) ) ;
261
+ } ) ;
229
262
} ) ;
230
- it ( 'and unsubscribes on view destruction' , function ( ) {
263
+
264
+ it ( 'fetches data for, and subscribes to any composees that are telemetry objects if parent is not' , function ( ) {
265
+ mockChildren = [
266
+ { name : "child 1" }
267
+ ] ;
268
+ var mockTelemetryChildren = [
269
+ { name : "child 2" } ,
270
+ { name : "child 3" } ,
271
+ { name : "child 4" }
272
+ ] ;
273
+ mockChildren = mockChildren . concat ( mockTelemetryChildren ) ;
274
+ mockComposition . load . andReturn ( Promise . resolve ( mockChildren ) ) ;
275
+
276
+ mockTelemetryAPI . canProvideTelemetry . andCallFake ( function ( object ) {
277
+ if ( object === mockTelemetryObject ) {
278
+ return false ;
279
+ } else {
280
+ return mockTelemetryChildren . indexOf ( object ) !== - 1 ;
281
+ }
282
+ } ) ;
283
+
284
+ controller . getData ( ) . then ( function ( ) {
285
+ done = true ;
286
+ } ) ;
287
+
231
288
waitsFor ( function ( ) {
232
289
return done ;
233
290
} , "getData to return" , 100 ) ;
234
291
235
292
runs ( function ( ) {
236
- var destroy = getCallback ( mockScope . $on , "$destroy" ) ;
237
- destroy ( ) ;
293
+ mockTelemetryChildren . forEach ( function ( child ) {
294
+ expect ( mockTelemetryAPI . subscribe ) . toHaveBeenCalledWith ( child , jasmine . any ( Function ) , { } ) ;
295
+ } ) ;
238
296
239
- expect ( unsubscribe ) . toHaveBeenCalled ( ) ;
297
+ mockTelemetryChildren . forEach ( function ( child ) {
298
+ expect ( mockTelemetryAPI . request ) . toHaveBeenCalledWith ( child , jasmine . any ( Object ) ) ;
299
+ } ) ;
300
+
301
+ expect ( mockTelemetryAPI . subscribe ) . not . toHaveBeenCalledWith ( mockChildren [ 0 ] , jasmine . any ( Function ) , { } ) ;
302
+ expect ( mockTelemetryAPI . subscribe ) . not . toHaveBeenCalledWith ( mockTelemetryObject [ 0 ] , jasmine . any ( Function ) , { } ) ;
240
303
} ) ;
241
304
} ) ;
242
305
} ) ;
0 commit comments