Skip to content

Commit

Permalink
add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Aug 14, 2024
1 parent 4111e12 commit 5f5ed93
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/transaction/components/TransactionButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { useChainId } from 'wagmi';
import { useShowCallsStatus } from 'wagmi/experimental';
Expand Down Expand Up @@ -97,4 +97,34 @@ describe('TransactionButton', () => {
const button = getByRole('button');
expect(button).toBeDisabled();
});

it('should call showCallsStatus when receipt and transactionId exist', () => {
const showCallsStatus = vi.fn();
(useShowCallsStatus as vi.Mock).mockReturnValue({ showCallsStatus });
(useTransactionContext as vi.Mock).mockReturnValue({
receipt: '123',
transactionId: '456',
});

render(<TransactionButton text="Transact" />);
const button = screen.getByText('View transaction');
fireEvent.click(button);

expect(showCallsStatus).toHaveBeenCalledWith({ id: '456' });
});

it('should enable button when not in progress, not missing props, and not waiting for receipt', () => {
(useTransactionContext as vi.Mock).mockReturnValue({
isLoading: false,
contracts: {},
address: '0x123',
transactionId: undefined,
transactionHash: undefined,
receipt: undefined,
});

const { getByRole } = render(<TransactionButton text="Submit" />);
const button = getByRole('button');
expect(button).not.toBeDisabled();
});
});

0 comments on commit 5f5ed93

Please sign in to comment.