feat(tests): agregar pruebas E2E para la creación, visualización y actualización de proformas

This commit is contained in:
David Arranz 2026-09-14 11:09:11 +02:00
parent a13ababdf6
commit 9f303819b3
10 changed files with 131 additions and 3 deletions

View File

@ -12,7 +12,10 @@ export const ProformaDetailHeaderMeta = ({
const items = useMemo(() => [customerName, documentReference], [customerName, documentReference]);
return (
<div className="flex flex-wrap items-center gap-x-3 gap-y-2 text-sm font-medium text-muted-foreground">
<div
className="flex flex-wrap items-center gap-x-3 gap-y-2 text-sm font-medium text-muted-foreground"
id="proforma-detail-identity"
>
{items.map((item, index) => (
<div className="flex items-center gap-3" key={`${item}-${index}`}>
{index > 0 ? <span className="hidden text-border sm:inline">|</span> : null}

View File

@ -246,6 +246,7 @@ export function ProformaRowActions({
return (
<RdxRowActions
data-testid={`proforma-row-${proforma.id}`}
overflowActions={menuActions}
overflowLabel={t("common.more_actions")}
primaryActions={visibleActions}

View File

@ -72,7 +72,12 @@ export const SelectedRecipientSummary = ({
<div className="min-w-0 space-y-3">
<div className="min-w-0 space-y-1">
<div className="flex min-w-0 flex-wrap items-center gap-2">
<p className="min-w-0 wrap-break-word text-base font-semibold">{recipient.name}</p>
<p
className="min-w-0 wrap-break-word text-base font-semibold"
id="proforma-recipient-name"
>
{recipient.name}
</p>
{recipient.status ? (
<RdxBadge

View File

@ -88,7 +88,11 @@ export const SelectCustomerDialog = ({
<Button onClick={ctrl.closeDialog} variant="outline">
Cancelar
</Button>
<Button disabled={ctrl.isLoading || !selectedCustomer} onClick={handleConfirm}>
<Button
disabled={ctrl.isLoading || !selectedCustomer}
id="customer-selection-confirm"
onClick={handleConfirm}
>
{selectedCustomer ? "Confirmar selección" : "Seleccionar cliente"}
</Button>
</div>

View File

@ -50,6 +50,7 @@ export const SelectCustomerSelectionList = ({
"cursor-pointer",
customer.id === selectedCustomer?.id && "border-primary bg-accent"
)}
data-testid={`customer-selection-${customer.id}`}
key={customer.id}
onClick={() => onSelect(customer)}
role="listitem"

View File

@ -0,0 +1,16 @@
import { expect, test } from "@playwright/test";
import { loginViaUi } from "../../support/login-via-ui";
import { createProformaViaUi } from "./support/create-proforma-via-ui";
test("CUSTOMER-INVOICES-PROFORMA-CREATE-001: crea un borrador mínimo sin líneas y comprueba persistencia", async ({
page,
}, testInfo) => {
await loginViaUi(page);
const proforma = await createProformaViaUi(page, testInfo);
await page.reload();
await expect(page).toHaveURL((url) => url.pathname === `/proformas/${proforma.id}/edit`);
await expect(page.locator('input[name="proformaReference"]')).toHaveValue(proforma.reference);
await expect(page.locator("#proforma-recipient-name")).toHaveText(proforma.customer.name);
});

View File

@ -0,0 +1,21 @@
import { expect, test } from "@playwright/test";
import { loginViaUi } from "../../support/login-via-ui";
import { createProformaViaUi } from "./support/create-proforma-via-ui";
test("CUSTOMER-INVOICES-PROFORMA-LIST-001: muestra la proforma persistida propia del escenario", async ({
page,
}, testInfo) => {
await loginViaUi(page);
const proforma = await createProformaViaUi(page, testInfo);
await page.goto("/proformas");
// La referencia asignada por el servidor permite aislar el registro sin depender de su página.
await page.locator('input[inputmode="search"]').fill(proforma.reference);
const row = page
.getByRole("row")
.filter({ has: page.getByTestId(`proforma-row-${proforma.id}`) });
await expect(row).toBeVisible();
await expect(row).toContainText(proforma.reference);
await expect(row).toContainText(proforma.customer.name);
});

View File

@ -0,0 +1,19 @@
import { expect, test } from "@playwright/test";
import { loginViaUi } from "../../support/login-via-ui";
import { createProformaViaUi } from "./support/create-proforma-via-ui";
test("CUSTOMER-INVOICES-PROFORMA-VIEW-001: muestra referencia y cliente persistidos al abrir y recargar detalle", async ({
page,
}, testInfo) => {
await loginViaUi(page);
const proforma = await createProformaViaUi(page, testInfo);
await page.goto(`/proformas/${proforma.id}`);
const identity = page.locator("#proforma-detail-identity");
await expect(identity).toContainText(proforma.reference);
await expect(identity).toContainText(proforma.customer.name);
await page.reload();
await expect(identity).toContainText(proforma.reference);
await expect(identity).toContainText(proforma.customer.name);
});

View File

@ -0,0 +1,29 @@
import { randomUUID } from "node:crypto";
import type { Page, TestInfo } from "@playwright/test";
import { expect } from "@playwright/test";
import { createCustomerViaUi } from "../../../customers/support/create-customer-via-ui";
export async function createProformaViaUi(page: Page, testInfo: TestInfo) {
const token = `e2eproforma${randomUUID().replaceAll("-", "")}`;
const customer = await createCustomerViaUi(page, testInfo, `E2E Proforma ${token}`);
await page.goto("/proformas/create");
await page.locator("#proforma-create-customer").click();
await page.getByRole("dialog").locator('input[inputmode="search"]').fill(token);
await page.getByTestId(`customer-selection-${customer.id}`).click();
await page.locator("#customer-selection-confirm").click();
await expect(page.locator("#proforma-create-customer")).toContainText(customer.name);
await page.getByTestId("submit-button").click();
await expect(page).toHaveURL(/\/proformas\/[^/]+\/edit\?returnTo=/);
const referenceInput = page.locator('input[name="proformaReference"]');
await expect(referenceInput).toHaveValue(/\S+/);
await expect(page.locator("#proforma-recipient-name")).toHaveText(customer.name);
const reference = await referenceInput.inputValue();
const id = new URL(page.url()).pathname.split("/")[2];
if (!id) {
throw new Error("Missing proforma ID in edit URL");
}
return { id, reference, customer, token };
}

View File

@ -0,0 +1,29 @@
import { expect, test } from "@playwright/test";
import { loginViaUi } from "../../support/login-via-ui";
import { createProformaViaUi } from "./support/create-proforma-via-ui";
test("CUSTOMER-INVOICES-PROFORMA-UPDATE-001: modifica referencia y descripción del borrador y comprueba persistencia", async ({
page,
}, testInfo) => {
await loginViaUi(page);
const proforma = await createProformaViaUi(page, testInfo);
const reference = `E2E ${proforma.token}`;
const description = `E2E updated draft ${proforma.token}`;
await page.locator('input[name="reference"]').fill(reference);
await page.locator('textarea[name="description"]').fill(description);
const responsePromise = page.waitForResponse(
(response) =>
response.request().method() === "PUT" &&
new URL(response.url()).pathname.endsWith(`/proformas/${proforma.id}`)
);
await page.getByTestId("submit-button").click();
expect((await responsePromise).status()).toBe(200);
await expect(page).toHaveURL((url) => url.pathname === `/proformas/${proforma.id}/edit`);
await expect(page.locator('input[name="reference"]')).toHaveValue(reference);
await expect(page.locator('textarea[name="description"]')).toHaveValue(description);
await page.reload();
await expect(page.locator('input[name="reference"]')).toHaveValue(reference);
await expect(page.locator('textarea[name="description"]')).toHaveValue(description);
});