-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test coverage and refactor hooks
- Loading branch information
1 parent
f64c051
commit e2bc5fc
Showing
16 changed files
with
618 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { useGetTransactionToast } from '../hooks/useGetTransactionToast'; | ||
import { useTransactionContext } from '../components/TransactionProvider'; | ||
import { TransactionToastIcon } from './TransactionToastIcon'; | ||
|
||
vi.mock('../hooks/useGetTransactionToast', () => ({ | ||
useGetTransactionToast: vi.fn(), | ||
vi.mock('../components/TransactionProvider', () => ({ | ||
useTransactionContext: vi.fn(), | ||
})); | ||
|
||
describe('TransactionToastIcon', () => { | ||
it('renders transaction toast icon', () => { | ||
(useGetTransactionToast as vi.Mock).mockReturnValue({ | ||
icon: <div>icon</div>, | ||
it('renders transaction toast icon when receipt exists', () => { | ||
(useTransactionContext as vi.Mock).mockReturnValue({ | ||
receipt: '123', | ||
}); | ||
|
||
render(<TransactionToastIcon className="custom-class" />); | ||
|
||
const iconElement = screen.getByText('icon'); | ||
const iconElement = screen.getByTestId('ockSuccessSvg'); | ||
expect(iconElement).toBeInTheDocument(); | ||
}); | ||
it('renders transaction toast icon when receipt exists', () => { | ||
(useTransactionContext as vi.Mock).mockReturnValue({ | ||
errorMessage: 'error', | ||
}); | ||
|
||
render(<TransactionToastIcon className="custom-class" />); | ||
|
||
const iconElement = screen.getByTestId('ockErrorSvg'); | ||
expect(iconElement).toBeInTheDocument(); | ||
}); | ||
it('renders transaction toast icon when txn is in progress', () => { | ||
(useTransactionContext as vi.Mock).mockReturnValue({ | ||
isLoading: true, | ||
}); | ||
|
||
render(<TransactionToastIcon className="custom-class" />); | ||
|
||
const iconElement = screen.getByTestId('ockSpinner'); | ||
expect(iconElement).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
import { useMemo } from 'react'; | ||
import { cn, text } from '../../styles/theme'; | ||
import { useGetTransactionToast } from '../hooks/useGetTransactionToast'; | ||
import type { TransactionToastIconReact } from '../types'; | ||
import { useTransactionContext } from './TransactionProvider'; | ||
import { Spinner } from '../../internal/components/Spinner'; | ||
import { successSvg } from '../../internal/svg/successSvg'; | ||
import { errorSvg } from '../../internal/svg/errorSvg'; | ||
|
||
export function TransactionToastIcon({ className }: TransactionToastIconReact) { | ||
const { icon } = useGetTransactionToast(); | ||
const { errorMessage, isLoading, receipt, transactionHash, transactionId } = | ||
useTransactionContext(); | ||
const isInProgress = isLoading || !!transactionId || !!transactionHash; | ||
|
||
const icon = useMemo(() => { | ||
if (receipt) { | ||
return successSvg; | ||
} | ||
if (errorMessage) { | ||
return errorSvg; | ||
} | ||
if (isInProgress) { | ||
return <Spinner className="px-1.5 py-1.5" />; | ||
} | ||
return null; | ||
}, [isInProgress, errorMessage, receipt]); | ||
return <div className={cn(text.label2, className)}>{icon}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.