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 ab2112b commit 99e618d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/transaction/components/TransactionToastIcon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vi.mock('../components/TransactionProvider', () => ({
}));

describe('TransactionToastIcon', () => {
it('renders transaction toast icon when receipt exists', () => {
it('renders success icon when receipt exists', () => {
(useTransactionContext as vi.Mock).mockReturnValue({
receipt: '123',
});
Expand All @@ -18,7 +18,7 @@ describe('TransactionToastIcon', () => {
const iconElement = screen.getByTestId('ockSuccessSvg');
expect(iconElement).toBeInTheDocument();
});
it('renders transaction toast icon when receipt exists', () => {
it('renders error icon when error exists', () => {
(useTransactionContext as vi.Mock).mockReturnValue({
errorMessage: 'error',
});
Expand All @@ -28,7 +28,7 @@ describe('TransactionToastIcon', () => {
const iconElement = screen.getByTestId('ockErrorSvg');
expect(iconElement).toBeInTheDocument();
});
it('renders transaction toast icon when txn is in progress', () => {
it('renders loading icon when txn is in progress', () => {
(useTransactionContext as vi.Mock).mockReturnValue({
isLoading: true,
});
Expand All @@ -38,4 +38,16 @@ describe('TransactionToastIcon', () => {
const iconElement = screen.getByTestId('ockSpinner');
expect(iconElement).toBeInTheDocument();
});
it('renders null when if no status exists', () => {
(useTransactionContext as vi.Mock).mockReturnValue({
isLoading: false,
});

const { container } = render(
<TransactionToastIcon className="test-class" />,
);

// Assert that nothing is rendered (container should be empty)
expect(container.firstChild).toBeNull();
});
});
5 changes: 5 additions & 0 deletions src/transaction/components/TransactionToastIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export function TransactionToastIcon({ className }: TransactionToastIconReact) {
}
return null;
}, [isInProgress, errorMessage, receipt]);

if (!icon) {
return null;
}

return <div className={cn(text.label2, className)}>{icon}</div>;
}

0 comments on commit 99e618d

Please sign in to comment.