-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: UI improvements in expanded card #29918
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b418cae
chore: adds several improvements to the UI
zone-live e2bc892
chore: prices, AI badge, bullets, and spacing
zone-live 52e78c4
chore: shadow and secondary button
zone-live 4b98897
chore: clean up
zone-live 48e70a5
chore: small tweak
zone-live 09fdbcb
chore: conditional trade button
zone-live d395905
chore: reset file
zone-live 36e1821
chore: update based on feedback review
zone-live 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 hidden or 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
175 changes: 175 additions & 0 deletions
175
app/components/Views/WhatsHappeningDetailView/components/AssetRow.test.tsx
This file contains hidden or 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,175 @@ | ||
| import React from 'react'; | ||
| import { screen, fireEvent } from '@testing-library/react-native'; | ||
| import { TextColor } from '@metamask/design-system-react-native'; | ||
| import type { RelatedAsset } from '@metamask/ai-controllers'; | ||
| import renderWithProvider from '../../../../util/test/renderWithProvider'; | ||
| import AssetRow from './AssetRow'; | ||
|
|
||
| jest.mock('../utils/getRelatedAssetImageSource', () => ({ | ||
| getRelatedAssetImageSource: jest.fn(() => undefined), | ||
| })); | ||
|
|
||
| jest.mock( | ||
| '../../../UI/Tokens/components/TokenListSecurityBadge/TokenListSecurityBadge', | ||
| () => 'TokenListSecurityBadge', | ||
| ); | ||
|
|
||
| const btcAsset: RelatedAsset = { | ||
| sourceAssetId: 'bitcoin', | ||
| symbol: 'BTC', | ||
| name: 'Bitcoin', | ||
| caip19: ['eip155:1/slip44:0'], | ||
| }; | ||
|
|
||
| const symbolOnlyAsset: RelatedAsset = { | ||
| sourceAssetId: 'unknown', | ||
| symbol: 'UNK', | ||
| name: '', | ||
| caip19: [], | ||
| }; | ||
|
|
||
| describe('AssetRow', () => { | ||
| const onAction = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('displays asset.name when name is present', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('Bitcoin')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('falls back to asset.symbol when name is empty', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={symbolOnlyAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy UNK" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('UNK')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('does not render an action button when onAction is omitted', () => { | ||
| renderWithProvider(<AssetRow asset={btcAsset} />); | ||
| expect(screen.queryByText('Buy')).toBeNull(); | ||
| expect(screen.queryByText('Trade')).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the action button with the provided label', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Trade" | ||
| accessibilityLabel="Trade BTC" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('Trade')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('calls onAction when the button is pressed', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| fireEvent.press(screen.getByText('Buy')); | ||
| expect(onAction).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('renders the TokenListSecurityBadge when caipAssetId is provided', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| caipAssetId="eip155:1/slip44:0" | ||
| />, | ||
| ); | ||
| expect(screen.getByTestId !== undefined).toBeTruthy(); | ||
| // The mocked component renders as 'TokenListSecurityBadge' native element | ||
| const badge = screen.UNSAFE_getByType( | ||
| 'TokenListSecurityBadge' as unknown as React.ComponentType, | ||
| ); | ||
| expect(badge).toBeTruthy(); | ||
| expect(badge.props.caipAssetId).toBe('eip155:1/slip44:0'); | ||
| }); | ||
|
|
||
| it('does not render the security badge when caipAssetId is not provided', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| expect( | ||
| screen.UNSAFE_queryByType( | ||
| 'TokenListSecurityBadge' as unknown as React.ComponentType, | ||
| ), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the price secondary line when secondaryLine is provided', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| secondaryLine={{ | ||
| priceText: '$95,000.00', | ||
| changeText: '+2.50%', | ||
| changeColor: TextColor.SuccessDefault, | ||
| }} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('$95,000.00')).toBeOnTheScreen(); | ||
| expect(screen.getByText('+2.50%')).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('renders just the price without change text when changeText is undefined', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| secondaryLine={{ | ||
| priceText: '$95,000.00', | ||
| changeText: undefined, | ||
| changeColor: TextColor.TextAlternative, | ||
| }} | ||
| />, | ||
| ); | ||
| expect(screen.getByText('$95,000.00')).toBeOnTheScreen(); | ||
| expect(screen.queryByText('%')).toBeNull(); | ||
| }); | ||
|
|
||
| it('does not render secondary line when secondaryLine is not provided', () => { | ||
| renderWithProvider( | ||
| <AssetRow | ||
| asset={btcAsset} | ||
| actionLabel="Buy" | ||
| accessibilityLabel="Buy BTC" | ||
| onAction={onAction} | ||
| />, | ||
| ); | ||
| expect(screen.queryByText('$')).toBeNull(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.