import { type Page, type Locator } from "@playwright/test"; import { fillDatePicker } from "../utils/date-picker"; export class InboundShipmentEditFormPage { private readonly page: Page; readonly heading: Locator; readonly receiptDateInput: Locator; readonly receivedLinesTable: Locator; readonly submitButton: Locator; readonly cancelButton: Locator; readonly notDraftMessage: Locator; readonly backButton: Locator; constructor(page: Page) { this.page = page; this.heading = page.getByRole("heading", { name: "Edit Inbound Shipment" }); this.receiptDateInput = page.getByLabel("Receipt Date"); this.receivedLinesTable = page.getByRole("table"); this.submitButton = page.getByRole("button", { name: /save changes|saving/i }); this.cancelButton = page.getByRole("button", { name: /^cancel$/i }); this.notDraftMessage = page.getByText("Only inbound shipments in DRAFT status can be edited."); this.backButton = page.getByRole("button", { name: /^back$/i }); } async goto(docNumber: string) { await this.page.goto(`/procurement/inbound-shipment/${docNumber}/edit`); } /** A received-line row in the DataTable, matched by its item name. */ getLineRow(itemName: string): Locator { return this.receivedLinesTable.getByRole("row").filter({ hasText: itemName }); } /** The editable Received Quantity input within a given line row. */ getReceivedQuantityInput(itemName: string): Locator { return this.getLineRow(itemName).getByLabel("Received Quantity"); } /** The editable Received Quantity input at the given zero-based row index. */ getReceivedQuantityInputByIndex(rowIndex: number): Locator { return this.receivedLinesTable .getByRole("row") .filter({ has: this.page.getByLabel("Received Quantity") }) .nth(rowIndex) .getByLabel("Received Quantity"); } getColumnHeader(name: string): Locator { return this.receivedLinesTable.getByRole("columnheader", { name, exact: true }); } async fillReceiptDate(date: string) { await fillDatePicker(this.receiptDateInput, date); } async setReceivedQuantity(itemName: string, quantity: string) { const input = this.getReceivedQuantityInput(itemName); await input.fill(quantity); } async submit() { await this.submitButton.click(); } async cancel() { await this.cancelButton.click(); } }