diff --git a/src/components/PaymentNotice/Card.tsx b/src/components/PaymentNotice/Card.tsx index 21e59bd..1fc0bff 100644 --- a/src/components/PaymentNotice/Card.tsx +++ b/src/components/PaymentNotice/Card.tsx @@ -41,7 +41,8 @@ export const _Card = (notice: PaymentNoticeType) => { const navigate = useNavigate(); const { setState } = useStore(); - function viewDetail() { + function viewDetail(e: React.MouseEvent) { + e.stopPropagation(); setState(STATE.PAYMENT_NOTICE, notice); navigate(`${ArcRoutes.PAYMENT_NOTICES}${iupd}`); } @@ -51,7 +52,7 @@ export const _Card = (notice: PaymentNoticeType) => { viewDetail()} + onClick={viewDetail} borderRadius={1} padding={3} gap={3} @@ -80,7 +81,7 @@ export const _Card = (notice: PaymentNoticeType) => { /> )} - viewDetail()}> + diff --git a/src/components/PaymentNotice/Error.test.tsx b/src/components/PaymentNotice/Error.test.tsx new file mode 100644 index 0000000..249fa11 --- /dev/null +++ b/src/components/PaymentNotice/Error.test.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import { PaymentNotice } from './PaymentNotice'; + +describe('Payment notices error component', () => { + const onRetry = vi.fn(); + + it('should render as expected', () => { + render(); + const button = screen.getByRole('button', { name: 'app.paymentNotice.error.button' }); + expect(button).toBeVisible(); + const description = screen.getByText('app.paymentNotice.error.description'); + expect(description).toBeVisible(); + }); + + it('should trigger the retry function correctly', () => { + const onRetry = vi.fn(); + render(); + const button = screen.getByRole('button', { name: 'app.paymentNotice.error.button' }); + fireEvent.click(button); + expect(onRetry).toHaveBeenCalledOnce(); + }); +}); diff --git a/src/components/PaymentNotice/Error.tsx b/src/components/PaymentNotice/Error.tsx index cc04231..d117795 100644 --- a/src/components/PaymentNotice/Error.tsx +++ b/src/components/PaymentNotice/Error.tsx @@ -5,6 +5,10 @@ import { useTranslation } from 'react-i18next'; import { Box, Button, Card, CardActions } from '@mui/material'; import { ErrorOutline } from '@mui/icons-material'; +interface ErrorProps { + onRetry: () => void; +} + /** * This component is considered private and should not be used directly. * Instead, use `PaymentNotice.Error` for rendering the card. @@ -12,7 +16,7 @@ import { ErrorOutline } from '@mui/icons-material'; * @component * @private */ -export const _Error = () => { +export const _Error = (props: ErrorProps) => { const { t } = useTranslation(); return ( { {t('app.paymentNotice.error.description')}