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
|
import actions from '../../../app/javascript/vehicle_journeys/actions/index'
import _ from 'lodash'
window._ = _
const dispatch = function(){}
window.fetch = function(){return Promise.resolve()}
const currentPage = 1
describe('when cannot fetch api', () => {
it('should create an action to toggle error', () => {
const expectedAction = {
type: 'UNAVAILABLE_SERVER',
}
expect(actions.unavailableServer()).toEqual(expectedAction)
})
})
describe('when fetching api', () => {
it('should create an action to fetch api', () => {
const expectedAction = {
type: 'FETCH_API',
}
expect(actions.fetchingApi()).toEqual(expectedAction)
})
})
describe('when receiveJourneyPatterns is triggered', () => {
it('should create an action to pass json to reducer', () => {
const json = undefined
const expectedAction = {
type: 'RECEIVE_VEHICLE_JOURNEYS',
json
}
expect(actions.receiveVehicleJourneys()).toEqual(expectedAction)
})
})
describe('when clicking on add button', () => {
it('should create an action to open a create modal', () => {
const expectedAction = {
type: 'CREATE_VEHICLEJOURNEY_MODAL',
}
expect(actions.openCreateModal()).toEqual(expectedAction)
})
})
describe('when validating the form', () => {
it('should check that non-commercial stops have passing time', () => {
let state = [{
vehicle_journey_at_stops: [{
area_kind: "non_commercial",
departure_time: {
hour: "00",
minute: "00"
}
}]
}]
expect(actions.validate(dispatch, state)).toEqual(true)
state = [{
vehicle_journey_at_stops: [{
area_kind: "non_commercial",
departure_time: {
hour: "00",
minute: "01"
}
}]
}]
expect(actions.validate(dispatch, state)).toEqual(true)
})
it('should not check that commercial stops', () => {
let state = [{
vehicle_journey_at_stops: [{
area_kind: "commercial",
departure_time: {
hour: "00",
minute: "00"
}
}]
}]
expect(actions.validate(dispatch, state)).toEqual(true)
})
})
describe('when using select2 to pick a journey pattern', () => {
it('should create an action to select a journey pattern inside modal', () => {
let selectedJP = {
id: 1,
object_id: 2,
short_id: 2,
name: 'test',
published_name: 'test',
stop_area_short_descriptions: ['test']
}
const expectedAction = {
type: 'SELECT_JP_CREATE_MODAL',
selectedItem:{
id: selectedJP.id,
objectid: selectedJP.object_id,
object_id: selectedJP.object_id,
short_id: selectedJP.object_id,
name: selectedJP.name,
published_name: selectedJP.published_name,
stop_areas: selectedJP.stop_area_short_descriptions,
stop_area_short_descriptions: selectedJP.stop_area_short_descriptions
}
}
expect(actions.selectJPCreateModal(selectedJP)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside create modal', () => {
it('should create an action to create a new vehicle journey', () => {
const data = {}
const selectedJourneyPattern = {}
const selectedCompany = {}
const stopPointsList = []
const expectedAction = {
type: 'ADD_VEHICLEJOURNEY',
data,
selectedJourneyPattern,
stopPointsList,
selectedCompany
}
expect(actions.addVehicleJourney(data, selectedJourneyPattern, stopPointsList, selectedCompany)).toEqual(expectedAction)
})
})
describe('when previous navigation button is clicked', () => {
it('should create an action to go to previous page', () => {
const nextPage = false
const queryString = ''
const pagination = {
totalCount: 25,
perPage: 12,
page:1
}
const expectedAction = {
type: 'GO_TO_PREVIOUS_PAGE',
dispatch,
pagination,
nextPage,
queryString
}
expect(actions.goToPreviousPage(dispatch, pagination, queryString)).toEqual(expectedAction)
})
})
describe('when next navigation button is clicked', () => {
it('should create an action to go to next page', () => {
const queryString = ''
const nextPage = true
const pagination = {
totalCount: 25,
perPage: 12,
page:1
}
const expectedAction = {
type: 'GO_TO_NEXT_PAGE',
dispatch,
pagination,
nextPage,
queryString
}
expect(actions.goToNextPage(dispatch, pagination, queryString)).toEqual(expectedAction)
})
})
describe('when checking a vehicleJourney', () => {
it('should create an action to select vj', () => {
const index = 1
const expectedAction = {
type: 'SELECT_VEHICLEJOURNEY',
index
}
expect(actions.selectVehicleJourney(index)).toEqual(expectedAction)
})
})
describe('when clicking on cancel selection button', () => {
it('should create an action to cancel whole selection', () => {
const index = 1
const expectedAction = {
type: 'CANCEL_SELECTION'
}
expect(actions.cancelSelection()).toEqual(expectedAction)
})
})
describe('when clicking on delete button', () => {
it('should create an action to delete vj', () => {
const expectedAction = {
type: 'DELETE_VEHICLEJOURNEYS',
}
expect(actions.deleteVehicleJourneys()).toEqual(expectedAction)
})
})
describe('when toggling arrivals', () => {
it('should create an action to toggleArrivals', () => {
const expectedAction = {
type: 'TOGGLE_ARRIVALS',
}
expect(actions.toggleArrivals()).toEqual(expectedAction)
})
})
describe('when updating vjas time', () => {
it('should create an action to update time', () => {
const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true, enforceConsistency = false
const expectedAction = {
type: 'UPDATE_TIME',
val,
subIndex,
index,
timeUnit,
isDeparture,
isArrivalsToggled,
enforceConsistency
}
expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture, isArrivalsToggled)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside shifting modal', () => {
it('should create an action to shift a vehiclejourney schedule', () => {
const addtionalTime = 0
const expectedAction = {
type: 'SHIFT_VEHICLEJOURNEY',
addtionalTime
}
expect(actions.shiftVehicleJourney(addtionalTime)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside editing modal', () => {
context("with invalid data", () => {
it('should not validate the data', () => {
const data = {
foo: {
validity: { valid: false }
},
bar: {
validity: { valid: true }
}
}
expect(actions.validateFields(data)).toBeFalsy
})
})
context("with data not needing validation", () => {
it('should validate the data', () => {
const data = {
foo: {}
}
expect(actions.validateFields(data)).toBeTruthy
})
})
context("with valid data", () => {
it('should validate the data', () => {
const data = {
foo: {
validity: { valid: true }
},
bar: {
validity: { valid: true }
}
}
expect(actions.validateFields(data)).toBeTruthy
})
})
context("once the data has been validated", () => {
it('should create an action to update a vehiclejourney', () => {
const data = {}
const selectedCompany = {}
const expectedAction = {
type: 'EDIT_VEHICLEJOURNEY',
data,
selectedCompany
}
expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction)
})
})
})
describe('when clicking on validate button inside duplicating modal', () => {
it('should create an action to duplicate a vehiclejourney schedule', () => {
const addtionalTime = 0
const departureDelta = 0
const duplicateNumber = 1
const expectedAction = {
type: 'DUPLICATE_VEHICLEJOURNEY',
addtionalTime,
duplicateNumber,
departureDelta
}
expect(actions.duplicateVehicleJourney(addtionalTime, duplicateNumber, departureDelta)).toEqual(expectedAction)
})
})
describe('when clicking on edit notes modal', () => {
it('should create an action to open footnotes modal', () => {
const vehicleJourney = {}
const expectedAction = {
type: 'EDIT_NOTES_VEHICLEJOURNEY_MODAL',
vehicleJourney
}
expect(actions.openNotesEditModal(vehicleJourney)).toEqual(expectedAction)
})
})
// ___ ___ ___ _____ _ _ ___ _____ ___ ___
// | __/ _ \ / _ \_ _| \| |/ _ \_ _| __/ __|
// | _| (_) | (_) || | | .` | (_) || | | _|\__ \
// |_| \___/ \___/ |_| |_|\_|\___/ |_| |___|___/
//
describe('when clicking on a footnote button inside footnote modal', () => {
it('should create an action to toggle this footnote', () => {
const footnote = {}, isShown = true
const expectedAction = {
type: 'TOGGLE_FOOTNOTE_MODAL',
footnote,
isShown
}
expect(actions.toggleFootnoteModal(footnote, isShown)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside footnote modal', () => {
it('should create an action to update vj footnotes', () => {
const footnotes = []
const expectedAction = {
type: 'EDIT_VEHICLEJOURNEY_NOTES',
footnotes
}
expect(actions.editVehicleJourneyNotes(footnotes)).toEqual(expectedAction)
})
})
// _____ ___ __ __ ___ _____ _ ___ _ ___ ___
// |_ _|_ _| \/ | __|_ _/_\ | _ ) | | __/ __|
// | | | || |\/| | _| | |/ _ \| _ \ |__| _|\__ \
// |_| |___|_| |_|___| |_/_/ \_\___/____|___|___/
//
describe('when clicking on calendar button in toolbox', () => {
it('should create an action to open calendar modal', () => {
const vehicleJourneys = []
const expectedAction = {
type: 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL',
vehicleJourneys
}
expect(actions.openCalendarsEditModal(vehicleJourneys)).toEqual(expectedAction)
})
})
describe('when clicking on delete button next to a timetable inside modal', () => {
it('should create an action to delete timetable from selected vehicle journeys', () => {
const timetable = {}
const expectedAction = {
type: 'DELETE_CALENDAR_MODAL',
timetable
}
expect(actions.deleteCalendarModal(timetable)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside calendars modal', () => {
it('should create an action to update vj calendars', () => {
const vehicleJourneys = []
const timetables = []
const expectedAction = {
type: 'EDIT_VEHICLEJOURNEYS_TIMETABLES',
vehicleJourneys,
timetables
}
expect(actions.editVehicleJourneyTimetables(vehicleJourneys, timetables)).toEqual(expectedAction)
})
})
describe('when clicking on add button inside calendars modal', () => {
it('should create an action to add the selected timetable to preselected vjs', () => {
const expectedAction = {
type: 'ADD_SELECTED_TIMETABLE',
}
expect(actions.addSelectedTimetable()).toEqual(expectedAction)
})
})
describe('when using select2 to pick a timetable', () => {
it('should create an action to select a timetable inside modal', () => {
let selectedTT = {
id: 1,
objectid: 2,
comment: 'test',
}
const expectedAction = {
type: 'SELECT_TT_CALENDAR_MODAL',
selectedItem:{
id: selectedTT.id,
objectid: selectedTT.objectid,
comment: selectedTT.comment,
}
}
expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction)
})
})
// ___ _ _ ___ ___ _ _ _ ___ ___
// | _ \ | | | _ \/ __| || | /_\ / __| __|
// | _/ |_| | / (__| __ |/ _ \\__ \ _|
// |_| \___/|_|_\\___|_||_/_/_\_\___/___|__
// \ \ / /_ _| \| | \ / _ \ \ / / __|
// \ \/\/ / | || .` | |) | (_) \ \/\/ /\__ \
// \_/\_/ |___|_|\_|___/ \___/ \_/\_/ |___/
//
describe('when clicking on purchase window button in toolbox', () => {
it('should create an action to open purchase window modal', () => {
const vehicleJourneys = []
const expectedAction = {
type: 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL',
vehicleJourneys
}
expect(actions.openPurchaseWindowsEditModal(vehicleJourneys)).toEqual(expectedAction)
})
})
describe('when clicking on delete button next to a purchase window inside modal', () => {
it('should create an action to delete purchase window from selected vehicle journeys', () => {
const purchaseWindow = {}
const expectedAction = {
type: 'DELETE_PURCHASE_WINDOW_MODAL',
purchaseWindow
}
expect(actions.deletePurchaseWindowsModal(purchaseWindow)).toEqual(expectedAction)
})
})
describe('when clicking on validate button inside purchase windows modal', () => {
it('should create an action to update vj purchase windows', () => {
const vehicleJourneys = []
const purchase_windows = []
const expectedAction = {
type: 'EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS',
vehicleJourneys,
purchase_windows
}
expect(actions.editVehicleJourneyPurchaseWindows(vehicleJourneys, purchase_windows)).toEqual(expectedAction)
})
})
describe('when clicking on add button inside purchase windows modal', () => {
it('should create an action to add the selected purchase window to preselected vjs', () => {
const expectedAction = {
type: 'ADD_SELECTED_PURCHASE_WINDOW',
}
expect(actions.addSelectedPurchaseWindow()).toEqual(expectedAction)
})
})
describe('when using select2 to pick a purchase window', () => {
it('should create an action to select a purchase window inside modal', () => {
let selectedTT = {
id: 1,
objectid: 2,
name: 'test',
color: 'color',
}
const expectedAction = {
type: 'SELECT_PURCHASE_WINDOW_MODAL',
selectedItem:{
id: selectedTT.id,
objectid: selectedTT.objectid,
name: selectedTT.name,
color: "color"
}
}
expect(actions.selectPurchaseWindowsModal(selectedTT)).toEqual(expectedAction)
})
})
// ___ ___ _ _____ ___ ___ ___
// | __|_ _| ||_ _| __| _ \/ __|
// | _| | || |__| | | _|| /\__ \
// |_| |___|____|_| |___|_|_\|___/
//
describe('when clicking on reset button inside query filters', () => {
it('should create an action to reset the query filters', () => {
const expectedAction = {
type: 'BATCH',
payload: [
{type: 'RESET_FILTERS'},
{type: 'RESET_PAGINATION'},
{type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined},
]
}
expect(actions.resetFilters()).toEqual(expectedAction)
})
})
describe('when clicking on filter button inside query filters', () => {
it('should create an action to filter', () => {
const expectedAction = {
type: 'BATCH',
payload: [
{type: 'CREATE_QUERY_STRING'},
{type: 'RESET_PAGINATION'},
{type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined},
]
}
expect(actions.filterQuery()).toEqual(expectedAction)
})
})
describe('when clicking on checkbox to show vj without schedule', () => {
it('should create an action to toggle this filter', () => {
const expectedAction = {
type: 'TOGGLE_WITHOUT_SCHEDULE',
}
expect(actions.toggleWithoutSchedule()).toEqual(expectedAction)
})
})
describe('when setting new interval', () => {
const val = 1
const unit = 'hour'
it('should create actions to update intervals in state', () => {
let expectedAction = {
type: 'UPDATE_START_TIME_FILTER',
val,
unit
}
expect(actions.updateStartTimeFilter(val, unit)).toEqual(expectedAction)
})
it('should create actions to update intervals in state', () => {
let expectedAction = {
type: 'UPDATE_END_TIME_FILTER',
val,
unit
}
expect(actions.updateEndTimeFilter(val, unit)).toEqual(expectedAction)
})
})
describe('when using select2 to pick a timetable in the filters', () => {
it('should create an action to select a timetable as a filter', () => {
let selectedTT = {
id: 1,
objectid: 2,
comment: 'test',
}
const expectedAction = {
type: 'SELECT_TT_FILTER',
selectedItem:{
id: selectedTT.id,
objectid: selectedTT.objectid,
comment: selectedTT.comment,
}
}
expect(actions.filterSelect2Timetable(selectedTT)).toEqual(expectedAction)
})
})
describe('when using select2 to pick a journeypattern in the filters', () => {
it('should create an action to select a journey pattern as a filter', () => {
let selectedJP = {
id: 1,
object_id: 2,
name: 'test',
published_name: 'test'
}
const expectedAction = {
type: 'SELECT_JP_FILTER',
selectedItem:{
id: selectedJP.id,
objectid: selectedJP.object_id,
name: selectedJP.name,
published_name: selectedJP.published_name
}
}
expect(actions.filterSelect2JourneyPattern(selectedJP)).toEqual(expectedAction)
})
})
describe('when user clicked either on filter or reset button in filters', () => {
it('should create an action to reset pagination', () => {
const expectedAction = {
type: 'RESET_PAGINATION',
}
expect(actions.resetPagination()).toEqual(expectedAction)
})
})
describe('when user clicked either on filter or reset button in filters', () => {
it('should create an action to create a queryString with params filters', () => {
const expectedAction = {
type: 'CREATE_QUERY_STRING',
}
expect(actions.createQueryString()).toEqual(expectedAction)
})
})
describe('when submitting new vj', () => {
it('should create an action to update pagination totalCount', () => {
const diff = 1
const expectedAction = {
type: 'UPDATE_TOTAL_COUNT',
diff
}
expect(actions.updateTotalCount(diff)).toEqual(expectedAction)
})
})
describe('when receiving vj', () => {
it('should create an action to show pagination totalCount', () => {
const total = 1
const expectedAction = {
type: 'RECEIVE_TOTAL_COUNT',
total
}
expect(actions.receiveTotalCount(total)).toEqual(expectedAction)
})
})
describe('when using select2 to pick a company', () => {
it('should create an action to select a company inside modal', () => {
let selectedCompany = {
id: 1,
objectid: 2,
name: 'test',
}
const expectedAction = {
type: 'SELECT_CP_EDIT_MODAL',
selectedItem:{
id: selectedCompany.id,
objectid: selectedCompany.objectid,
name: selectedCompany.name,
}
}
expect(actions.select2Company(selectedCompany)).toEqual(expectedAction)
})
})
describe('when using select2 to unselect a company', () => {
it('should create an action to unselect a company inside modal', () => {
let selectedCompany = {
id: 1,
objectid: 2,
name: 'test',
}
const expectedAction = {
type: 'UNSELECT_CP_EDIT_MODAL'
}
expect(actions.unselect2Company()).toEqual(expectedAction)
})
})
describe('actions.adjustSchedule', () => {
set('time', () => {
return {
hour: 9,
minute: 30
}
})
context('when editing the departure time', () => {
set('action', () => { return { isDeparture: true } })
context('with a positive delta', () => {
set('schedule', () => {
return {
departure_time: time,
arrival_time: time
}
})
it('should do nothing', () => {
expect(actions.adjustSchedule(action, schedule, true)).toEqual(schedule)
})
}),
context('with a delta < 0', () => {
set('departure_time', () => {
return {
hour: time.hour,
minute: time.minute - 1
}
})
set('schedule', () => {
return {
departure_time: departure_time,
arrival_time: time
}
})
it('should adjust arrival time', () => {
let expected = {
departure_time: departure_time,
arrival_time: departure_time,
delta: 0
}
expect(actions.adjustSchedule(action, schedule, true)).toEqual(expected)
})
})
}),
context('when editing the arrival time', () => {
set('action', () => { return { isDeparture: false } })
context('with a positive delta', () => {
set('schedule', () => {
return {
departure_time: time,
arrival_time: time
}
})
it('should do nothing', () => {
expect(actions.adjustSchedule(action, schedule, true)).toEqual(schedule)
})
}),
context('with a delta < 0', () => {
set('arrival_time', () => {
return {
hour: time.hour,
minute: time.minute + 1
}
})
set('schedule', () => {
return {
departure_time: time,
arrival_time: arrival_time
}
})
it('should adjust departure time', () => {
let expected = {
departure_time: arrival_time,
arrival_time: arrival_time,
delta: 0
}
expect(actions.adjustSchedule(action, schedule, true)).toEqual(expected)
})
})
})
})
|