-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrealtime-staff-attendances.spec.ts
1018 lines (872 loc) · 36.8 KB
/
realtime-staff-attendances.spec.ts
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
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later
import { GroupId } from 'lib-common/generated/api-types/shared'
import HelsinkiDateTime from 'lib-common/helsinki-date-time'
import { randomId } from 'lib-common/id-type'
import LocalDate from 'lib-common/local-date'
import LocalTime from 'lib-common/local-time'
import { FeatureFlags } from 'lib-customizations/types'
import { mobileViewport } from '../../browser'
import {
testDaycare2,
testDaycareGroup,
Fixture,
fullDayTimeRange,
familyWithTwoGuardians,
testDaycare
} from '../../dev-api/fixtures'
import {
createDefaultServiceNeedOptions,
getStaffAttendances,
resetServiceState
} from '../../generated/api-clients'
import {
DevCareArea,
DevDaycareGroup,
DevEmployee,
StaffAttendancePlanId
} from '../../generated/api-types'
import { UnitPage } from '../../pages/employee/units/unit'
import MobileNav from '../../pages/mobile/mobile-nav'
import {
StaffAttendanceEditPage,
StaffAttendancePage
} from '../../pages/mobile/staff-page'
import { pairMobileDevice } from '../../utils/mobile'
import { Page } from '../../utils/page'
import { employeeLogin } from '../../utils/user'
let page: Page
let nav: MobileNav
let mobileSignupUrl: string
let staffAttendancePage: StaffAttendancePage
let staffFixture: DevEmployee
let employeeName: string
const pin = '4242'
let careArea: DevCareArea
const daycareGroup2Fixture: DevDaycareGroup = {
...testDaycareGroup,
id: randomId(),
name: 'Ryhmä 2'
}
beforeEach(async () => {
await resetServiceState()
await Fixture.family(familyWithTwoGuardians).save()
await createDefaultServiceNeedOptions()
careArea = await Fixture.careArea().save()
await Fixture.daycare({
...testDaycare2,
areaId: careArea.id,
enabledPilotFeatures: ['REALTIME_STAFF_ATTENDANCE'],
operationTimes: [
fullDayTimeRange,
fullDayTimeRange,
fullDayTimeRange,
fullDayTimeRange,
fullDayTimeRange,
null,
null
],
shiftCareOperationTimes: null,
shiftCareOpenOnHolidays: false
}).save()
await Fixture.daycareGroup({
...testDaycareGroup,
daycareId: testDaycare2.id
}).save()
await Fixture.daycareGroup({
...daycareGroup2Fixture,
daycareId: testDaycare2.id
}).save()
const daycarePlacementFixture = await Fixture.placement({
childId: familyWithTwoGuardians.children[0].id,
unitId: testDaycare2.id
}).save()
await Fixture.groupPlacement({
daycarePlacementId: daycarePlacementFixture.id,
daycareGroupId: testDaycareGroup.id,
startDate: daycarePlacementFixture.startDate,
endDate: daycarePlacementFixture.endDate
}).save()
staffFixture = await Fixture.employee({
preferredFirstName: 'Kutsumanimi'
})
.staff(testDaycare2.id)
.withGroupAcl(testDaycareGroup.id)
.withGroupAcl(daycareGroup2Fixture.id)
.save()
await Fixture.employeePin({ userId: staffFixture.id, pin }).save()
employeeName = `${staffFixture.lastName} Kutsumanimi`
})
const initPages = async (
mockedTime: HelsinkiDateTime,
featureFlags: Partial<FeatureFlags> = {}
) => {
page = await Page.open({
viewport: mobileViewport,
mockedTime,
employeeMobileCustomizations: { featureFlags }
})
nav = new MobileNav(page)
mobileSignupUrl = await pairMobileDevice(testDaycare2.id)
await page.goto(mobileSignupUrl)
await nav.staff.click()
staffAttendancePage = new StaffAttendancePage(page)
}
describe('Realtime staff attendance page', () => {
test('Staff member can be marked as arrived and departed', async () => {
const date = LocalDate.of(2022, 5, 5)
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(6, 0)))
const arrivalTime = '05:59'
const departureTime = '12:45'
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.markStaffArrived({
pin,
time: arrivalTime,
group: testDaycareGroup,
hasOccupancyEffect: true
})
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.assertEmployeeAttendances([
`Paikalla ${arrivalTime}–`
])
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(13, 30)))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.markStaffDeparted({ pin, time: departureTime })
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertEmployeeAttendances([
`Paikalla ${arrivalTime}–${departureTime}`
])
await staffAttendancePage.goBackFromMemberPage()
await staffAttendancePage.assertPresentStaffCount(0)
const desktopPage = await Page.open({
mockedTime: HelsinkiDateTime.fromLocal(date, LocalTime.of(13, 30))
})
await employeeLogin(desktopPage, staffFixture)
const unitPage = new UnitPage(desktopPage)
await unitPage.navigateToUnit(testDaycare2.id)
const calendarPage = await unitPage.openCalendarPage()
await calendarPage.selectGroup(testDaycareGroup.id)
const staffAttendances = calendarPage.staffAttendances
await staffAttendances.assertTableRow({
rowIx: 0,
nth: date.getIsoDayOfWeek() - 1,
name: `${staffFixture.lastName} ${staffFixture.firstName}`,
attendances: [[arrivalTime, departureTime]]
})
await staffAttendances.assertArrivalTimeTooltip(
0,
date,
'Merkintä luotu 05.05.2022 06:00, testMobileDevice'
)
await staffAttendances.assertDepartureTimeTooltip(
0,
date,
'Merkintä luotu 05.05.2022 13:30, testMobileDevice'
)
})
test('Occupancy effect can not be unchecked on arrival if it has been given permanently but can be edited', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 6, 0))
await Fixture.staffOccupancyCoefficient(
testDaycare2.id,
staffFixture.id
).save()
const arrivalTime = '05:59'
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.staffMemberPage.markArrivedBtn.click()
await staffAttendancePage.pinInput.locator.type(pin)
await staffAttendancePage.anyArrivalPage.arrivedInput.fill(arrivalTime)
await staffAttendancePage.staffArrivalPage.groupSelect.selectOption(
testDaycareGroup.id
)
await staffAttendancePage.staffArrivalPage.occupancyEffectCheckbox.waitUntilHidden()
await staffAttendancePage.anyArrivalPage.markArrived.click()
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.editButton.click()
const editPage = new StaffAttendanceEditPage(page)
await editPage.occupancyEffect.waitUntilChecked(true)
await editPage.occupancyEffect.uncheck()
await editPage.submit(pin)
await staffAttendancePage.editButton.click()
await editPage.occupancyEffect.waitUntilChecked(false)
})
test('Staff member cannot use departure time that is before last arrival time', async () => {
const arrivalTime = '05:59'
await initPages(HelsinkiDateTime.of(2022, 5, 5, 6, 0))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.markStaffArrived({
pin,
time: arrivalTime,
group: testDaycareGroup
})
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.assertEmployeeAttendances([
`Paikalla ${arrivalTime}–`
])
await staffAttendancePage.anyMemberPage.markDeparted.click()
await staffAttendancePage.pinInput.locator.type(pin)
for (const departureTime of ['05:58', '05:59']) {
await staffAttendancePage.staffDeparturePage.departureTime.fill(
departureTime
)
await staffAttendancePage.staffDeparturePage.departureIsBeforeArrival.waitUntilVisible()
await staffAttendancePage.staffDeparturePage.departureIsBeforeArrival.assertText(
(text) => text.endsWith(arrivalTime)
)
await staffAttendancePage.staffDeparturePage.markDepartedBtn.assertDisabled(
true
)
}
})
test('Staff member cannot use arrival time that is before last departure time', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 8, 0))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
const arrivalTime = '07:30'
const departureTime = '07:55'
await staffAttendancePage.markStaffArrived({
pin,
time: arrivalTime,
group: testDaycareGroup
})
await staffAttendancePage.markStaffDeparted({
pin,
time: departureTime
})
await staffAttendancePage.staffMemberPage.markArrivedBtn.click()
await staffAttendancePage.pinInput.locator.type(pin)
await staffAttendancePage.anyArrivalPage.arrivedInput.fill('07:54')
await staffAttendancePage.staffArrivalPage.groupSelect.selectOption(
testDaycareGroup.id
)
await staffAttendancePage.staffArrivalPage.arrivalIsBeforeDeparture.waitUntilVisible()
await staffAttendancePage.staffArrivalPage.arrivalIsBeforeDeparture.assertText(
(text) => text.endsWith(departureTime)
)
await staffAttendancePage.anyArrivalPage.markArrived.assertDisabled(true)
})
test('Staff member can use arrival time that is equal to last departure time', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 8, 0))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
const arrivalTime = '07:30'
const departureTime = '07:55'
await staffAttendancePage.markStaffArrived({
pin,
time: arrivalTime,
group: testDaycareGroup
})
await staffAttendancePage.markStaffDeparted({
pin,
time: departureTime
})
await staffAttendancePage.markStaffArrived({
pin,
time: departureTime,
group: testDaycareGroup
})
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.assertEmployeeAttendances([
`Paikalla ${arrivalTime}–${departureTime}`,
`Paikalla ${departureTime}–`
])
})
test('Staff member cannot be marked as arrived on a non-operational day', async () => {
const saturday = LocalDate.of(2022, 5, 7)
await initPages(HelsinkiDateTime.fromLocal(saturday, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.staffMemberPage.markArrivedBtn.assertDisabled(
true
)
})
test('Message is shown when open attendance exist in another unit', async () => {
const anotherDaycare = await Fixture.daycare({
...testDaycare,
areaId: careArea.id,
enabledPilotFeatures: ['REALTIME_STAFF_ATTENDANCE']
}).save()
const anotherGroupId = randomId<GroupId>()
await Fixture.daycareGroup({
id: anotherGroupId,
daycareId: anotherDaycare.id,
name: 'Toiset testailijat'
}).save()
const mockedDateTime = HelsinkiDateTime.of(2022, 5, 5, 12, 0)
const yesterday = mockedDateTime.subHours(24)
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: anotherGroupId,
arrived: yesterday,
departed: null
}).save()
await initPages(mockedDateTime)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.staffMemberPage.openAttendanceWarning.assertTextEquals(
'Avoin kirjaus ke 4.5.2022 - Alkuräjähdyksen päiväkoti. Kirjaus on päätettävä ennen uuden lisäystä.'
)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.staffMemberPage.markArrivedBtn.assertDisabled(
true
)
})
test('Staff arrival page behaves correctly with different time values when no plan exists', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 12, 0))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.clickStaffArrivedAndSetPin(pin)
// Within 30min from now so ok
await staffAttendancePage.setArrivalTime('12:30')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
// 1min too far in the future
await staffAttendancePage.setArrivalTime('12:31')
await staffAttendancePage.assertArrivalTimeInputInfo(
'Oltava välillä 11:30-12:30'
)
await staffAttendancePage.assertGroupSelectionVisible(false)
await staffAttendancePage.assertDoneButtonEnabled(false)
})
test('Staff arrival page behaves correctly with different time values in the future when plan exists', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
// Now it is 7:30
await initPages(HelsinkiDateTime.of(2022, 5, 5, 7, 30))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.clickStaffArrivedAndSetPin(pin)
// Within 30min from planned start so ok, type required
await staffAttendancePage.setArrivalTime('07:30')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(false)
await staffAttendancePage.selectAttendanceType('JUSTIFIED_CHANGE')
await staffAttendancePage.assertDoneButtonEnabled(true)
// Within 5min from planned start so ok, type not required
await staffAttendancePage.setArrivalTime('07:55')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
// Not ok because >+-30min from current time
await staffAttendancePage.setArrivalTime('08:01')
await staffAttendancePage.assertArrivalTimeInputInfo(
'Oltava välillä 07:00-08:00'
)
// Not ok because >30min from current time
await staffAttendancePage.setArrivalTime('06:59')
await staffAttendancePage.assertArrivalTimeInputInfo(
'Oltava välillä 07:00-08:00'
)
})
test('Staff arrival page behaves correctly with different time values in the past when plan exists', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
// Now it is 8:30
await initPages(HelsinkiDateTime.of(2022, 5, 5, 8, 30))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.clickStaffArrivedAndSetPin(pin)
// Within 5min from planned start so ok, type not required
await staffAttendancePage.setArrivalTime('08:00')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
// More than 5min from planned start, type is not required but can be selected
await staffAttendancePage.setArrivalTime('08:15')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
await staffAttendancePage.selectAttendanceType('JUSTIFIED_CHANGE')
await staffAttendancePage.assertDoneButtonEnabled(true)
// Not ok because >+-30min from current time
await staffAttendancePage.setArrivalTime('07:59')
await staffAttendancePage.assertArrivalTimeInputInfo(
'Oltava välillä 08:00-09:00'
)
})
test('Staff departure page behaves correctly with different time values in the future when plan exists', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.of(2022, 5, 5, 8, 0),
departed: null,
occupancyCoefficient: 0,
type: 'PRESENT'
}).save()
// Now it is 15:30
await initPages(HelsinkiDateTime.of(2022, 5, 5, 15, 30))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.clickStaffDepartedAndSetPin(pin)
// Before planned end no type is required
await staffAttendancePage.setDepartureTime('15:30')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
// Departure time in the future is not allowed
await staffAttendancePage.setDepartureTime('16:00')
await staffAttendancePage.assertDepartureTimeInputInfo(
'Oltava 15:30 tai aikaisemmin'
)
await staffAttendancePage.assertMarkDepartedButtonEnabled(false)
})
test('Staff departure page behaves correctly with different time values in the past when plan exists', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.of(2022, 5, 5, 8, 0),
departed: null,
occupancyCoefficient: 0,
type: 'PRESENT'
}).save()
// Now it is 16:30
await initPages(HelsinkiDateTime.of(2022, 5, 5, 16, 30))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.clickStaffDepartedAndSetPin(pin)
// Departure is possible now
await staffAttendancePage.setDepartureTime('16:30')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
// Departure is possible when the plan ends
await staffAttendancePage.setDepartureTime('16:00')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
await staffAttendancePage.assertDepartureTypeVisible(
'JUSTIFIED_CHANGE',
false
)
// More than 5 min from the plan -> ask for reason
await staffAttendancePage.setDepartureTime('15:54')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
await staffAttendancePage.assertDepartureTypeVisible(
'JUSTIFIED_CHANGE',
true
)
})
test('Staff departs in the middle of the planned day', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.of(2022, 5, 5, 8, 2),
departed: null,
occupancyCoefficient: 0,
type: 'PRESENT'
}).save()
// Now it is 14:02
await initPages(HelsinkiDateTime.of(2022, 5, 5, 14, 2))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.clickStaffDepartedAndSetPin(pin)
await staffAttendancePage.setDepartureTime('14:02')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
await staffAttendancePage.selectAttendanceType('OTHER_WORK')
await staffAttendancePage.clickMarkDepartedButton()
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertShiftTimeTextShown(
'Työvuoro tänään\n08:00 – 16:00'
)
await staffAttendancePage.assertAttendanceTimeTextShown(
'Paikalla 08:02–14:02,Työasia 14:02–'
)
})
test('Staff departs to non work in the middle of the planned day and comes back later', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.of(2022, 5, 5, 8, 2),
departed: null,
occupancyCoefficient: 0,
type: 'PRESENT'
}).save()
// Now it is 14:02
await initPages(HelsinkiDateTime.of(2022, 5, 5, 14, 2))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.clickStaffDepartedAndSetPin(pin)
await staffAttendancePage.setDepartureTime('14:02')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
await staffAttendancePage.clickMarkDepartedButton()
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertShiftTimeTextShown(
'Työvuoro tänään\n08:00 – 16:00'
)
await staffAttendancePage.assertAttendanceTimeTextShown(
'Paikalla 08:02–14:02'
)
await initPages(HelsinkiDateTime.of(2022, 5, 5, 15, 0))
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.clickStaffArrivedAndSetPin(pin)
await staffAttendancePage.setArrivalTime('15:00')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
await staffAttendancePage.clickDoneButton()
await staffAttendancePage.assertAttendanceTimeTextShown(
'Paikalla 08:02–14:02,Paikalla 15:00–'
)
})
test('Staff has been in training and arrives and then departs in the middle of the planned day', async () => {
// Planned attendance 08:00 - 16:00
const planStart = HelsinkiDateTime.of(2022, 5, 5, 8, 0)
const planEnd = HelsinkiDateTime.of(2022, 5, 5, 16, 0)
await Fixture.staffAttendancePlan({
id: randomId<StaffAttendancePlanId>(),
employeeId: staffFixture.id,
startTime: planStart,
endTime: planEnd
}).save()
await initPages(HelsinkiDateTime.of(2022, 5, 5, 12, 4))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.clickStaffArrivedAndSetPin(pin)
await staffAttendancePage.setArrivalTime('12:04')
await staffAttendancePage.selectArrivalGroup(testDaycareGroup.id)
await staffAttendancePage.assertDoneButtonEnabled(true)
await staffAttendancePage.selectAttendanceType('TRAINING')
await staffAttendancePage.clickDoneButton()
await staffAttendancePage.assertShiftTimeTextShown(
'Työvuoro tänään\n08:00 – 16:00'
)
await staffAttendancePage.assertAttendanceTimeTextShown(
'Koulutus 08:00–12:04,Paikalla 12:04–'
)
// Clock is now 14:02
await initPages(HelsinkiDateTime.of(2022, 5, 5, 14, 2))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.clickStaffDepartedAndSetPin(pin)
await staffAttendancePage.setDepartureTime('14:02')
await staffAttendancePage.assertMarkDepartedButtonEnabled(true)
await staffAttendancePage.selectAttendanceType('OTHER_WORK')
await staffAttendancePage.clickMarkDepartedButton()
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertShiftTimeTextShown(
'Työvuoro tänään\n08:00 – 16:00'
)
await staffAttendancePage.assertAttendanceTimeTextShown(
'Koulutus 08:00–12:04,Paikalla 12:04–14:02,Työasia 14:02–'
)
})
test('New external staff member can be added and marked as departed', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 16, 0))
const name = 'Nomen Estomen'
const arrivalTime = '03:20'
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.markNewExternalStaffArrived(
arrivalTime,
name,
testDaycareGroup
)
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(name)
await staffAttendancePage.assertEmployeeStatus('Läsnä')
await staffAttendancePage.assertExternalStaffArrivalTime(arrivalTime)
await staffAttendancePage.markExternalStaffDeparted('11:09')
await staffAttendancePage.assertPresentStaffCount(0)
})
test('External staff member cannot use departure time that is before arrival', async () => {
await initPages(HelsinkiDateTime.of(2022, 5, 5, 16, 0))
const name = 'Nomen Estomen'
const arrivalTime = '08:00'
const departureTime = '07:55'
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.markNewExternalStaffArrived(
arrivalTime,
name,
testDaycareGroup
)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(name)
await staffAttendancePage.externalMemberPage.departureTimeInput.fill(
departureTime
)
await staffAttendancePage.externalMemberPage.departureIsBeforeArrival.waitUntilVisible()
await staffAttendancePage.externalMemberPage.departureIsBeforeArrival.assertText(
(text) => text.endsWith(arrivalTime)
)
await staffAttendancePage.anyMemberPage.markDeparted.assertDisabled(true)
})
test('New external staff member cannot be added on a non-operational day', async () => {
const saturday = LocalDate.of(2022, 5, 7)
await initPages(HelsinkiDateTime.fromLocal(saturday, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.assertMarkNewExternalStaffDisabled()
})
})
describe('Realtime staff attendance edit page', () => {
test('Staff member can add new attendance with attendance types disabled', async () => {
const date = LocalDate.of(2022, 5, 5)
const arrivalTime = '05:59'
const departureTime = '12:45'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.parse(arrivalTime)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.parse(departureTime))
}).save()
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(16, 0)), {
staffAttendanceTypes: false
})
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.editButton.click()
const newDepartureTime = '16:00'
const editPage = new StaffAttendanceEditPage(page)
await editPage.addLink.click()
await editPage.addLink.waitUntilHidden()
await editPage.fillDeparted(1, newDepartureTime)
await editPage.addLink.waitUntilVisible()
await editPage.submit(pin)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.arrivalTime.assertTextEquals(departureTime)
await staffAttendancePage.departureTime.assertTextEquals(newDepartureTime)
})
test('Staff member can add new attendance with group', async () => {
const date = LocalDate.of(2022, 5, 5)
const arrivalTime = '05:59'
const departureTime = '12:45'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.parse(arrivalTime)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.parse(departureTime))
}).save()
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.editButton.click()
const newDepartureTime = '16:00'
const editPage = new StaffAttendanceEditPage(page)
await editPage.addLink.click()
await editPage.addLink.waitUntilHidden()
await editPage.fillDeparted(1, newDepartureTime)
await editPage.addLink.waitUntilVisible()
await editPage.submit(pin)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertEmployeeAttendances([
`Paikalla ${arrivalTime}–${departureTime}`,
`Paikalla ${departureTime}–${newDepartureTime}`
])
})
test('Staff member can add new attendance without group', async () => {
const date = LocalDate.of(2022, 5, 5)
const arrivalTime = '05:59'
const departureTime = '12:45'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
type: 'TRAINING',
groupId: null,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.parse(arrivalTime)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.parse(departureTime))
}).save()
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.editButton.click()
const newDepartureTime = '16:00'
const editPage = new StaffAttendanceEditPage(page)
await editPage.addLink.click()
await editPage.addLink.waitUntilHidden()
await editPage.fillDeparted(1, newDepartureTime)
await editPage.addLink.waitUntilVisible()
await editPage.submit(pin)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertEmployeeAttendances([
`Koulutus ${arrivalTime}–${departureTime}`,
`Koulutus ${departureTime}–${newDepartureTime}`
])
})
test('Staff member can edit existing attendance', async () => {
const date = LocalDate.of(2022, 5, 5)
const arrivalTime = '05:59'
const departureTime = '12:45'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.parse(arrivalTime)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.parse(departureTime))
}).save()
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.editButton.click()
const newArrivalTime = '06:00'
const newDepartureTime = '12:46'
const editPage = new StaffAttendanceEditPage(page)
await editPage.selectGroup(0, daycareGroup2Fixture.id)
await editPage.selectType(0, 'OVERTIME')
await editPage.fillArrived(0, newArrivalTime)
await editPage.fillDeparted(0, newDepartureTime)
await editPage.submit(pin)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertEmployeeAttendances([
`Ylityö ${newArrivalTime}–${newDepartureTime}`
])
const attendances = await getStaffAttendances()
expect(attendances).toHaveLength(1)
expect(attendances[0].groupId).toBe(daycareGroup2Fixture.id)
})
test('Staff member can remove existing attendance', async () => {
const date = LocalDate.of(2022, 5, 5)
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.of(5, 59)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.of(12, 45))
}).save()
await initPages(HelsinkiDateTime.fromLocal(date, LocalTime.of(16, 0)))
await staffAttendancePage.assertPresentStaffCount(0)
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.editButton.click()
const editPage = new StaffAttendanceEditPage(page)
await editPage.remove(0)
await editPage.submit(pin)
await staffAttendancePage.assertEmployeeStatus('Poissa')
await staffAttendancePage.assertEmployeeAttendances([])
})
test('Staff member can edit past attendances', async () => {
const today = LocalDate.of(2023, 1, 24)
const date = today.subDays(3)
const arrivalTime = '09:00'
const departureTime = '17:00'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
type: 'TRAINING',
groupId: null,
arrived: HelsinkiDateTime.fromLocal(date, LocalTime.parse(arrivalTime)),
departed: HelsinkiDateTime.fromLocal(date, LocalTime.parse(departureTime))
}).save()
await initPages(HelsinkiDateTime.fromLocal(today, LocalTime.of(10, 0)))
await staffAttendancePage.selectTab('absent')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.previousAttendancesButton.click()
await staffAttendancePage.previousAttendancesPage
.attendanceOfDate(date, 0)
.times.assertTextEquals('09:00 - 17:00')
await staffAttendancePage.previousAttendancesPage
.attendanceOfDate(date, 0)
.groupOrType.assertTextEquals('Koulutus')
await staffAttendancePage.previousAttendancesPage
.editAttendancesOfDateButton(date)
.click()
const editPage = new StaffAttendanceEditPage(page)
await editPage.fillArrived(0, '09:15')
await editPage.fillDeparted(0, '16:30')
await editPage.submit(pin)
await staffAttendancePage.previousAttendancesButton.click()
await staffAttendancePage.previousAttendancesPage
.attendanceOfDate(date, 0)
.times.assertTextEquals('09:15 - 16:30')
})
test('Staff member can edit ongoing attendance from yesterday through previous attendances', async () => {
const today = LocalDate.of(2023, 1, 24)
const yesterday = today.subDays(1)
const arrivalTime = '22:00'
await Fixture.realtimeStaffAttendance({
employeeId: staffFixture.id,
groupId: testDaycareGroup.id,
arrived: HelsinkiDateTime.fromLocal(
yesterday,
LocalTime.parse(arrivalTime)
),
departed: null
}).save()
await initPages(HelsinkiDateTime.fromLocal(today, LocalTime.of(21, 0)))
await staffAttendancePage.assertPresentStaffCount(1)
await staffAttendancePage.selectTab('present')
await staffAttendancePage.openStaffPage(employeeName)
await staffAttendancePage.previousAttendancesButton.click()
await staffAttendancePage.previousAttendancesPage
.attendanceOfDate(yesterday, 0)
.times.assertTextEquals('22:00 -')