diff --git a/src/transaction/components/TransactionButton.test.tsx b/src/transaction/components/TransactionButton.test.tsx index b305945fde..b0784ef6af 100644 --- a/src/transaction/components/TransactionButton.test.tsx +++ b/src/transaction/components/TransactionButton.test.tsx @@ -4,6 +4,7 @@ import { useChainId } from 'wagmi'; import { useShowCallsStatus } from 'wagmi/experimental'; import { TransactionButton } from './TransactionButton'; import { useTransactionContext } from './TransactionProvider'; +import { getChainExplorer } from '../../network/getChainExplorer'; vi.mock('./TransactionProvider', () => ({ useTransactionContext: vi.fn(), @@ -17,6 +18,10 @@ vi.mock('wagmi/experimental', () => ({ useShowCallsStatus: vi.fn(), })); +vi.mock('../../network/getChainExplorer', () => ({ + getChainExplorer: vi.fn(), +})); + describe('TransactionButton', () => { beforeEach(() => { (useChainId as vi.Mock).mockReturnValue(123); @@ -127,4 +132,45 @@ describe('TransactionButton', () => { const button = getByRole('button'); expect(button).not.toBeDisabled(); }); + + it('should open transaction link when only receipt exists', () => { + const onSubmit = vi.fn(); + const chainExplorerUrl = 'https://explorer.com'; + (useTransactionContext as vi.Mock).mockReturnValue({ + receipt: 'receipt-123', + transactionId: undefined, + transactionHash: 'hash-789', + onSubmit, + }); + (getChainExplorer as vi.Mock).mockReturnValue(chainExplorerUrl); + window.open = vi.fn(); + + render(); + const button = screen.getByText('View transaction'); + fireEvent.click(button); + + expect(window.open).toHaveBeenCalledWith( + `${chainExplorerUrl}/tx/hash-789`, + '_blank', + 'noopener,noreferrer', + ); + expect(onSubmit).not.toHaveBeenCalled(); + }); + + it('should call onSubmit when neither receipt nor transactionId exists', () => { + const onSubmit = vi.fn(); + (useTransactionContext as vi.Mock).mockReturnValue({ + receipt: undefined, + transactionId: undefined, + onSubmit, + address: '123', + contracts: [{}], + }); + + render(); + const button = screen.getByText('Transact'); + fireEvent.click(button); + + expect(onSubmit).toHaveBeenCalled(); + }); }); diff --git a/src/transaction/hooks/useGetTransactionStatusAction.test.tsx b/src/transaction/hooks/useGetTransactionStatusAction.test.tsx index c7a4db8e3c..17ce2a069b 100644 --- a/src/transaction/hooks/useGetTransactionStatusAction.test.tsx +++ b/src/transaction/hooks/useGetTransactionStatusAction.test.tsx @@ -101,4 +101,19 @@ describe('useGetTransactionStatusAction', () => { expect(result.current.actionElement).toBeNull(); }); + + it('should call showCallsStatus when button is clicked', () => { + const showCallsStatus = vi.fn(); + (useShowCallsStatus as vi.Mock).mockReturnValue({ showCallsStatus }); + (useTransactionContext as vi.Mock).mockReturnValue({ + transactionId: 'ab123', + }); + + const { result } = renderHook(() => useGetTransactionStatusAction()); + + const button = result.current.actionElement as JSX.Element; + button.props.onClick(); + + expect(showCallsStatus).toHaveBeenCalledWith({ id: 'ab123' }); + }); }); diff --git a/src/transaction/hooks/useGetTransactionToastAction.test.tsx b/src/transaction/hooks/useGetTransactionToastAction.test.tsx index ba6d298af6..2923a43e31 100644 --- a/src/transaction/hooks/useGetTransactionToastAction.test.tsx +++ b/src/transaction/hooks/useGetTransactionToastAction.test.tsx @@ -154,4 +154,19 @@ describe('useGetTransactionToastAction', () => { `); }); + + it('should call showCallsStatus when button is clicked', () => { + const showCallsStatus = vi.fn(); + (useShowCallsStatus as vi.Mock).mockReturnValue({ showCallsStatus }); + (useTransactionContext as vi.Mock).mockReturnValue({ + transactionId: 'ab123', + }); + + const { result } = renderHook(() => useGetTransactionToastAction()); + + const button = result.current.actionElement as JSX.Element; + button.props.onClick(); + + expect(showCallsStatus).toHaveBeenCalledWith({ id: 'ab123' }); + }); });