import { When, Then } from '@cucumber/cucumber' import { expect } from '@playwright/test' import type { AppWorld } from '../support/world.js' import { config } from '../support/types.js' When('the lifecycle cron runs', async function (this: AppWorld) { await this.runLifecycle() }) Then( 'the lifecycle cron sent {int} contracts', async function (this: AppWorld, count: number) { const result = await this.runLifecycle() expect(result.contractsSent).toBe(count) }, ) Then( 'the lifecycle cron sent {int} reminders', async function (this: AppWorld, count: number) { const result = await this.runLifecycle() expect(result.reminders).toBe(count) }, ) Then( 'the lifecycle cron completed {int} bookings', async function (this: AppWorld, count: number) { const result = await this.runLifecycle() expect(result.ended).toBe(count) }, ) When( 'I search the bookings list for {string}', async function (this: AppWorld, text: string) { await this.page .getByPlaceholder(/suchen/i) .first() .fill(text) await this.page.waitForTimeout(400) // debounce }, ) When( 'I trigger booking action {string}', async function (this: AppWorld, actionId: string) { const action = this.page.getByTestId(actionId).first() await action.waitFor({ state: 'visible', timeout: config.responseTimeout }) await action.click({ timeout: config.responseTimeout }) const confirm = this.page.getByTestId(`${actionId}-confirm`).first() await confirm.waitFor({ state: 'visible', timeout: config.responseTimeout }) await confirm.click({ timeout: config.responseTimeout }) await this.page.waitForLoadState('networkidle', { timeout: 1000 }).catch(() => {}) await this.page.waitForTimeout(750) }, ) Then( 'the audit log tab includes {string}', async function (this: AppWorld, entry: string) { await this.page.getByRole('tab', { name: /protokoll|audit/i }).click() await expect( this.page.getByText(entry, { exact: false }).first(), ).toBeVisible({ timeout: config.responseTimeout }) }, ) When( 'the admin approves the booking {string}', async function (this: AppWorld, bookingId: string) { await this.gotoApp(`/admin/bookings/${bookingId}`) await this.page.getByRole('button', { name: /reserv/i }).first().click() await this.page.waitForTimeout(500) }, ) When( 'the admin records the deposit received for {string}', async function (this: AppWorld, bookingId: string) { await this.gotoApp(`/admin/bookings/${bookingId}`) await this.page.getByRole('button', { name: /anzahlung/i }).first().click() await this.page.waitForTimeout(500) }, ) Then( 'the booking {string} has status {string}', async function (this: AppWorld, bookingId: string, status: string) { await this.gotoApp(`/admin/bookings/${bookingId}`) await this.expectText(status) }, ) Then( 'the audit log for {string} includes {string}', async function (this: AppWorld, bookingId: string, entry: string) { await this.gotoApp(`/admin/bookings/${bookingId}`) await this.page.getByRole('tab', { name: /protokoll|audit/i }).click() await expect( this.page.getByText(entry, { exact: false }).first(), ).toBeVisible({ timeout: config.responseTimeout }) }, )