jasmine-core 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,633 @@
1
+ describe("TreeProcessor", function() {
2
+ var nodeNumber = 0, leafNumber = 0;
3
+
4
+ function Node(attrs) {
5
+ attrs = attrs || {};
6
+ this.id = 'node' + nodeNumber++;
7
+ this.children = attrs.children || [];
8
+ this.canBeReentered = function() {
9
+ return !attrs.noReenter;
10
+ };
11
+ this.isExecutable = function() {
12
+ return attrs.executable !== false;
13
+ };
14
+ this.sharedUserContext = function() {
15
+ return attrs.userContext || {};
16
+ };
17
+ this.getResult = jasmine.createSpy(this.id + '#execute');
18
+ this.beforeAllFns = attrs.beforeAllFns || [];
19
+ this.afterAllFns = attrs.afterAllFns || [];
20
+ }
21
+
22
+ function Leaf(attrs) {
23
+ attrs = attrs || {};
24
+ this.id = 'leaf' + leafNumber++;
25
+ this.isExecutable = function() {
26
+ return attrs.executable !== false;
27
+ };
28
+ this.execute = jasmine.createSpy(this.id + '#execute');
29
+ }
30
+
31
+ it("processes a single executable leaf", function() {
32
+ var leaf = new Leaf(),
33
+ processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
34
+ result = processor.processTree();
35
+
36
+ expect(result.valid).toBe(true);
37
+
38
+ expect(result[leaf.id]).toEqual({
39
+ executable: true,
40
+ segments: jasmine.any(Array)
41
+ });
42
+ });
43
+
44
+ it("processes a single non-executable leaf", function() {
45
+ var leaf = new Leaf({ executable: false }),
46
+ processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
47
+ result = processor.processTree();
48
+
49
+ expect(result.valid).toBe(true);
50
+
51
+ expect(result[leaf.id]).toEqual({
52
+ executable: false,
53
+ segments: jasmine.any(Array)
54
+ });
55
+ });
56
+
57
+ it("processes a single non-specified leaf", function() {
58
+ var leaf = new Leaf(),
59
+ processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [] }),
60
+ result = processor.processTree();
61
+
62
+ expect(result.valid).toBe(true);
63
+
64
+ expect(result[leaf.id]).toEqual({
65
+ executable: false,
66
+ segments: jasmine.any(Array)
67
+ });
68
+ });
69
+
70
+ it("processes a tree with a single leaf with the root specified", function() {
71
+ var leaf = new Leaf(),
72
+ parent = new Node({ children: [leaf] }),
73
+ processor = new j$.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
74
+ result = processor.processTree();
75
+
76
+ expect(result.valid).toBe(true);
77
+
78
+ expect(result[parent.id]).toEqual({
79
+ executable: true,
80
+ segments: jasmine.any(Array)
81
+ });
82
+
83
+ expect(result[leaf.id]).toEqual({
84
+ executable: true,
85
+ segments: jasmine.any(Array)
86
+ });
87
+ });
88
+
89
+ it("processes a tree with a single non-executable leaf, with the root specified", function() {
90
+ var leaf = new Leaf({ executable: false }),
91
+ parent = new Node({ children: [leaf] }),
92
+ processor = new j$.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
93
+ result = processor.processTree();
94
+
95
+ expect(result.valid).toBe(true);
96
+
97
+ expect(result[parent.id]).toEqual({
98
+ executable: false,
99
+ segments: jasmine.any(Array)
100
+ });
101
+
102
+ expect(result[leaf.id]).toEqual({
103
+ executable: false,
104
+ segments: jasmine.any(Array)
105
+ });
106
+ });
107
+
108
+ it("processes a complicated tree with the root specified", function() {
109
+ var nonExecutable = new Leaf({ executable: false }),
110
+ executable = new Leaf({ executable: true }),
111
+ parent = new Node({ children: [nonExecutable, executable] }),
112
+ childless = new Node(),
113
+ childOfDisabled = new Leaf({ executable: true }),
114
+ disabledNode = new Node({ executable: false, children: [childOfDisabled] }),
115
+ root = new Node({ children: [parent, childless, disabledNode] }),
116
+ processor = new j$.TreeProcessor({ tree: root, runnableIds: [root.id] }),
117
+ result = processor.processTree();
118
+
119
+ expect(result.valid).toBe(true);
120
+
121
+ expect(result[root.id]).toEqual({
122
+ executable: true,
123
+ segments: jasmine.any(Array)
124
+ });
125
+
126
+ expect(result[childless.id]).toEqual({
127
+ executable: false,
128
+ segments: jasmine.any(Array)
129
+ });
130
+
131
+ expect(result[nonExecutable.id]).toEqual({
132
+ executable: false,
133
+ segments: jasmine.any(Array)
134
+ });
135
+
136
+ expect(result[executable.id]).toEqual({
137
+ executable: true,
138
+ segments: jasmine.any(Array)
139
+ });
140
+
141
+ expect(result[parent.id]).toEqual({
142
+ executable: true,
143
+ segments: jasmine.any(Array)
144
+ });
145
+
146
+ expect(result[disabledNode.id]).toEqual({
147
+ executable: false,
148
+ segments: jasmine.any(Array)
149
+ });
150
+
151
+ expect(result[childOfDisabled.id]).toEqual({
152
+ executable: false,
153
+ segments: jasmine.any(Array)
154
+ });
155
+ });
156
+
157
+ it("marks the run order invalid if it would re-enter a node that does not allow re-entry", function() {
158
+ var leaf1 = new Leaf(),
159
+ leaf2 = new Leaf(),
160
+ leaf3 = new Leaf(),
161
+ reentered = new Node({ noReenter: true, children: [leaf1, leaf2] }),
162
+ root = new Node({ children: [reentered, leaf3] }),
163
+ processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
164
+ result = processor.processTree();
165
+
166
+ expect(result).toEqual({ valid: false });
167
+ });
168
+
169
+ it("marks the run order valid if a node being re-entered allows re-entry", function() {
170
+ var leaf1 = new Leaf(),
171
+ leaf2 = new Leaf(),
172
+ leaf3 = new Leaf(),
173
+ reentered = new Node({ children: [leaf1, leaf2] }),
174
+ root = new Node({ children: [reentered, leaf3] }),
175
+ processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
176
+ result = processor.processTree();
177
+
178
+ expect(result.valid).toBe(true);
179
+ });
180
+
181
+ it("marks the run order valid if a node which can't be re-entered is only entered once", function() {
182
+ var leaf1 = new Leaf(),
183
+ leaf2 = new Leaf(),
184
+ leaf3 = new Leaf(),
185
+ noReentry = new Node({ noReenter: true }),
186
+ root = new Node({ children: [noReentry] }),
187
+ processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf2.id, leaf1.id, leaf3.id] }),
188
+ result = processor.processTree();
189
+
190
+ expect(result.valid).toBe(true);
191
+ });
192
+
193
+ it("marks the run order valid if a node which can't be re-entered is run directly", function() {
194
+ var leaf1 = new Leaf(),
195
+ noReentry = new Node({ noReenter: true }),
196
+ root = new Node({ children: [noReentry] }),
197
+ processor = new j$.TreeProcessor({ tree: root, runnableIds: [root.id] }),
198
+ result = processor.processTree();
199
+
200
+ expect(result.valid).toBe(true);
201
+ });
202
+
203
+ it("runs a single leaf", function() {
204
+ var leaf = new Leaf(),
205
+ node = new Node({ children: [leaf] }),
206
+ queueRunner = jasmine.createSpy('queueRunner'),
207
+ processor = new j$.TreeProcessor({ tree: node, runnableIds: [leaf.id], queueRunnerFactory: queueRunner }),
208
+ treeComplete = jasmine.createSpy('treeComplete');
209
+
210
+ processor.execute(treeComplete);
211
+
212
+ expect(queueRunner).toHaveBeenCalledWith({
213
+ onComplete: treeComplete,
214
+ onException: jasmine.any(Function),
215
+ queueableFns: [{ fn: jasmine.any(Function) }]
216
+ });
217
+
218
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
219
+
220
+ expect(leaf.execute).toHaveBeenCalledWith('foo', true);
221
+ });
222
+
223
+ it("runs a node with no children", function() {
224
+ var node = new Node({ userContext: { node: 'context' } }),
225
+ root = new Node({ children: [node] }),
226
+ nodeStart = jasmine.createSpy('nodeStart'),
227
+ nodeComplete = jasmine.createSpy('nodeComplete'),
228
+ queueRunner = jasmine.createSpy('queueRunner'),
229
+ processor = new j$.TreeProcessor({
230
+ tree: root,
231
+ runnableIds: [node.id],
232
+ nodeStart: nodeStart,
233
+ nodeComplete: nodeComplete,
234
+ queueRunnerFactory: queueRunner
235
+ }),
236
+ treeComplete = jasmine.createSpy('treeComplete'),
237
+ nodeDone = jasmine.createSpy('nodeDone');
238
+
239
+ processor.execute(treeComplete);
240
+
241
+ expect(queueRunner).toHaveBeenCalledWith({
242
+ onComplete: treeComplete,
243
+ onException: jasmine.any(Function),
244
+ queueableFns: [{ fn: jasmine.any(Function) }]
245
+ });
246
+
247
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
248
+
249
+ expect(nodeStart).toHaveBeenCalledWith(node);
250
+ expect(queueRunner).toHaveBeenCalledWith({
251
+ onComplete: jasmine.any(Function),
252
+ queueableFns: [],
253
+ userContext: { node: 'context' },
254
+ onException: jasmine.any(Function)
255
+ });
256
+
257
+ node.getResult.and.returnValue({ my: 'result' });
258
+
259
+ queueRunner.calls.mostRecent().args[0].onComplete();
260
+ expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' });
261
+ expect(nodeDone).toHaveBeenCalled();
262
+ });
263
+
264
+ it("runs a node with children", function() {
265
+ var leaf1 = new Leaf(),
266
+ leaf2 = new Leaf(),
267
+ node = new Node({ children: [leaf1, leaf2] }),
268
+ root = new Node({ children: [node] }),
269
+ queueRunner = jasmine.createSpy('queueRunner'),
270
+ processor = new j$.TreeProcessor({
271
+ tree: root,
272
+ runnableIds: [node.id],
273
+ queueRunnerFactory: queueRunner
274
+ }),
275
+ treeComplete = jasmine.createSpy('treeComplete'),
276
+ nodeDone = jasmine.createSpy('nodeDone');
277
+
278
+ processor.execute(treeComplete);
279
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
280
+ queueableFns[0].fn(nodeDone);
281
+
282
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
283
+ expect(queueableFns.length).toBe(2);
284
+
285
+ queueableFns[0].fn('foo');
286
+ expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
287
+
288
+ queueableFns[1].fn('bar');
289
+ expect(leaf2.execute).toHaveBeenCalledWith('bar', true);
290
+ });
291
+
292
+ it("runs a disabled node", function() {
293
+ var leaf1 = new Leaf(),
294
+ node = new Node({ children: [leaf1], executable: false }),
295
+ root = new Node({ children: [node] }),
296
+ queueRunner = jasmine.createSpy('queueRunner'),
297
+ nodeStart = jasmine.createSpy('nodeStart'),
298
+ nodeComplete = jasmine.createSpy('nodeComplete'),
299
+ processor = new j$.TreeProcessor({
300
+ tree: root,
301
+ runnableIds: [node.id],
302
+ queueRunnerFactory: queueRunner,
303
+ nodeStart: nodeStart,
304
+ nodeComplete: nodeComplete
305
+ }),
306
+ treeComplete = jasmine.createSpy('treeComplete'),
307
+ nodeDone = jasmine.createSpy('nodeDone');
308
+
309
+ processor.execute(treeComplete);
310
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
311
+ queueableFns[0].fn(nodeDone);
312
+
313
+ expect(nodeStart).toHaveBeenCalledWith(node);
314
+
315
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
316
+ expect(queueableFns.length).toBe(1);
317
+
318
+ queueableFns[0].fn('foo');
319
+ expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
320
+
321
+ node.getResult.and.returnValue({ im: 'disabled' });
322
+
323
+ queueRunner.calls.mostRecent().args[0].onComplete();
324
+ expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' });
325
+ });
326
+
327
+ it("runs beforeAlls for a node with children", function() {
328
+ var leaf = new Leaf(),
329
+ node = new Node({
330
+ children: [leaf],
331
+ beforeAllFns: ['beforeAll1', 'beforeAll2']
332
+ }),
333
+ root = new Node({ children: [node] }),
334
+ queueRunner = jasmine.createSpy('queueRunner'),
335
+ processor = new j$.TreeProcessor({
336
+ tree: root,
337
+ runnableIds: [node.id],
338
+ queueRunnerFactory: queueRunner
339
+ }),
340
+ treeComplete = jasmine.createSpy('treeComplete'),
341
+ nodeDone = jasmine.createSpy('nodeDone');
342
+
343
+ processor.execute(treeComplete);
344
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
345
+ queueableFns[0].fn(nodeDone);
346
+
347
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
348
+
349
+ expect(queueableFns).toEqual(['beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
350
+ });
351
+
352
+ it("runs afterAlls for a node with children", function() {
353
+ var leaf = new Leaf(),
354
+ node = new Node({
355
+ children: [leaf],
356
+ afterAllFns: ['afterAll1', 'afterAll2']
357
+ }),
358
+ root = new Node({ children: [node] }),
359
+ queueRunner = jasmine.createSpy('queueRunner'),
360
+ processor = new j$.TreeProcessor({
361
+ tree: root,
362
+ runnableIds: [node.id],
363
+ queueRunnerFactory: queueRunner
364
+ }),
365
+ treeComplete = jasmine.createSpy('treeComplete'),
366
+ nodeDone = jasmine.createSpy('nodeDone');
367
+
368
+ processor.execute(treeComplete);
369
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
370
+ queueableFns[0].fn(nodeDone);
371
+
372
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
373
+
374
+ expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
375
+ });
376
+
377
+ it("does not run beforeAlls or afterAlls for a node with no children", function() {
378
+ var node = new Node({
379
+ beforeAllFns: ['before'],
380
+ afterAllFns: ['after']
381
+ }),
382
+ root = new Node({ children: [node] }),
383
+ queueRunner = jasmine.createSpy('queueRunner'),
384
+ processor = new j$.TreeProcessor({
385
+ tree: root,
386
+ runnableIds: [node.id],
387
+ queueRunnerFactory: queueRunner
388
+ }),
389
+ treeComplete = jasmine.createSpy('treeComplete'),
390
+ nodeDone = jasmine.createSpy('nodeDone');
391
+
392
+ processor.execute(treeComplete);
393
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
394
+ queueableFns[0].fn(nodeDone);
395
+
396
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
397
+
398
+ expect(queueableFns).toEqual([]);
399
+ });
400
+
401
+ it("does not run beforeAlls or afterAlls for a disabled node", function() {
402
+ var leaf = new Leaf(),
403
+ node = new Node({
404
+ children: [leaf],
405
+ beforeAllFns: ['before'],
406
+ afterAllFns: ['after'],
407
+ executable: false
408
+ }),
409
+ root = new Node({ children: [node] }),
410
+ queueRunner = jasmine.createSpy('queueRunner'),
411
+ processor = new j$.TreeProcessor({
412
+ tree: root,
413
+ runnableIds: [node.id],
414
+ queueRunnerFactory: queueRunner
415
+ }),
416
+ treeComplete = jasmine.createSpy('treeComplete'),
417
+ nodeDone = jasmine.createSpy('nodeDone');
418
+
419
+ processor.execute(treeComplete);
420
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
421
+ queueableFns[0].fn(nodeDone);
422
+
423
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
424
+
425
+ expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }]);
426
+ });
427
+
428
+ it("runs leaves in the order specified", function() {
429
+ var leaf1 = new Leaf(),
430
+ leaf2 = new Leaf(),
431
+ root = new Node({ children: [leaf1, leaf2] }),
432
+ queueRunner = jasmine.createSpy('queueRunner'),
433
+ processor = new j$.TreeProcessor({
434
+ tree: root,
435
+ runnableIds: [leaf2.id, leaf1.id],
436
+ queueRunnerFactory: queueRunner
437
+ }),
438
+ treeComplete = jasmine.createSpy('treeComplete');
439
+
440
+ processor.execute(treeComplete);
441
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
442
+ queueableFns[0].fn();
443
+
444
+ expect(leaf1.execute).not.toHaveBeenCalled();
445
+ expect(leaf2.execute).toHaveBeenCalled();
446
+
447
+ queueableFns[1].fn();
448
+
449
+ expect(leaf1.execute).toHaveBeenCalled();
450
+ });
451
+
452
+ it("runs specified leaves before non-specified leaves", function() {
453
+ var specified = new Leaf(),
454
+ nonSpecified = new Leaf(),
455
+ root = new Node({ children: [nonSpecified, specified] }),
456
+ queueRunner = jasmine.createSpy('queueRunner'),
457
+ processor = new j$.TreeProcessor({
458
+ tree: root,
459
+ runnableIds: [specified.id],
460
+ queueRunnerFactory: queueRunner
461
+ }),
462
+ treeComplete = jasmine.createSpy('treeComplete');
463
+
464
+ processor.execute(treeComplete);
465
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
466
+ queueableFns[0].fn();
467
+
468
+ expect(nonSpecified.execute).not.toHaveBeenCalled();
469
+ expect(specified.execute).toHaveBeenCalledWith(undefined, true);
470
+
471
+ queueableFns[1].fn();
472
+
473
+ expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, false);
474
+ });
475
+
476
+ it("runs nodes and leaves with a specified order", function() {
477
+ var specifiedLeaf = new Leaf(),
478
+ childLeaf = new Leaf(),
479
+ specifiedNode = new Node({ children: [childLeaf] }),
480
+ root = new Node({ children: [specifiedLeaf, specifiedNode] }),
481
+ queueRunner = jasmine.createSpy('queueRunner'),
482
+ processor = new j$.TreeProcessor({
483
+ tree: root,
484
+ runnableIds: [specifiedNode.id, specifiedLeaf.id],
485
+ queueRunnerFactory: queueRunner
486
+ });
487
+
488
+ processor.execute();
489
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
490
+ queueableFns[0].fn();
491
+
492
+ expect(specifiedLeaf.execute).not.toHaveBeenCalled();
493
+ var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
494
+ nodeQueueableFns[0].fn();
495
+
496
+ expect(childLeaf.execute).toHaveBeenCalled();
497
+
498
+ queueableFns[1].fn();
499
+
500
+ expect(specifiedLeaf.execute).toHaveBeenCalled();
501
+ });
502
+
503
+ it("runs a node multiple times if the order specified leaves and re-enters it", function() {
504
+ var leaf1 = new Leaf(),
505
+ leaf2 = new Leaf(),
506
+ leaf3 = new Leaf(),
507
+ leaf4 = new Leaf(),
508
+ leaf5 = new Leaf(),
509
+ reentered = new Node({ children: [leaf1, leaf2, leaf3] }),
510
+ root = new Node({ children: [reentered, leaf4, leaf5] }),
511
+ queueRunner = jasmine.createSpy('queueRunner'),
512
+ processor = new j$.TreeProcessor({
513
+ tree: root,
514
+ runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
515
+ queueRunnerFactory: queueRunner
516
+ });
517
+
518
+ processor.execute();
519
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
520
+ expect(queueableFns.length).toBe(5);
521
+
522
+ queueableFns[0].fn();
523
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
524
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
525
+ expect(leaf1.execute).toHaveBeenCalled();
526
+
527
+ queueableFns[1].fn();
528
+ expect(leaf4.execute).toHaveBeenCalled();
529
+
530
+ queueableFns[2].fn();
531
+ expect(queueRunner.calls.count()).toBe(3);
532
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
533
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
534
+ expect(leaf2.execute).toHaveBeenCalled();
535
+
536
+ queueableFns[3].fn();
537
+ expect(leaf5.execute).toHaveBeenCalled();
538
+
539
+ queueableFns[4].fn();
540
+ expect(queueRunner.calls.count()).toBe(4);
541
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
542
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
543
+ expect(leaf3.execute).toHaveBeenCalled();
544
+ });
545
+
546
+ it("runs a parent of a node with segments correctly", function() {
547
+ var leaf1 = new Leaf(),
548
+ leaf2 = new Leaf(),
549
+ leaf3 = new Leaf(),
550
+ leaf4 = new Leaf(),
551
+ leaf5 = new Leaf(),
552
+ parent = new Node({ children: [leaf1, leaf2, leaf3] }),
553
+ grandparent = new Node({ children: [parent] }),
554
+ root = new Node({ children: [grandparent, leaf4, leaf5] }),
555
+ queueRunner = jasmine.createSpy('queueRunner'),
556
+ processor = new j$.TreeProcessor({
557
+ tree: root,
558
+ runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
559
+ queueRunnerFactory: queueRunner
560
+ });
561
+
562
+ processor.execute();
563
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
564
+ expect(queueableFns.length).toBe(5);
565
+
566
+ queueableFns[0].fn();
567
+ expect(queueRunner.calls.count()).toBe(2);
568
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
569
+
570
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
571
+ expect(queueRunner.calls.count()).toBe(3);
572
+
573
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
574
+ expect(leaf1.execute).toHaveBeenCalled();
575
+
576
+ queueableFns[1].fn();
577
+ expect(leaf4.execute).toHaveBeenCalled();
578
+
579
+ queueableFns[2].fn();
580
+ expect(queueRunner.calls.count()).toBe(4);
581
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
582
+
583
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
584
+ expect(queueRunner.calls.count()).toBe(5);
585
+
586
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
587
+ expect(leaf2.execute).toHaveBeenCalled();
588
+
589
+ queueableFns[3].fn();
590
+ expect(leaf5.execute).toHaveBeenCalled();
591
+
592
+ queueableFns[4].fn();
593
+ expect(queueRunner.calls.count()).toBe(6);
594
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
595
+
596
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
597
+ expect(queueRunner.calls.count()).toBe(7);
598
+
599
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
600
+ expect(leaf3.execute).toHaveBeenCalled();
601
+ });
602
+
603
+ it("runs nodes in the order they were declared", function() {
604
+ var leaf1 = new Leaf(),
605
+ leaf2 = new Leaf(),
606
+ leaf3 = new Leaf(),
607
+ parent = new Node({ children: [leaf2, leaf3] }),
608
+ root = new Node({ children: [leaf1, parent] }),
609
+ queueRunner = jasmine.createSpy('queueRunner'),
610
+ processor = new j$.TreeProcessor({
611
+ tree: root,
612
+ runnableIds: [root.id],
613
+ queueRunnerFactory: queueRunner
614
+ });
615
+
616
+ processor.execute();
617
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
618
+ expect(queueableFns.length).toBe(2);
619
+
620
+ queueableFns[0].fn();
621
+ expect(leaf1.execute).toHaveBeenCalled();
622
+
623
+ queueableFns[1].fn();
624
+
625
+ var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
626
+ expect(childFns.length).toBe(2);
627
+ childFns[0].fn();
628
+ expect(leaf2.execute).toHaveBeenCalled();
629
+
630
+ childFns[1].fn();
631
+ expect(leaf3.execute).toHaveBeenCalled();
632
+ });
633
+ });