-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Send flow sub components #1906
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3924850
hardcode autocomplete values
brendan-defi f0e2626
textClassName override
brendan-defi 11f8904
actionable token balance component
brendan-defi 4309e09
trim and hide long token names
brendan-defi 0717b1c
export token balance
brendan-defi d1b36cd
send components
brendan-defi f829c34
send utils
brendan-defi 35cf20a
simplify address resolution
brendan-defi 321f471
fix lints
brendan-defi 37ddab5
separate components, add tests
brendan-defi e0f30ce
add test
brendan-defi eeaedeb
add tests
brendan-defi 367f325
fix typos
brendan-defi 8d3c4e3
add tests
brendan-defi 1d6b923
add tests
brendan-defi db5deaf
add tests
brendan-defi 34d0a1d
fix lints
brendan-defi 037d9a6
hanlde optional subtitle
brendan-defi 4bf85a0
add tests
brendan-defi 46b70b8
fix typos
brendan-defi ae4a93b
add loadingDisplay override to AmountInputTypeSwitch
brendan-defi fe818ab
refactor TokenBaance for readability
brendan-defi a27d194
add classname override and remove unnecessary object
brendan-defi e20e4f1
classNames object
brendan-defi 79c64d4
classNames object
brendan-defi 86b19c1
add classNames overrides, tests
brendan-defi da1a65b
update tests
brendan-defi 30decf8
fix lints
brendan-defi 1aa46ca
add comments
brendan-defi 5170682
fix lints
brendan-defi 7cfb954
remove extraneous div
brendan-defi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { TokenBalance } from './TokenBalance'; | ||
|
||
const mockToken = { | ||
symbol: 'ETH', | ||
address: '' as const, | ||
chainId: 8453, | ||
decimals: 18, | ||
image: null, | ||
name: 'Ethereum', | ||
cryptoBalance: 1, | ||
fiatBalance: 3300, | ||
}; | ||
|
||
describe('TokenBalance', () => { | ||
describe('Main TokenBalance component', () => { | ||
it('renders as div when no onClick provided', () => { | ||
render(<TokenBalance token={mockToken} />); | ||
expect(screen.queryByRole('button')).toBeNull(); | ||
}); | ||
|
||
it('renders as button with onClick handler', () => { | ||
const onClick = vi.fn(); | ||
render(<TokenBalance token={mockToken} onClick={onClick} />); | ||
|
||
const button = screen.getByRole('button'); | ||
fireEvent.click(button); | ||
expect(onClick).toHaveBeenCalledWith(mockToken); | ||
}); | ||
|
||
it('applies custom classNames to the div container', () => { | ||
const customClassNames = { container: 'custom-class' }; | ||
render(<TokenBalance token={mockToken} classNames={customClassNames} />); | ||
expect(screen.getByTestId('ockTokenBalance')).toHaveClass( | ||
customClassNames.container, | ||
); | ||
}); | ||
|
||
it('applies custom classNames to the button container', () => { | ||
const customClassNames = { container: 'custom-class' }; | ||
const handleClick = vi.fn(); | ||
render( | ||
<TokenBalance | ||
token={mockToken} | ||
onClick={handleClick} | ||
classNames={customClassNames} | ||
/>, | ||
); | ||
expect(screen.getByTestId('ockTokenBalanceButton')).toHaveClass( | ||
customClassNames.container, | ||
); | ||
}); | ||
}); | ||
|
||
describe('TokenBalanceContent', () => { | ||
it('renders token details correctly', () => { | ||
render(<TokenBalance token={mockToken} subtitle="Test subtitle" />); | ||
|
||
expect(screen.getByText('Ethereum')).toBeInTheDocument(); | ||
expect(screen.getByText('0.000 ETH Test subtitle')).toBeInTheDocument(); | ||
expect(screen.getByText('$3,300.00')).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows/hides token image based on showImage prop', () => { | ||
const { rerender } = render( | ||
<TokenBalance | ||
token={mockToken} | ||
showImage={true} | ||
subtitle="Test subtitle" | ||
/>, | ||
); | ||
expect(screen.getByTestId('ockTokenImage_NoImage')).toBeInTheDocument(); | ||
|
||
rerender( | ||
<TokenBalance | ||
token={mockToken} | ||
showImage={false} | ||
subtitle="Test subtitle" | ||
/>, | ||
); | ||
expect(screen.queryByTestId('ockTokenImage_NoImage')).toBeNull(); | ||
}); | ||
|
||
it('renders subtitle when provided', () => { | ||
const subtitle = '(50% of balance)'; | ||
render(<TokenBalance token={mockToken} subtitle={subtitle} />); | ||
expect(screen.getByText(`0.000 ETH ${subtitle}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders action button when showAction is true', () => { | ||
const onActionPress = vi.fn(); | ||
render( | ||
<TokenBalance | ||
token={mockToken} | ||
actionText="Custom Action" | ||
onActionPress={onActionPress} | ||
/>, | ||
); | ||
|
||
const actionButton = screen.getByRole('button', { | ||
name: 'Custom Action', | ||
}); | ||
expect(actionButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(actionButton); | ||
expect(onActionPress).toHaveBeenCalled(); | ||
}); | ||
|
||
it('handles keyboard events on action button', () => { | ||
const onActionPress = vi.fn(); | ||
render(<TokenBalance token={mockToken} onActionPress={onActionPress} />); | ||
|
||
const actionButton = screen.getByRole('button', { name: 'Use max' }); | ||
fireEvent.keyDown(actionButton); | ||
expect(onActionPress).toHaveBeenCalled(); | ||
}); | ||
|
||
it('applies custom class names to token elements when no action is provided', () => { | ||
const customClassNames = { | ||
tokenName: 'custom-name', | ||
tokenValue: 'custom-value', | ||
fiatValue: 'custom-fiat', | ||
}; | ||
|
||
render(<TokenBalance token={mockToken} classNames={customClassNames} />); | ||
|
||
expect(screen.getByText('Ethereum')).toHaveClass('custom-name'); | ||
expect(screen.getByText('0.000 ETH')).toHaveClass('custom-value'); | ||
expect(screen.getByText('$3,300.00')).toHaveClass('custom-fiat'); | ||
}); | ||
|
||
it('applies custom class names to token elements when action is provided', () => { | ||
const customClassNames = { | ||
tokenName: 'custom-name', | ||
tokenValue: 'custom-value', | ||
action: 'custom-action', | ||
}; | ||
|
||
render( | ||
<TokenBalance | ||
token={mockToken} | ||
classNames={customClassNames} | ||
onActionPress={() => {}} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('Ethereum')).toHaveClass('custom-name'); | ||
expect(screen.getByText('0.000 ETH')).toHaveClass('custom-value'); | ||
expect(screen.getByTestId('ockTokenBalanceAction')).toHaveClass( | ||
'custom-action', | ||
); | ||
}); | ||
|
||
it('handles token with empty/null name', () => { | ||
const tokenWithoutName = { | ||
...mockToken, | ||
name: null as unknown as string, | ||
}; | ||
render( | ||
<TokenBalance token={tokenWithoutName} subtitle="Test subtitle" />, | ||
); | ||
|
||
const nameElement = screen.getByText('', { | ||
selector: 'span.ock-font-family.font-semibold', | ||
}); | ||
expect(nameElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('handles token size prop correctly', () => { | ||
const customSize = 60; | ||
render( | ||
<TokenBalance | ||
token={mockToken} | ||
tokenSize={customSize} | ||
subtitle="Test subtitle" | ||
/>, | ||
); | ||
const imageContainer = screen.getByTestId('ockTokenImage_NoImage'); | ||
expect(imageContainer).toHaveStyle({ | ||
width: `${customSize}px`, | ||
height: `${customSize}px`, | ||
minWidth: `${customSize}px`, | ||
minHeight: `${customSize}px`, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use an object structure here with classNames like dan suggested in quality TDD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will that be a breaking change for FundCard though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah good point i guess we can revisit here and i saw you updated to classNames in other component 👍