From ebdc1ca56435d0f1a7339f4858f5130065d5fdd8 Mon Sep 17 00:00:00 2001 From: Joosa Kurvinen Date: Wed, 22 Jan 2025 15:06:28 +0200 Subject: [PATCH] add e2e test --- .../src/e2e-test/pages/employee/units/unit.ts | 16 +++++ .../unit-service-worker-note.spec.ts | 60 +++++++++++++++++++ .../components/unit/UnitServiceWorkerNote.tsx | 12 +++- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100755 frontend/src/e2e-test/specs/5_employee/unit-service-worker-note.spec.ts diff --git a/frontend/src/e2e-test/pages/employee/units/unit.ts b/frontend/src/e2e-test/pages/employee/units/unit.ts index 830981733eb..b9fb1e195d4 100644 --- a/frontend/src/e2e-test/pages/employee/units/unit.ts +++ b/frontend/src/e2e-test/pages/employee/units/unit.ts @@ -50,12 +50,28 @@ export class UnitPage { #groupsTab: Element #calendarTab: Element #applicationProcessTab: Element + serviceWorkerNote: { + addButton: Element + editButton: Element + saveButton: Element + removeButton: Element + content: Element + input: TextInput + } constructor(private readonly page: Page) { this.#unitInfoTab = page.findByDataQa('unit-info-tab') this.#groupsTab = page.findByDataQa('groups-tab') this.#calendarTab = page.findByDataQa('calendar-tab') this.#applicationProcessTab = page.findByDataQa('application-process-tab') + this.serviceWorkerNote = { + addButton: page.findByDataQa('note-add-btn'), + editButton: page.findByDataQa('note-edit-btn'), + saveButton: page.findByDataQa('note-save-btn'), + removeButton: page.findByDataQa('note-remove-btn'), + content: page.findByDataQa('service-worker-note'), + input: new TextInput(page.findByDataQa('note-input')) + } } static async openUnit(page: Page, id: string): Promise { diff --git a/frontend/src/e2e-test/specs/5_employee/unit-service-worker-note.spec.ts b/frontend/src/e2e-test/specs/5_employee/unit-service-worker-note.spec.ts new file mode 100755 index 00000000000..43beda5ba68 --- /dev/null +++ b/frontend/src/e2e-test/specs/5_employee/unit-service-worker-note.spec.ts @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2017-2022 City of Espoo +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +import LocalDate from 'lib-common/local-date' +import LocalTime from 'lib-common/local-time' + +import { Fixture } from '../../dev-api/fixtures' +import { resetServiceState } from '../../generated/api-clients' +import { DevCareArea, DevDaycare, DevEmployee } from '../../generated/api-types' +import { UnitPage } from '../../pages/employee/units/unit' +import { Page } from '../../utils/page' +import { employeeLogin } from '../../utils/user' + +const mockedTime = LocalDate.of(2022, 12, 1).toHelsinkiDateTime( + LocalTime.of(12, 0) +) + +let area: DevCareArea +let daycare: DevDaycare +let serviceWorker: DevEmployee +let page: Page + +beforeEach(async () => { + await resetServiceState() + area = await Fixture.careArea().save() + daycare = await Fixture.daycare({ areaId: area.id }).save() + serviceWorker = await Fixture.employee().serviceWorker().save() + + page = await Page.open({ mockedTime }) +}) + +describe('Employee - Unit - Service worker note', () => { + test('happy path', async () => { + await employeeLogin(page, serviceWorker) + const unitPage = new UnitPage(page) + await unitPage.navigateToUnit(daycare.id) + + await unitPage.serviceWorkerNote.addButton.waitUntilVisible() + await unitPage.serviceWorkerNote.content.waitUntilHidden() + + await unitPage.serviceWorkerNote.addButton.click() + const text1 = 'Väistötiloissa joulukuussa, esteellinen sijainti' + await unitPage.serviceWorkerNote.input.fill(text1) + await unitPage.serviceWorkerNote.saveButton.click() + await unitPage.serviceWorkerNote.saveButton.waitUntilHidden() + await unitPage.serviceWorkerNote.content.assertTextEquals(text1) + + await unitPage.serviceWorkerNote.editButton.click() + const text2 = 'Väistötiloissa marraskuussa 2025, esteellinen sijainti' + await unitPage.serviceWorkerNote.input.fill(text2) + await unitPage.serviceWorkerNote.saveButton.click() + await unitPage.serviceWorkerNote.saveButton.waitUntilHidden() + await unitPage.serviceWorkerNote.content.assertTextEquals(text2) + + await unitPage.serviceWorkerNote.removeButton.click() + await unitPage.serviceWorkerNote.addButton.waitUntilVisible() + await unitPage.serviceWorkerNote.content.waitUntilHidden() + }) +}) diff --git a/frontend/src/employee-frontend/components/unit/UnitServiceWorkerNote.tsx b/frontend/src/employee-frontend/components/unit/UnitServiceWorkerNote.tsx index 798ae059de7..7e94e685bc8 100644 --- a/frontend/src/employee-frontend/components/unit/UnitServiceWorkerNote.tsx +++ b/frontend/src/employee-frontend/components/unit/UnitServiceWorkerNote.tsx @@ -44,7 +44,7 @@ export default React.memo(function UnitServiceWorkerNote({ {editing ? ( <> - +