FactuGES_ERP/tests/e2e/customers/create-customer.spec.ts

45 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

import { expect, test } from "@playwright/test";
import { loginViaUi } from "../support/login-via-ui";
import { createCustomerViaUi } from "./support/create-customer-via-ui";
test.beforeEach(async ({ page }) => {
await loginViaUi(page);
});
test("CUSTOMERS-CREATE-001: crea un cliente y conserva sus datos tras recargar", async ({
page,
}, testInfo) => {
const customer = await createCustomerViaUi(page, testInfo);
await page.reload();
await expect(page.locator('input[name="name"]')).toHaveValue(customer.name);
await expect(page.locator('input[name="primaryEmail"]')).toHaveValue(customer.email);
});
test("CUSTOMERS-CREATE-002: valida el nombre obligatorio sin enviar el alta", async ({ page }) => {
await page.goto("/customers/create");
const name = page.locator('input[name="name"]');
await expect(name).toBeVisible();
await expect(name).toHaveValue("");
let creationRequests = 0;
page.on("request", (request) => {
if (request.method() === "POST" && /\/customers\/?$/.test(new URL(request.url()).pathname)) {
creationRequests += 1;
}
});
await page.getByTestId("submit-button").click();
await expect(name).toHaveAttribute("aria-invalid", "true");
await expect(
page.locator('[data-slot="field"]').filter({ has: name }).locator('[data-slot="field-error"]')
).toBeVisible();
await expect(page).toHaveURL(/\/customers\/create$/);
// El error visible marca el fin de la validación; sin POST no puede existir un alta.
expect(creationRequests).toBe(0);
});