feat: mejorar el componente de ayuda para proformas y ajustar pruebas de actualización

This commit is contained in:
David Arranz 2026-08-28 13:34:03 +02:00
parent a37d6fc96b
commit 1a8d63373d
4 changed files with 432 additions and 420 deletions

View File

@ -10,6 +10,7 @@ import {
Separator,
} from "@repo/shadcn-ui/components";
import { AlertCircleIcon, CheckCircle2Icon, CircleDashedIcon, CircleHelpIcon } from "lucide-react";
import type { ComponentProps } from "react";
import { useTranslation } from "../../../../i18n";
import type { ProformaIssuanceReadiness } from "../../../shared";
@ -23,7 +24,7 @@ interface ProformaUpdateHelpPopoverProps {
onRetryReadiness?: () => void;
}
interface HelpTriggerProps {
interface HelpTriggerProps extends ComponentProps<typeof Button> {
ariaLabel: string;
pendingBlockersCount: number;
}
@ -39,9 +40,16 @@ interface HelpReadinessSectionProps {
translate: (key: string, params?: Record<string, string | number | null | undefined>) => string;
}
const HelpTrigger = ({ ariaLabel, pendingBlockersCount }: HelpTriggerProps) => {
const HelpTrigger = ({ ariaLabel, className, pendingBlockersCount, ...props }: HelpTriggerProps) => {
return (
<Button aria-label={ariaLabel} className="relative" size="icon" type="button" variant="outline">
<Button
{...props}
aria-label={ariaLabel}
className={className ? `relative ${className}` : "relative"}
size="icon"
type="button"
variant="outline"
>
<CircleHelpIcon aria-hidden="true" className="size-4" />
{pendingBlockersCount > 0 ? (
<Badge
@ -190,9 +198,9 @@ export const ProformaUpdateHelpPopover = ({
return (
<Popover>
<PopoverTrigger>
<HelpTrigger ariaLabel={triggerAriaLabel} pendingBlockersCount={pendingBlockersCount} />
</PopoverTrigger>
<PopoverTrigger
render={<HelpTrigger ariaLabel={triggerAriaLabel} pendingBlockersCount={pendingBlockersCount} />}
/>
<PopoverContent
align="end"

View File

@ -31,7 +31,7 @@ const buildFormData = (value: Partial<ProformaUpdateForm> = {}): ProformaUpdateF
...value,
}) as ProformaUpdateForm;
test("excluye items vacíos no valorados al construir el PUT de update", () => {
test("mantiene los items vacíos y respeta su orden al construir el PUT de update", () => {
const formData = buildFormData({
items: [
{
@ -66,7 +66,17 @@ test("excluye items vacíos no valorados al construir el PUT de update", () => {
formData
);
assert.equal(result.data.items?.length, 1);
assert.equal(result.data.items?.[0]?.description, "Servicio");
assert.equal(result.data.items?.length, 2);
assert.equal(result.data.items?.[0]?.description, "");
assert.equal(result.data.items?.[0]?.quantity, null);
assert.equal(result.data.items?.[0]?.unit_amount, null);
assert.equal(result.data.items?.[0]?.position, 0);
assert.equal(result.data.items?.[1]?.description, "Servicio");
assert.deepEqual(result.data.items?.[1]?.quantity, { value: "100", scale: "2" });
assert.deepEqual(result.data.items?.[1]?.unit_amount, {
value: "1000000",
scale: "4",
currency_code: "EUR",
});
assert.equal(result.data.items?.[1]?.position, 1);
});

View File

@ -109,9 +109,7 @@ export const buildUpdateProformaByIdParams = (
// Si se han tocado los detalles, se envían todos
if (shouldReplaceItems(patch)) {
const context = buildProformaItemUpdateDTOContext(formData);
data.items = formData.items
.filter(isValuedProformaItem)
.map((item, index) => toProformaItemUpdateDTO(item, index, context));
data.items = formData.items.map((item, index) => toProformaItemUpdateDTO(item, index, context));
}
return {
@ -146,10 +144,6 @@ const toProformaItemUpdateDTO = (
};
};
const isValuedProformaItem = (item: ProformaItemUpdateForm): boolean => {
return item.quantity !== null && item.unitAmount !== null;
};
const buildProformaItemUpdateDTOContext = (
formData: ProformaUpdateForm
): ProformaItemUpdateDTOContext => {