-
Notifications
You must be signed in to change notification settings - Fork 176
/
RouteModel.spec.js
1450 lines (1130 loc) · 66 KB
/
RouteModel.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ava from 'ava';
import sinon from 'sinon';
import * as _every from 'lodash/every';
import * as _isArray from 'lodash/isArray';
import * as _isEmpty from 'lodash/isEmpty';
import * as _map from 'lodash/map';
import LegModel from '../../../src/assets/scripts/client/aircraft/FlightManagementSystem/LegModel';
import RouteModel from '../../../src/assets/scripts/client/aircraft/FlightManagementSystem/RouteModel';
import WaypointModel from '../../../src/assets/scripts/client/aircraft/FlightManagementSystem/WaypointModel';
import AirportModel from '../../../src/assets/scripts/client/airport/AirportModel';
import {
createNavigationLibraryFixture,
resetNavigationLibraryFixture
} from '../../fixtures/navigationLibraryFixtures';
import { createAirportModelFixture } from '../../fixtures/airportFixtures';
const complexRouteStringMock = 'KLAS07R.BOACH6.TNP..OAL..MLF..PGS.TYSSN4.KLAS07R';
const singleFixRouteStringMock = 'DVC';
const singleDirectSegmentRouteStringMock = 'OAL..MLF';
const multiDirectSegmentRouteStringMock = 'OAL..MLF..PGS';
const singleSidProcedureSegmentRouteStringMock = 'KLAS07R.BOACH6.TNP';
const singleStarProcedureSegmentRouteStringMock = 'TNP.KEPEC3.KLAS07R';
const multiProcedureSegmentRouteStringMock = 'KLAS07R.BOACH6.TNP.KEPEC3.KLAS07R';
const nightmareRouteStringMock = 'TNP.KEPEC3.KLAS07R.BOACH6.TNP..OAL..PGS.TYSSN4.KLAS07R.BOACH6.TNP..GUP..IGM';
ava.beforeEach(() => {
createNavigationLibraryFixture();
});
ava.afterEach(() => {
resetNavigationLibraryFixture();
});
ava('throws when instantiated without valid parameters', (t) => {
t.throws(() => new RouteModel());
t.throws(() => new RouteModel(false));
});
ava('throws when instantiated with route string containing spaces', (t) => {
t.throws(() => new RouteModel('KLAS07R BOACH6 TNP'));
});
ava('does not throw when instantiated with valid parameters', (t) => {
t.notThrows(() => new RouteModel(complexRouteStringMock));
});
ava('instantiates correctly when provided valid single-fix route string', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 1);
});
ava('instantiates correctly when provided valid single-segment direct route string', (t) => {
const model = new RouteModel(singleDirectSegmentRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 2);
});
ava('instantiates correctly when provided valid single-segment procedural route string', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 1);
t.true(model._legCollection[0]._waypointCollection.length === 8);
});
ava('instantiates correctly when provided valid multi-segment direct route string', (t) => {
const model = new RouteModel(multiDirectSegmentRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 3);
});
ava('instantiates correctly when provided valid multi-segment procedural route string', (t) => {
const model = new RouteModel(multiProcedureSegmentRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 2);
t.true(model._legCollection[0]._waypointCollection.length === 8);
t.true(model._legCollection[1]._waypointCollection.length === 13);
});
ava('instantiates correctly when provided valid multi-segment mixed route string', (t) => {
const model = new RouteModel(complexRouteStringMock);
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 4);
t.true(model._legCollection[0]._waypointCollection.length === 8);
t.true(model._legCollection[1]._waypointCollection.length === 1);
t.true(model._legCollection[2]._waypointCollection.length === 1);
t.true(model._legCollection[3]._waypointCollection.length === 6);
});
ava('#currentLeg throws when #_legCollection does not contain at least one leg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
model._legCollection = [];
t.throws(() => model.currentLeg);
});
ava('#currentLeg returns the first element of the #_legCollection', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.currentLeg;
t.true(result instanceof LegModel);
t.true(result.routeString === singleFixRouteStringMock);
});
ava('#legCollection returns the entire #_legCollection', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const expectedResult = model._legCollection;
const result = model.legCollection;
t.deepEqual(result, expectedResult);
});
ava('#currentWaypoint returns the #currentWaypoint on the #currentLeg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const expectedResult = model.currentLeg.currentWaypoint;
const result = model.currentWaypoint;
t.deepEqual(result, expectedResult);
});
ava('#nextLeg returns null when there are no more legs after the current leg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.nextLeg;
t.true(!result);
});
ava('#nextLeg returns the second element of the #_legCollection when it exists', (t) => {
const model = new RouteModel(singleDirectSegmentRouteStringMock);
const result = model.nextLeg;
t.true(result instanceof LegModel);
t.true(result.routeString === 'MLF');
});
ava('#nextWaypoint returns null when there are no more waypoints after the current waypoint', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.nextWaypoint;
t.true(!result);
});
ava('#nextWaypoint returns next waypoint of the current leg when the current leg has another waypoint', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
const result = model.nextWaypoint;
t.true(result instanceof WaypointModel);
t.true(result.name === 'JOTNU');
});
ava('#nextWaypoint returns the first waypoint of the next leg when a nextLeg exists and the current leg does not contain more waypoints', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('PRINO');
const result = model.nextWaypoint;
t.true(result instanceof WaypointModel);
t.true(result.name === 'JESJI');
});
ava('#waypoints returns an array containing the `WaypointModel`s of all legs', (t) => {
const model = new RouteModel(complexRouteStringMock);
const result = model.waypoints;
const expectedWaypointNames = ['JESJI', 'BAKRR', 'MINEY', 'HITME', 'BOACH', 'ZELMA',
'JOTNU', 'TNP', 'OAL', 'MLF', 'PGS', 'CEJAY', 'KADDY', 'TYSSN', 'SUZSI', 'PRINO'
];
const waypointNames = _map(result, (waypointModel) => waypointModel.name);
t.true(_isArray(result));
t.deepEqual(waypointNames, expectedWaypointNames);
});
ava('.absorbRouteModel() returns no-continuity message when routes have no common fixes', (t) => {
const primaryModel = new RouteModel('CLARR..SKEBR..MDDOG..IPUMY');
const otherModel = new RouteModel('BOACH..CRESO..BLD');
const expectedResult = [false, 'routes do not have continuity!'];
const result = primaryModel.absorbRouteModel(otherModel);
t.deepEqual(result, expectedResult);
});
ava('.absorbRouteModel() calls ._overwriteRouteBetweenWaypointNames() when provided route has two points of continuity with this route', (t) => {
const primaryModel = new RouteModel('CLARR..SKEBR..MDDOG..IPUMY..TOMIS..LEMNZ..LOOSN');
const otherModel = new RouteModel('MDDOG..JEBBB..BESSY..LEMNZ');
const primaryModelOverwriteRouteBetweenWaypointNamesSpy = sinon.spy(primaryModel, '_overwriteRouteBetweenWaypointNames');
const expectedResult = [true, { log: 'rerouting to: CLARR SKEBR MDDOG JEBBB BESSY LEMNZ LOOSN', say: 'rerouting as requested' }];
const result = primaryModel.absorbRouteModel(otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelOverwriteRouteBetweenWaypointNamesSpy.calledWithExactly('MDDOG', 'LEMNZ', otherModel));
});
ava('.absorbRouteModel() calls ._prependRouteModelEndingAtWaypointName() when provided route ends on a waypoint on this route', (t) => {
const primaryModel = new RouteModel('CHRLT.V394.LAS');
const otherModel = new RouteModel('GFS..WHIGG..CLARR');
const primaryModelPrependRouteModelEndingAtWaypointNameSpy = sinon.spy(primaryModel, '_prependRouteModelEndingAtWaypointName');
const expectedResult = [true, { log: 'rerouting to: GFS WHIGG CLARR V394 LAS', say: 'rerouting as requested' }];
const result = primaryModel.absorbRouteModel(otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelPrependRouteModelEndingAtWaypointNameSpy.calledWithExactly('CLARR', otherModel));
});
ava('.absorbRouteModel() calls ._appendRouteModelBeginningAtWaypointName() when provided route that begins on a waypoint on this route', (t) => {
const primaryModel = new RouteModel('DAG.V394.LAS');
const otherModel = new RouteModel('CLARR..TRREY..SOSOY');
const primaryModelAppendRouteModelBeginningAtWaypointNameSpy = sinon.spy(primaryModel, '_appendRouteModelBeginningAtWaypointName');
const expectedResult = [true, { log: 'rerouting to: DAG V394 CLARR TRREY SOSOY', say: 'rerouting as requested' }];
const result = primaryModel.absorbRouteModel(otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelAppendRouteModelBeginningAtWaypointNameSpy.calledWithExactly('CLARR', otherModel));
});
ava('.activateHoldForWaypointName() returns early when the specified waypoint does not exist in the route', (t) => {
const model = new RouteModel('DAG..KEPEC');
const legModel1 = model._legCollection[0];
const legModel2 = model._legCollection[1];
const activateHoldForWaypointNameSpy1 = sinon.spy(legModel1, 'activateHoldForWaypointName');
const activateHoldForWaypointNameSpy2 = sinon.spy(legModel2, 'activateHoldForWaypointName');
const holdParametersMock = { turnDirection: 'left' };
const result = model.activateHoldForWaypointName('PRINO', holdParametersMock);
t.true(typeof result === 'undefined');
t.true(activateHoldForWaypointNameSpy1.notCalled);
t.true(activateHoldForWaypointNameSpy2.notCalled);
});
ava('.activateHoldForWaypointName() calls LegModel.activateHoldForWaypointName() with the appropriate arguments on the appropriate leg', (t) => {
const model = new RouteModel('DAG..KEPEC');
const legModel1 = model._legCollection[0];
const legModel2 = model._legCollection[1];
const activateHoldForWaypointNameSpy1 = sinon.spy(legModel1, 'activateHoldForWaypointName');
const activateHoldForWaypointNameSpy2 = sinon.spy(legModel2, 'activateHoldForWaypointName');
const holdParametersMock = { turnDirection: 'left' };
const result = model.activateHoldForWaypointName('KEPEC', holdParametersMock);
t.true(typeof result === 'undefined');
t.true(activateHoldForWaypointNameSpy1.notCalled);
t.true(activateHoldForWaypointNameSpy2.calledWithExactly('KEPEC', holdParametersMock));
});
ava('._createLegModelsFromWaypointModels() returns an array of LegModels matching the specified array of WaypointModels', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R');
model.skipToWaypointName('KIMME');
const result = model._createLegModelsFromWaypointModels(model.currentLeg._waypointCollection);
const expectedWaypointNames = ['KIMME', 'CHIPZ', 'POKRR', 'PRINO'];
const waypointNames = result.map((legModel) => legModel.routeString);
t.true(_isArray(result));
t.true(_every(result, (legModel) => legModel instanceof LegModel));
t.deepEqual(waypointNames, expectedWaypointNames);
});
ava('.getAltitudeRestrictedWaypoints() returns an array of WaypointModels that have altitude restrictions', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.getAltitudeRestrictedWaypoints();
const expectedWaypointNames = ['BAKRR', 'MINEY', 'BOACH'];
const waypointNames = result.map((waypoint) => waypoint.name);
const allWaypointsHaveRestrictions = _every(result, (waypoint) => waypoint.hasAltitudeRestriction);
t.deepEqual(waypointNames, expectedWaypointNames);
t.true(allWaypointsHaveRestrictions);
});
ava('.getArrivalRunwayAirportIcao() returns null if there is no STAR leg', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getArrivalRunwayAirportIcao();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayAirportIcao() returns the appropriate runway\'s airport\'s ICAO identifier', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R');
const expectedResult = 'klas';
const result = model.getArrivalRunwayAirportIcao();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayAirportModel() returns null when there is no STAR leg', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getArrivalRunwayAirportModel();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayAirportModel() returns the appropriate runway\'s AirportModel', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R');
const expectedAirportIcao = 'klas';
const result = model.getArrivalRunwayAirportModel();
t.true(result instanceof AirportModel);
t.true(result.icao === expectedAirportIcao);
});
ava('.getArrivalRunwayName() returns null when there is no STAR leg', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getArrivalRunwayName();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayName() returns the appropriate runway name', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R');
const expectedResult = '07R';
const result = model.getArrivalRunwayName();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayModel() returns null when there is no STAR leg', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getArrivalRunwayModel();
t.true(result === expectedResult);
});
ava('.getArrivalRunwayModel() returns the appropriate RunwayModel', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R');
const expectedRunwayName = '07R';
const result = model.getArrivalRunwayModel();
t.true(result.name === expectedRunwayName);
});
ava('.getBottomAltitude() returns -1 when there is no bottom altitude in the route', (t) => {
const model = new RouteModel(singleDirectSegmentRouteStringMock);
const expectedResult = -1;
const result = model.getBottomAltitude();
t.true(result === expectedResult);
});
ava('.getBottomAltitude() returns the lowest #altitudeMinimum of any LegModel in the #_legCollection', (t) => {
const model = new RouteModel('TNP.KEPEC3.KLAS07R..DRK.ZIMBO1.KLAS07R');
const expectedResult = 6000;
const result = model.getBottomAltitude();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayAirportIcao() returns null if there is no SID leg', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getDepartureRunwayAirportIcao();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayAirportIcao() returns the appropriate runway\'s airport\'s ICAO identifier', (t) => {
const model = new RouteModel('KLAS07R.BOACH6.TNP');
const expectedResult = 'klas';
const result = model.getDepartureRunwayAirportIcao();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayAirportModel() returns null when there is no SID leg', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getDepartureRunwayAirportModel();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayAirportModel() returns the appropriate runway\'s AirportModel', (t) => {
const model = new RouteModel('KLAS07R.BOACH6.TNP');
const expectedAirportIcao = 'klas';
const result = model.getDepartureRunwayAirportModel();
t.true(result instanceof AirportModel);
t.true(result.icao === expectedAirportIcao);
});
ava('.getDepartureRunwayName() returns null when there is no SID leg', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getDepartureRunwayName();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayName() returns the appropriate runway name', (t) => {
const model = new RouteModel('KLAS07R.BOACH6.TNP');
const expectedResult = '07R';
const result = model.getDepartureRunwayName();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayModel() returns null when there is no SID leg', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const expectedResult = null;
const result = model.getDepartureRunwayModel();
t.true(result === expectedResult);
});
ava('.getDepartureRunwayModel() returns the appropriate RunwayModel', (t) => {
const model = new RouteModel('KLAS07R.BOACH6.TNP');
const expectedRunwayName = '07R';
const result = model.getDepartureRunwayModel();
t.true(result.name === expectedRunwayName);
});
ava('.getFullRouteString() returns a route string for the entire route, including past legs, in dot notation', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('GUP');
const result = model.getFullRouteString();
t.true(result === nightmareRouteStringMock);
});
ava('.getFullRouteStringWithoutAirportsWithSpaces() returns the full route string, with airports removed, with spaces', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('GUP');
const expectedResult = 'TNP KEPEC3 BOACH6 TNP OAL PGS TYSSN4 BOACH6 TNP GUP IGM';
const result = model.getFullRouteStringWithoutAirportsWithSpaces();
t.true(result === expectedResult);
});
ava('.getFullRouteStringWithSpaces() returns a route string for the entire route, including past legs, separated by spaces', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('GUP');
const expectedResult = 'TNP KEPEC3 KLAS07R BOACH6 TNP OAL PGS TYSSN4 KLAS07R BOACH6 TNP GUP IGM';
const result = model.getFullRouteStringWithSpaces();
t.true(result === expectedResult);
});
ava('.getRouteString() returns a route string for the remaining legs only, in dot notation', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('GUP');
const result = model.getRouteString();
t.true(result === 'GUP..IGM');
});
ava('.getRouteStringWithSpaces() returns a route string for the remaining legs only, separated by spaces', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
model.skipToWaypointName('GUP');
const result = model.getRouteStringWithSpaces();
t.true(result === 'GUP IGM');
});
ava('.getSidIcao() returns undefined when there is no SID leg in the route', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const result = model.getSidIcao();
t.true(typeof result === 'undefined');
});
ava('.getSidIcao() returns the ICAO identifier for the SID procedure in the route', (t) => {
const model = new RouteModel(complexRouteStringMock);
const result = model.getSidIcao();
t.true(result === 'BOACH6');
});
ava('.getSidName() returns undefined when there is no SID leg in the route', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const result = model.getSidName();
t.true(typeof result === 'undefined');
});
ava('.getSidName() returns the spoken name of the SID procedure in the route', (t) => {
const model = new RouteModel(complexRouteStringMock);
const result = model.getSidName();
t.true(result === 'Boach Six');
});
ava('.getStarIcao() returns undefined when there is no STAR leg in the route', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.getStarIcao();
t.true(typeof result === 'undefined');
});
ava('.getStarIcao() returns the ICAO identifier for the STAR procedure in the route', (t) => {
const model = new RouteModel(complexRouteStringMock);
const result = model.getStarIcao();
t.true(result === 'TYSSN4');
});
ava('.getStarName() returns undefined when there is no STAR leg in the route', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.getStarName();
t.true(typeof result === 'undefined');
});
ava('.getStarName() returns the spoken name of the STAR procedure in the route', (t) => {
const model = new RouteModel(complexRouteStringMock);
const result = model.getStarName();
t.true(result === 'Tyson Four');
});
ava('.getTopAltitude() returns -1 when there is no top altitude in the route', (t) => {
const model = new RouteModel(singleDirectSegmentRouteStringMock);
const expectedResult = -1;
const result = model.getTopAltitude();
t.true(result === expectedResult);
});
ava('.getTopAltitude() returns the highest #altitudeMaximum of any LegModel in the #_legCollection', (t) => {
const model = new RouteModel('KLAS25R.BOACH6.HEC..KLAS25R.SHEAD9.KENNO');
const expectedResult = 11000;
const result = model.getTopAltitude();
t.true(result === expectedResult);
});
ava('.hasNextLeg() returns false when the current leg is the last in the #_legCollection', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.hasNextLeg();
t.false(result);
});
ava('.hasNextLeg() returns true when there is a leg in the #_legCollection after the current leg', (t) => {
const model = new RouteModel(nightmareRouteStringMock);
const result = model.hasNextLeg();
t.true(result);
});
ava('.hasNextWaypoint() returns false when we are at the last waypoint of the last leg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.hasNextWaypoint();
t.false(result);
});
ava('.hasNextWaypoint() returns true when the current leg contains more waypoints', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.hasNextWaypoint();
t.true(result);
});
ava('.hasNextWaypoint() returns true when we are at the last waypoint of a leg that is not the last leg', (t) => {
const model = new RouteModel(multiDirectSegmentRouteStringMock);
const result = model.hasNextWaypoint();
t.true(result);
});
ava('.hasWaypointName() returns false when the specified waypoint is not in the route', (t) => {
const model = new RouteModel('DVC');
const result = model.hasWaypointName('MLF');
t.false(result);
});
ava('.hasWaypointName() returns true when the specified waypoint is in the route', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const result = model.hasWaypointName('ZELMA');
t.true(result);
});
ava('.isRunwayModelValidForSid() returns false if passed runway is not an instance of RunwayModel', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('00');
const result = model.isRunwayModelValidForSid(runwayModel);
t.false(result);
});
ava('.isRunwayModelValidForSid() returns true if the flight plan does not contain a SID', (t) => {
const model = new RouteModel(multiDirectSegmentRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('01R');
const result = model.isRunwayModelValidForSid(runwayModel);
t.true(result);
});
ava('.isRunwayModelValidForSid() returns false if the specified runway exists and is not valid for the assigned SID', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('01R');
const result = model.isRunwayModelValidForSid(runwayModel);
t.false(result);
});
ava('.isRunwayModelValidForSid() returns true if the specified runway exists and is valid for the assigned SID', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('25R');
const result = model.isRunwayModelValidForSid(runwayModel);
t.true(result);
});
ava('.isRunwayModelValidForStar() returns false if passed runway is not an instance of RunwayModel', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('00');
const result = model.isRunwayModelValidForStar(runwayModel);
t.false(result);
});
ava('.isRunwayModelValidForStar() returns true if the flight plan does not contain a STAR', (t) => {
const model = new RouteModel(multiDirectSegmentRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('01R');
const result = model.isRunwayModelValidForStar(runwayModel);
t.true(result);
});
ava('.isRunwayModelValidForStar() returns false if the specified runway exists and is not valid for the assigned STAR', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('01R');
const result = model.isRunwayModelValidForStar(runwayModel);
t.false(result);
});
ava('.isRunwayModelValidForStar() returns true if the specified runway exists and is valid for the assigned STAR', (t) => {
const model = new RouteModel(complexRouteStringMock);
const airportModel = createAirportModelFixture();
const runwayModel = airportModel.getRunway('25R');
const result = model.isRunwayModelValidForStar(runwayModel);
t.true(result);
});
ava('.moveToNextWaypoint() calls #currentLeg.moveToNextWaypoint() when the current leg contains more waypoints', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const currentLegMoveToNextWaypointSpy = sinon.spy(model.currentLeg, 'moveToNextWaypoint');
model.moveToNextWaypoint();
t.true(currentLegMoveToNextWaypointSpy.calledWithExactly());
});
ava('.moveToNextWaypoint() calls .moveToNextLeg() when the current leg is at its last waypoint', (t) => {
const model = new RouteModel(multiDirectSegmentRouteStringMock);
const moveToNextLegSpy = sinon.spy(model, 'moveToNextLeg');
model.moveToNextWaypoint();
t.true(moveToNextLegSpy.calledWithExactly());
});
ava('.replaceArrivalProcedure() returns false when route string does not yield a valid leg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.replaceArrivalProcedure('gobbledeegook');
t.false(result);
t.true(model.waypoints.length === 1);
});
ava('.replaceArrivalProcedure() appends specified STAR leg as the new last leg when no STAR leg previously existed', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.replaceArrivalProcedure(singleStarProcedureSegmentRouteStringMock);
t.true(result);
t.true(model.getRouteString() === `${singleFixRouteStringMock}..${singleStarProcedureSegmentRouteStringMock}`);
});
ava('.replaceArrivalProcedure() replaces STAR leg with a new one when the route already has a STAR leg', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const differentStarRouteStringMock = 'TNP.KEPEC3.KLAS25L';
const result = model.replaceArrivalProcedure(differentStarRouteStringMock);
t.true(result);
t.true(model.getRouteString() === differentStarRouteStringMock);
});
ava('.replaceDepartureProcedure() returns false when route string does not yield a valid leg', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.replaceDepartureProcedure('gobbledeegook');
t.false(result);
t.true(model.waypoints.length === 1);
});
ava('.replaceDepartureProcedure() appends specified SID leg as the new first leg when no SID leg previously existed', (t) => {
const model = new RouteModel(singleFixRouteStringMock);
const result = model.replaceDepartureProcedure(singleSidProcedureSegmentRouteStringMock);
t.true(result);
t.true(model.getRouteString() === `${singleSidProcedureSegmentRouteStringMock}..${singleFixRouteStringMock}`);
});
ava('.replaceDepartureProcedure() replaces SID leg with a new one when the route already has a SID leg', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
const differentSidRouteStringMock = 'KLAS25L.BOACH6.TNP';
const result = model.replaceDepartureProcedure(differentSidRouteStringMock);
t.true(result);
t.true(model.getRouteString() === differentSidRouteStringMock);
});
ava('.moveToNextLeg() returns early when we are at the last leg in the route', (t) => {
const model = new RouteModel(singleSidProcedureSegmentRouteStringMock);
model.moveToNextLeg();
t.true(_isEmpty(model._previousLegCollection));
t.true(model._legCollection.length === 1);
});
ava('.moveToNextLeg() moves the #currentLeg from the #_legCollection to the #_previousLegCollection', (t) => {
const model = new RouteModel('OAL..TNP.KEPEC3.KLAS07R');
t.true(model._previousLegCollection.length === 0);
t.true(model._legCollection.length === 2);
model.moveToNextLeg();
t.true(model._previousLegCollection.length === 1);
t.true(model._previousLegCollection[0].routeString === 'OAL');
t.true(model._legCollection.length === 1);
t.true(model._legCollection[0].routeString === 'TNP.KEPEC3.KLAS07R');
});
ava('.skipToWaypointName() returns false when the specified waypoint is not in the route', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const result = model.skipToWaypointName('gobbledeegook');
t.false(result);
t.true(model._legCollection.length === 1);
});
ava('.skipToWaypointName() calls #currentLeg.skipToWaypointName() when current leg contains the specified waypoint', (t) => {
const model = new RouteModel(singleStarProcedureSegmentRouteStringMock);
const currentLegSkipToWaypointNameSpy = sinon.spy(model.currentLeg, 'skipToWaypointName');
const waypointNameToSkipTo = 'KEPEC';
model.skipToWaypointName(waypointNameToSkipTo);
t.true(currentLegSkipToWaypointNameSpy.calledWithExactly(waypointNameToSkipTo));
});
ava('.skipToWaypointName() moves appropriate legs/waypoints to previous collections when specified waypoint exists in a future leg', (t) => {
const model = new RouteModel('OAL..TNP.KEPEC3.KLAS07R');
model.skipToWaypointName('KEPEC');
t.true(model._previousLegCollection.length === 1);
t.true(model._previousLegCollection[0].routeString === 'OAL');
t.true(model._legCollection.length === 1);
t.true(model._legCollection[0].routeString === 'TNP.KEPEC3.KLAS07R');
t.true(model._legCollection[0]._waypointCollection.length === 8);
t.true(model._legCollection[0]._previousWaypointCollection.length === 5);
});
ava('.updateSidLegForDepartureRunwayModel() returns early when the route contains no SID leg to update', (t) => {
const routeModel = new RouteModel('OAL..TNP');
const airportModel = createAirportModelFixture();
const nextRunwayName = '25L';
const nextRunwayModel = airportModel.getRunway(nextRunwayName);
const sidLegUpdateSidRunwaySpy = sinon.spy(routeModel._legCollection[0], 'updateSidLegForDepartureRunwayModel');
routeModel.updateSidLegForDepartureRunwayModel(nextRunwayModel);
t.true(sidLegUpdateSidRunwaySpy.notCalled);
});
ava('.updateSidLegForDepartureRunwayModel() calls LegModel.updateStarLegForArrivalRunwayModel() on the SID leg', (t) => {
const routeModel = new RouteModel('KLAS07R.BOACH6.TNP');
const airportModel = createAirportModelFixture();
const nextRunwayName = '25L';
const nextRunwayModel = airportModel.getRunway(nextRunwayName);
const sidLegUpdateSidRunwaySpy = sinon.spy(routeModel._legCollection[0], 'updateSidLegForDepartureRunwayModel');
routeModel.updateSidLegForDepartureRunwayModel(nextRunwayModel);
t.true(sidLegUpdateSidRunwaySpy.calledWithExactly(nextRunwayModel));
});
ava('.updateStarLegForArrivalRunwayModel() returns early when the route contains no STAR leg to update', (t) => {
const routeModel = new RouteModel('OAL..TNP');
const airportModel = createAirportModelFixture();
const nextRunwayName = '25L';
const nextRunwayModel = airportModel.getRunway(nextRunwayName);
const createAmendedStarLegSpy = sinon.spy(routeModel, '_createAmendedStarLegUsingDifferentExitName');
const result = routeModel.updateStarLegForArrivalRunwayModel(nextRunwayModel);
t.true(createAmendedStarLegSpy.notCalled);
t.true(typeof result === 'undefined');
});
ava('.updateStarLegForArrivalRunwayModel() returns early when the runway is not valid for the current STAR', (t) => {
const routeModel = new RouteModel('DRK.ZIMBO1.KLAS07R');
const airportModel = createAirportModelFixture();
const nextRunwayName = '25L';
const nextRunwayModel = airportModel.getRunway(nextRunwayName);
const createAmendedStarLegSpy = sinon.spy(routeModel, '_createAmendedStarLegUsingDifferentExitName');
const result = routeModel.updateStarLegForArrivalRunwayModel(nextRunwayModel);
t.true(createAmendedStarLegSpy.notCalled);
t.true(typeof result === 'undefined');
});
ava('.updateStarLegForArrivalRunwayModel() replaces the STAR leg with a newly created one using the correct parameters', (t) => {
const routeModel = new RouteModel('TNP.KEPEC3.KLAS07R');
const airportModel = createAirportModelFixture();
const nextRunwayName = '25L';
const nextRunwayModel = airportModel.getRunway(nextRunwayName);
const createAmendedStarLegSpy = sinon.spy(routeModel, '_createAmendedStarLegUsingDifferentExitName');
const result = routeModel.updateStarLegForArrivalRunwayModel(nextRunwayModel);
t.true(createAmendedStarLegSpy.calledWithExactly('KLAS25L', 0));
t.true(typeof result === 'undefined');
});
ava('.reset() clears #_legCollection', (t) => {
const model = new RouteModel(complexRouteStringMock);
model.reset();
t.true(_isArray(model._legCollection));
t.true(model._legCollection.length === 0);
});
ava('._appendRouteModelBeginningAtWaypointName() throws when leg type is not airway/direct/SID/STAR', (t) => {
const primaryModel = new RouteModel('CLARR..SKEBR..MDDOG..IPUMY');
const otherModel = new RouteModel('SKEBR..CRESO..BLD');
primaryModel._legCollection[1]._legType = 'nonsensical';
t.throws(() => primaryModel._appendRouteModelBeginningAtWaypointName('SKEBR', otherModel));
});
ava('._appendRouteModelBeginningAtWaypointName() calls ._appendRouteModelOutOfAirwayLeg() when divergent leg is airway leg', (t) => {
const primaryModel = new RouteModel('DAG.V394.LAS');
const otherModel = new RouteModel('CLARR..TRREY..SOSOY');
const primaryModelAppendRouteModelOutOfAirwayLegSpy = sinon.spy(primaryModel, '_appendRouteModelOutOfAirwayLeg');
const expectedResult = [true, { log: 'rerouting to: DAG V394 CLARR TRREY SOSOY', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelBeginningAtWaypointName('CLARR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelAppendRouteModelOutOfAirwayLegSpy.calledWithExactly('CLARR', otherModel));
});
ava('._appendRouteModelBeginningAtWaypointName() calls ._appendRouteModelOutOfDirectLeg() when divergent leg is direct leg', (t) => {
const primaryModel = new RouteModel('CLARR..SKEBR..MDDOG..IPUMY');
const otherModel = new RouteModel('SKEBR..CRESO..BLD');
const primaryModelAppendRouteModelOutOfDirectLegSpy = sinon.spy(primaryModel, '_appendRouteModelOutOfDirectLeg');
const expectedResult = [true, { log: 'rerouting to: CLARR SKEBR CRESO BLD', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelBeginningAtWaypointName('SKEBR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelAppendRouteModelOutOfDirectLegSpy.calledWithExactly('SKEBR', otherModel));
});
ava('._appendRouteModelBeginningAtWaypointName() calls ._appendRouteModelOutOfSidLeg() when divergent leg is SID leg', (t) => {
const primaryModel = new RouteModel('KLAS07R.BOACH6.HEC');
const otherModel = new RouteModel('BOACH..SKEBR..TARRK');
const primaryModelAppendRouteModelOutOfSidLegSpy = sinon.spy(primaryModel, '_appendRouteModelOutOfSidLeg');
const expectedResult = [true, { log: 'rerouting to: JESJI BAKRR MINEY HITME BOACH SKEBR TARRK', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelBeginningAtWaypointName('BOACH', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelAppendRouteModelOutOfSidLegSpy.calledWithExactly('BOACH', otherModel));
});
ava('._appendRouteModelBeginningAtWaypointName() calls ._appendRouteModelOutOfStarLeg() when divergent leg is STAR leg', (t) => {
const primaryModel = new RouteModel('DVC.GRNPA1.KLAS07R');
const otherModel = new RouteModel('LUXOR..WINDS..CRESO');
const primaryModelAppendRouteModelOutOfStarLegSpy = sinon.spy(primaryModel, '_appendRouteModelOutOfStarLeg');
const expectedResult = [true, { log: 'rerouting to: DVC BETHL HOLDM KSINO LUXOR WINDS CRESO', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelBeginningAtWaypointName('LUXOR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModelAppendRouteModelOutOfStarLegSpy.calledWithExactly('LUXOR', otherModel));
});
ava('._appendRouteModelOutOfAirwayLeg() correctly places RouteModel and adjusts airway exit', (t) => {
const primaryModel = new RouteModel('DAG.V394.LAS');
const otherModel = new RouteModel('CLARR..TRREY..SOSOY');
const expectedResult = [true, { log: 'rerouting to: DAG V394 CLARR TRREY SOSOY', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelOutOfAirwayLeg('CLARR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModel._legCollection.length === 4);
t.true(primaryModel._legCollection[0].routeString === 'DAG.V394.CLARR');
t.true(primaryModel._legCollection[1].routeString === 'CLARR');
t.true(primaryModel._legCollection[2].routeString === 'TRREY');
t.true(primaryModel._legCollection[3].routeString === 'SOSOY');
});
ava('._appendRouteModelOutOfDirectLeg() correctly places RouteModel', (t) => {
const primaryModel = new RouteModel('CLARR..SKEBR..MDDOG..IPUMY');
const otherModel = new RouteModel('SKEBR..CRESO..BLD');
const expectedResult = [true, { log: 'rerouting to: CLARR SKEBR CRESO BLD', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelOutOfDirectLeg('SKEBR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModel._legCollection.length === 4);
t.true(primaryModel._legCollection[0].routeString === 'CLARR');
t.true(primaryModel._legCollection[1].routeString === 'SKEBR');
t.true(primaryModel._legCollection[2].routeString === 'CRESO');
t.true(primaryModel._legCollection[3].routeString === 'BLD');
});
ava('._appendRouteModelOutOfSidLeg() correctly places RouteModel and explodes remaining SID waypoints into legs', (t) => {
const primaryModel = new RouteModel('KLAS07R.BOACH6.HEC');
const otherModel = new RouteModel('BOACH..SKEBR..TARRK');
const expectedResult = [true, { log: 'rerouting to: JESJI BAKRR MINEY HITME BOACH SKEBR TARRK', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelOutOfSidLeg('BOACH', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModel._legCollection.length === 7);
t.true(primaryModel._legCollection[0].routeString === 'JESJI');
t.true(primaryModel._legCollection[1].routeString === 'BAKRR');
t.true(primaryModel._legCollection[2].routeString === 'MINEY');
t.true(primaryModel._legCollection[3].routeString === 'HITME');
t.true(primaryModel._legCollection[4].routeString === 'BOACH');
t.true(primaryModel._legCollection[5].routeString === 'SKEBR');
t.true(primaryModel._legCollection[6].routeString === 'TARRK');
});
ava('._appendRouteModelOutOfStarLeg() correctly places RouteModel and changes STAR exit when divergent fix is a valid exit', (t) => {
const primaryModel = new RouteModel('BCE.GRNPA1.KLAS07R');
const otherModel = new RouteModel('DUBLX..PRINO..RELIN');
const expectedResult = [true, { log: 'rerouting to: BCE GRNPA1 DUBLX PRINO RELIN', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelOutOfStarLeg('DUBLX', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModel._legCollection.length === 4);
t.true(primaryModel._legCollection[0].routeString === 'BCE.GRNPA1.DUBLX');
t.true(primaryModel._legCollection[1].routeString === 'DUBLX');
t.true(primaryModel._legCollection[2].routeString === 'PRINO');
t.true(primaryModel._legCollection[3].routeString === 'RELIN');
});
ava('._appendRouteModelOutOfStarLeg() correctly places RouteModel and explodes remaining STAR waypoints into legs', (t) => {
const primaryModel = new RouteModel('DVC.GRNPA1.KLAS07R');
const otherModel = new RouteModel('LUXOR..WINDS..CRESO');
const expectedResult = [true, { log: 'rerouting to: DVC BETHL HOLDM KSINO LUXOR WINDS CRESO', say: 'rerouting as requested' }];
const result = primaryModel._appendRouteModelOutOfStarLeg('LUXOR', otherModel);
t.deepEqual(result, expectedResult);
t.true(primaryModel._legCollection.length === 7);
t.true(primaryModel._legCollection[0].routeString === 'DVC');
t.true(primaryModel._legCollection[1].routeString === 'BETHL');
t.true(primaryModel._legCollection[2].routeString === 'HOLDM');
t.true(primaryModel._legCollection[3].routeString === 'KSINO');
t.true(primaryModel._legCollection[4].routeString === 'LUXOR');
t.true(primaryModel._legCollection[5].routeString === 'WINDS');
t.true(primaryModel._legCollection[6].routeString === 'CRESO');
});
ava.todo('._combineRouteStrings()');
ava('._createAmendedAirwayLegUsingDifferentEntryName() returns a new LegModel with the same airway and exit, with new specified entry', (t) => {
const model = new RouteModel('CHRLT.V394.LAS');
const nextEntryFixName = 'CLARR';
const legIndex = 0;
const result = model._createAmendedAirwayLegUsingDifferentEntryName(nextEntryFixName, legIndex);
t.true(result instanceof LegModel);
t.true(result.routeString === 'CLARR.V394.LAS');
});
ava('._createAmendedAirwayLegUsingDifferentExitName() returns a new LegModel with same airway and entry, with new specified exit', (t) => {