|
| 1 | +// SPDX-FileCopyrightText: 2017-2025 City of Espoo |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 | + |
| 5 | +import FiniteDateRange from 'lib-common/finite-date-range' |
| 6 | +import LocalDate from 'lib-common/local-date' |
| 7 | + |
| 8 | +import config from '../../../config' |
| 9 | +import { Page, Element, DatePicker } from '../../../utils/page' |
| 10 | + |
| 11 | +export class OutOfOfficePage { |
| 12 | + #outOfOffice: Element |
| 13 | + #outOfOfficeEditor: Element |
| 14 | + #addButton: Element |
| 15 | + #saveButton: Element |
| 16 | + #editButton: Element |
| 17 | + #removeButton: Element |
| 18 | + |
| 19 | + constructor(page: Page) { |
| 20 | + this.#outOfOffice = page.findByDataQa('out-of-office-page') |
| 21 | + this.#outOfOfficeEditor = page.findByDataQa('out-of-office-editor') |
| 22 | + this.#addButton = page.findByDataQa('add-out-of-office') |
| 23 | + this.#saveButton = page.findByDataQa('save-out-of-office') |
| 24 | + this.#editButton = page.findByDataQa('edit-out-of-office') |
| 25 | + this.#removeButton = page.findByDataQa('remove-out-of-office') |
| 26 | + } |
| 27 | + |
| 28 | + static async open(page: Page) { |
| 29 | + await page.goto(config.employeeUrl + '/out-of-office') |
| 30 | + return new OutOfOfficePage(page) |
| 31 | + } |
| 32 | + |
| 33 | + async addOutOfOfficePeriod(startDate: LocalDate, endDate: LocalDate) { |
| 34 | + await this.#addButton.click() |
| 35 | + |
| 36 | + const startInput = new DatePicker( |
| 37 | + this.#outOfOfficeEditor.findAll('input').first() |
| 38 | + ) |
| 39 | + const endInput = new DatePicker( |
| 40 | + this.#outOfOfficeEditor.findAll('input').last() |
| 41 | + ) |
| 42 | + |
| 43 | + await startInput.fill(startDate) |
| 44 | + await endInput.fill(endDate) |
| 45 | + await this.#saveButton.click() |
| 46 | + } |
| 47 | + |
| 48 | + async editStartOfPeriod(newStartDate: LocalDate) { |
| 49 | + await this.#editButton.click() |
| 50 | + const startInput = new DatePicker( |
| 51 | + this.#outOfOfficeEditor.findAll('input').first() |
| 52 | + ) |
| 53 | + await startInput.fill(newStartDate) |
| 54 | + await this.#saveButton.click() |
| 55 | + } |
| 56 | + |
| 57 | + async removeOutOfOfficePeriod() { |
| 58 | + await this.#removeButton.click() |
| 59 | + } |
| 60 | + |
| 61 | + async assertNoPeriods() { |
| 62 | + await this.#outOfOffice.assertText((t) => |
| 63 | + t.includes('Ei tulevia poissaoloja') |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + async assertPeriodExists(startDate: LocalDate, endDate: LocalDate) { |
| 68 | + const periodText = |
| 69 | + FiniteDateRange.tryCreate(startDate, endDate)?.format() ?? 'error' |
| 70 | + await this.#outOfOffice.assertText( |
| 71 | + (t) => t.includes(periodText) && !t.includes('Ei tulevia poissaoloja') |
| 72 | + ) |
| 73 | + } |
| 74 | + |
| 75 | + async assertPeriodDoesNotExist(startDate: LocalDate, endDate: LocalDate) { |
| 76 | + const periodText = |
| 77 | + FiniteDateRange.tryCreate(startDate, endDate)?.format() ?? 'error' |
| 78 | + await this.#outOfOffice.assertText((t) => !t.includes(periodText)) |
| 79 | + } |
| 80 | +} |
0 commit comments