From 795745dee3448a33c3e187759fd5d840a23597e2 Mon Sep 17 00:00:00 2001 From: leleOFA Date: Thu, 13 Feb 2025 16:42:19 +0100 Subject: [PATCH] fix: fix test for payment --- .../NotificationPaymentRecipient.tsx | 2 +- .../NotificationPaymentRecipient.test.tsx | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/pn-commons/src/components/NotificationDetail/NotificationPaymentRecipient.tsx b/packages/pn-commons/src/components/NotificationDetail/NotificationPaymentRecipient.tsx index 112bc22bfc..d90099300f 100644 --- a/packages/pn-commons/src/components/NotificationDetail/NotificationPaymentRecipient.tsx +++ b/packages/pn-commons/src/components/NotificationDetail/NotificationPaymentRecipient.tsx @@ -44,7 +44,7 @@ type Props = { const RenderAlertPayment: React.FC<{ errorOnPayment: boolean }> = ({ errorOnPayment }) => errorOnPayment && ( - + {getLocalizedOrDefaultLabel('notifications', 'payment.error-payment')} ); diff --git a/packages/pn-commons/src/components/NotificationDetail/__test__/NotificationPaymentRecipient.test.tsx b/packages/pn-commons/src/components/NotificationDetail/__test__/NotificationPaymentRecipient.test.tsx index e4258aa7c4..097c29ceb7 100644 --- a/packages/pn-commons/src/components/NotificationDetail/__test__/NotificationPaymentRecipient.test.tsx +++ b/packages/pn-commons/src/components/NotificationDetail/__test__/NotificationPaymentRecipient.test.tsx @@ -3,7 +3,7 @@ import { vi } from 'vitest'; import { paymentInfo } from '../../../__mocks__/ExternalRegistry.mock'; import { notificationDTO, payments } from '../../../__mocks__/NotificationDetail.mock'; import { PaymentAttachmentSName, PaymentStatus, PaymentsData } from '../../../models'; -import { act, fireEvent, render, within } from '../../../test-utils'; +import { act, fireEvent, render, waitFor, within } from '../../../test-utils'; import { setPaymentCache } from '../../../utility'; import { getF24Payments, @@ -57,13 +57,11 @@ describe('NotificationPaymentRecipient Component', () => { expect(pagoPABox).toHaveLength(pageLength > 5 ? 5 : pageLength); expect(downloadPagoPANotice).not.toBeInTheDocument(); expect(payButton).toBeInTheDocument(); - expect(payButton).toBeDisabled(); expect(f24OnlyBox).toBeInTheDocument(); expect(paginationBox).toBeInTheDocument(); }); it('select and unselect payment', async () => { - vi.useFakeTimers(); const { getByTestId, queryAllByTestId, queryByTestId } = render( { const item = queryAllByTestId('pagopa-item')[paymentIndex]; const radioButton = item.querySelector('[data-testid="radio-button"] input'); expect(downloadPagoPANotice).not.toBeInTheDocument(); - expect(payButton).toBeDisabled(); - // select payment + + // test error payment + fireEvent.click(payButton); + await waitFor(() => { + expect(getByTestId('payment-error')).toBeInTheDocument(); + }); + + // Clicca sul radioButton per correggere l'errore fireEvent.click(radioButton!); + + await waitFor(() => { + expect(queryByTestId('payment-error')).not.toBeInTheDocument(); + }); // after radio button click, there is a timer of 1 second after that the paymeny is enabled // wait... - act(() => { - vi.advanceTimersByTime(1000); - }); downloadPagoPANotice = getByTestId('download-pagoPA-notice-button'); expect(downloadPagoPANotice).toBeInTheDocument(); expect(payButton).not.toBeDisabled(); @@ -101,7 +106,6 @@ describe('NotificationPaymentRecipient Component', () => { expect(f24Download).toBeInTheDocument(); // unselect payment fireEvent.click(radioButton!); - expect(payButton).toBeDisabled(); expect(downloadPagoPANotice).not.toBeInTheDocument(); expect(f24Download).not.toBeInTheDocument(); });