28 lines
1.1 KiB
TypeScript
28 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) {
|
||
|
|
const suffix = `${Date.now()}-${testInfo.workerIndex}-${testInfo.retry}-${randomUUID().slice(0, 8)}`;
|
||
|
|
const name = `zzzz E2E customer ${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 };
|
||
|
|
}
|