|
| 1 | +// SPDX-FileCopyrightText: 2017-2025 City of Espoo |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 | + |
| 5 | +import { DevEmployee } from 'e2e-test/generated/api-types' |
| 6 | +import FiniteDateRange from 'lib-common/finite-date-range' |
| 7 | +import LocalDate from 'lib-common/local-date' |
| 8 | +import LocalTime from 'lib-common/local-time' |
| 9 | + |
| 10 | +import config from '../../config' |
| 11 | +import { |
| 12 | + Fixture, |
| 13 | + testAdult, |
| 14 | + testCareArea, |
| 15 | + testChild, |
| 16 | + testDaycare |
| 17 | +} from '../../dev-api/fixtures' |
| 18 | +import { |
| 19 | + createMessageAccounts, |
| 20 | + resetServiceState |
| 21 | +} from '../../generated/api-clients' |
| 22 | +import CitizenMessagesPage from '../../pages/citizen/citizen-messages' |
| 23 | +import { OutOfOfficePage } from '../../pages/employee/messages/out-of-office-page' |
| 24 | +import { Page } from '../../utils/page' |
| 25 | +import { employeeLogin, enduserLogin } from '../../utils/user' |
| 26 | + |
| 27 | +let supervisor: DevEmployee |
| 28 | + |
| 29 | +beforeEach(async () => { |
| 30 | + await resetServiceState() |
| 31 | + await Fixture.careArea(testCareArea).save() |
| 32 | + const unit = await Fixture.daycare(testDaycare).save() |
| 33 | + supervisor = await Fixture.employee().unitSupervisor(unit.id).save() |
| 34 | + |
| 35 | + await Fixture.family({ |
| 36 | + guardian: testAdult, |
| 37 | + children: [testChild] |
| 38 | + }).save() |
| 39 | + |
| 40 | + await Fixture.placement({ |
| 41 | + childId: testChild.id, |
| 42 | + unitId: testDaycare.id, |
| 43 | + startDate: LocalDate.of(2022, 1, 1), |
| 44 | + endDate: LocalDate.of(2022, 12, 31) |
| 45 | + }).save() |
| 46 | + |
| 47 | + await createMessageAccounts() |
| 48 | +}) |
| 49 | + |
| 50 | +describe('Out of Office', () => { |
| 51 | + test('Out of Office flow', async () => { |
| 52 | + // Employee sets an out of office period and edits it |
| 53 | + const employeePage = await Page.open({ |
| 54 | + mockedTime: LocalDate.of(2022, 12, 1).toHelsinkiDateTime( |
| 55 | + LocalTime.of(12, 0) |
| 56 | + ) |
| 57 | + }) |
| 58 | + await employeeLogin(employeePage, supervisor) |
| 59 | + const outOfOfficePage = await OutOfOfficePage.open(employeePage) |
| 60 | + await outOfOfficePage.assertNoPeriods() |
| 61 | + |
| 62 | + const startDate = LocalDate.of(2022, 12, 1) |
| 63 | + const endDate = LocalDate.of(2022, 12, 7) |
| 64 | + await outOfOfficePage.addOutOfOfficePeriod(startDate, endDate) |
| 65 | + await outOfOfficePage.assertPeriodExists(startDate, endDate) |
| 66 | + |
| 67 | + const newStartDate = LocalDate.of(2022, 12, 2) |
| 68 | + await outOfOfficePage.editStartOfPeriod(newStartDate) |
| 69 | + await outOfOfficePage.assertPeriodExists(newStartDate, endDate) |
| 70 | + await outOfOfficePage.assertPeriodDoesNotExist(startDate, endDate) |
| 71 | + |
| 72 | + // Citizen doesn't see the out of office period because it starts the next day |
| 73 | + const citizenPage1 = await Page.open({ |
| 74 | + mockedTime: LocalDate.of(2022, 12, 1).toHelsinkiDateTime( |
| 75 | + LocalTime.of(13, 0) |
| 76 | + ) |
| 77 | + }) |
| 78 | + const { editor: editor1 } = await getCitizenMessageEditor(citizenPage1) |
| 79 | + await editor1.assertNoOutOfOffice() |
| 80 | + |
| 81 | + // Citizen sees the out of office period the next day |
| 82 | + const citizenPage2 = await Page.open({ |
| 83 | + mockedTime: LocalDate.of(2022, 12, 2).toHelsinkiDateTime( |
| 84 | + LocalTime.of(13, 0) |
| 85 | + ) |
| 86 | + }) |
| 87 | + const { editor: editor2, messagesPage: messagesPage2 } = |
| 88 | + await getCitizenMessageEditor(citizenPage2) |
| 89 | + await editor2.assertOutOfOffice({ |
| 90 | + name: getSupervisorName(), |
| 91 | + period: FiniteDateRange.tryCreate(newStartDate, endDate)! |
| 92 | + }) |
| 93 | + |
| 94 | + // Citizen sends the message (so that a message that can be replied to is available) |
| 95 | + await editor2.fillMessage('Test title', 'Test content') |
| 96 | + await editor2.sendMessage() |
| 97 | + |
| 98 | + // Reply editor shows the out of office period |
| 99 | + await messagesPage2.openFirstThreadReplyEditor() |
| 100 | + await messagesPage2.assertThreadOutOfOffice({ |
| 101 | + name: getSupervisorName(), |
| 102 | + period: FiniteDateRange.tryCreate(newStartDate, endDate)! |
| 103 | + }) |
| 104 | + |
| 105 | + // Employee removes the out of office period |
| 106 | + await outOfOfficePage.removeOutOfOfficePeriod() |
| 107 | + await outOfOfficePage.assertNoPeriods() |
| 108 | + }) |
| 109 | +}) |
| 110 | + |
| 111 | +function getSupervisorName() { |
| 112 | + return `${supervisor.lastName} ${supervisor.firstName}` |
| 113 | +} |
| 114 | + |
| 115 | +async function getCitizenMessageEditor(citizenPage: Page) { |
| 116 | + await enduserLogin(citizenPage, testAdult) |
| 117 | + await citizenPage.goto(config.enduserMessagesUrl) |
| 118 | + const messagesPage = new CitizenMessagesPage(citizenPage) |
| 119 | + const editor = await messagesPage.createNewMessage() |
| 120 | + const supervisorName = getSupervisorName() |
| 121 | + await editor.selectRecipients([supervisorName]) |
| 122 | + return { editor, messagesPage } |
| 123 | +} |
0 commit comments