32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
|
|
import type { Page, TestInfo } from "@playwright/test";
|
|
import { expect } from "@playwright/test";
|
|
|
|
export async function createCustomerViaUi(
|
|
page: Page,
|
|
testInfo: TestInfo,
|
|
namePrefix = "zzzz E2E customer"
|
|
) {
|
|
const suffix = `${Date.now()}-${testInfo.workerIndex}-${testInfo.retry}-${randomUUID().slice(0, 8)}`;
|
|
const name = `${namePrefix} ${suffix}`;
|
|
const email = `e2e-${suffix}@example.invalid`;
|
|
|
|
await page.goto("/customers/create");
|
|
await page.locator('input[name="name"]').fill(name);
|
|
await page.locator('input[name="primaryEmail"]').fill(email);
|
|
await page.getByTestId("submit-button").click();
|
|
|
|
// La navegación solo ocurre tras la respuesta real de creación.
|
|
await expect(page).toHaveURL(/\/customers\/[^/]+\/edit\?returnTo=/);
|
|
await expect(page.locator('input[name="name"]')).toHaveValue(name);
|
|
await expect(page.locator('input[name="primaryEmail"]')).toHaveValue(email);
|
|
|
|
const editUrl = new URL(page.url());
|
|
const id = editUrl.pathname.split("/")[2];
|
|
if (!id) {
|
|
throw new Error("Missing customer ID in edit URL");
|
|
}
|
|
return { id, name, email };
|
|
}
|