import { test, expect } from "../fixtures/supplier-management"; import { SupplierCreateFormPage } from "../pages/supplier-create-form"; import { SupplierDetailPage } from "../pages/supplier-detail"; import { SupplierListPage } from "../pages/supplier-list"; for (const kind of ["customer", "supplier"] as const) { test(`admin configures a BP and its ${kind} account`, async ({ page }) => { const accountForm = new SupplierCreateFormPage(page); const accountDetail = new SupplierDetailPage(page); const directory = new SupplierListPage(page); const name = `E2E BP ${Date.now()} ${kind}`; const code = `E2E-${kind}-${Date.now()}`; await page.goto("/master-data/business-partner/create"); await page.getByLabel("Business partner name", { exact: true }).fill(name); await page.getByRole("button", { name: "Save", exact: true }).click(); await expect(page.getByRole("heading", { name, exact: true })).toBeVisible(); await page.getByRole("button", { name: "Add address", exact: true }).click(); await page.getByLabel("Address line 1", { exact: true }).fill("Test address"); await page.getByLabel("City", { exact: true }).fill("Tokyo"); await page.getByLabel("Postal code", { exact: true }).fill("1000001"); await page.getByLabel("Country", { exact: true }).fill("JP"); await page.getByRole("button", { name: "Save", exact: true }).last().click(); await expect(page.getByText("Test address", { exact: true })).toBeVisible(); await accountDetail.selectAccountTab(kind); await accountForm.selectFirstCompany(); await accountForm.codeInput.fill(code); await accountForm.nameInput.fill("Account-specific name"); await accountForm.submitButton.click(); await expect(page.getByRole("heading", { name: code, exact: true })).toBeVisible(); await expect(page.getByRole("link", { name, exact: true })).toBeVisible(); await expect( page.getByRole("definition").filter({ hasText: "Account-specific name" }), ).toBeVisible(); await accountDetail.editButton.click(); await expect(page.getByLabel("Account name", { exact: true })).toHaveValue( "Account-specific name", ); await page.getByRole("button", { name: "Cancel", exact: true }).click(); const { addressSection } = accountDetail; await addressSection.getByText("Assign", { exact: true }).click(); const assignmentDialog = page.getByRole("dialog", { name: "Assign address", exact: true }); await assignmentDialog.getByRole("combobox", { name: "Purpose", exact: true }).click(); await page .getByRole("option", { name: kind === "customer" ? "Bill to" : "Remit to", exact: true }) .click(); await assignmentDialog.getByRole("combobox", { name: "Address", exact: true }).click(); await page.getByRole("option").first().click(); await assignmentDialog.getByRole("button", { name: "Save", exact: true }).click(); await expect(assignmentDialog).toBeHidden(); await addressSection.getByRole("button", { name: "Set as default", exact: true }).click(); await expect(addressSection.getByText("Default", { exact: true })).toBeVisible(); await directory.breadcrumb.click(); await directory.filterByRole(kind); await directory.searchInput.fill(name); await expect(directory.getRow(name)).toHaveCount(1); await page.getByRole("link", { name, exact: true }).click(); await accountDetail.selectAccountTab(kind); await expect(page.getByRole("heading", { name: code, exact: true })).toBeVisible(); await expect(page.getByRole("button", { name: "Unset default", exact: true })).toBeVisible(); }); }