-
Notifications
You must be signed in to change notification settings - Fork 97
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: add new Review component and apply it to SendConfirmation #6402
base: main
Are you sure you want to change the base?
Changes from all commits
8038fd7
49392f7
9fff8bb
d3f146f
6db6d68
0b70162
1c60a2c
13be246
5853011
36cff0f
84d9b84
4c441c2
6491bd9
a09bf64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ interface Props { | |
backgroundColor?: Colors | ||
foregroundColor?: Colors | ||
borderColor?: Colors | ||
DefaultIcon?: React.ComponentType<{ foregroundColor?: Colors; backgroundColor?: Colors }> | ||
DefaultIcon?: React.ComponentType<{ | ||
color?: Colors | ||
backgroundColor?: Colors | ||
size?: number | ||
}> | ||
} | ||
|
||
const DEFAULT_ICON_SIZE = 40 | ||
|
@@ -30,7 +34,7 @@ function ContactCircle({ | |
backgroundColor, | ||
foregroundColor, | ||
borderColor, | ||
DefaultIcon = ({ foregroundColor }) => <User color={foregroundColor} />, | ||
DefaultIcon = ({ color, size = 20 }) => <User size={size} color={color} />, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why apply a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's indeed redundant, will remove! |
||
}: Props) { | ||
const address = recipient.address | ||
const iconBackgroundColor = backgroundColor ?? getAddressBackgroundColor(address || '0x0') | ||
|
@@ -65,7 +69,13 @@ function ContactCircle({ | |
) | ||
} | ||
|
||
return <DefaultIcon foregroundColor={fontColor} backgroundColor={iconBackgroundColor} /> | ||
return ( | ||
<DefaultIcon | ||
size={iconSize / 1.625} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like using magic numbers but in this case this is the exact proportion as per the new designs (which I think must be applied across the codebase for consistency) |
||
color={fontColor} | ||
backgroundColor={iconBackgroundColor} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { render } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { type Recipient } from 'src/recipients/recipient' | ||
import { typeScale } from 'src/styles/fonts' | ||
import { | ||
Review, | ||
ReviewContent, | ||
ReviewDetailsItem, | ||
ReviewSummaryItem, | ||
ReviewSummaryItemContact, | ||
} from './Review' | ||
|
||
describe('Review', () => { | ||
it('uses the custom headerAction if provided', async () => { | ||
const tree = render( | ||
<Review title="Custom HeaderAction" headerAction={<>Custom Left Action</>} testID="Review"> | ||
<ReviewContent> | ||
<></> | ||
</ReviewContent> | ||
</Review> | ||
) | ||
|
||
expect(tree.getByTestId('Review')).toHaveTextContent('Custom Left Action') | ||
}) | ||
}) | ||
|
||
describe('ReviewSummaryItem', () => { | ||
it('renders the title and optional subtitle', () => { | ||
const tree = render( | ||
<ReviewSummaryItem | ||
header="Item Header" | ||
title="Item Title" | ||
subtitle="Item Subtitle" | ||
icon={<>Item Icon</>} | ||
testID="MyItem" | ||
/> | ||
) | ||
|
||
// Check if header, title, and subtitle all exist | ||
expect(tree.getByTestId('MyItem/Header')).toHaveTextContent('Item Header') | ||
expect(tree.getByTestId('MyItem/Title')).toHaveTextContent('Item Title') | ||
expect(tree.getByTestId('MyItem/Subtitle')).toHaveTextContent('Item Subtitle') | ||
expect(tree.getByTestId('MyItem')).toHaveTextContent('Item Icon') | ||
}) | ||
|
||
it('does not render subtitle if not provided', () => { | ||
const tree = render( | ||
<ReviewSummaryItem header="Header" title="Title" icon={<></>} testID="NoSubtitleItem" /> | ||
) | ||
expect(tree.queryByTestId('NoSubtitleItem/Subtitle')).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('ReviewSummaryItemContact', () => { | ||
it('displays name + phone if recipient has a name and phone number', () => { | ||
const recipient = { | ||
name: 'John Doe', | ||
displayNumber: '+111111111', | ||
e164PhoneNumber: '+222222222', | ||
} as Recipient | ||
const tree = render( | ||
<ReviewSummaryItemContact header="Contact" recipient={recipient} testID="ContactItem" /> | ||
) | ||
|
||
expect(tree.getByTestId('ContactItem/Name/Header')).toHaveTextContent('Contact') | ||
expect(tree.getByTestId('ContactItem/Name/Title')).toHaveTextContent('John Doe') | ||
expect(tree.getByTestId('ContactItem/Name/Subtitle')).toHaveTextContent('+111111111') | ||
}) | ||
|
||
it('displays only displayNumber phone if name is not available', () => { | ||
const recipient = { | ||
displayNumber: '+111111111', | ||
e164PhoneNumber: '+222222222', | ||
} as Recipient | ||
const tree = render( | ||
<ReviewSummaryItemContact header="Contact" recipient={recipient} testID="ContactItem" /> | ||
) | ||
|
||
// This means phone is the title, no subtitle | ||
expect(tree.getByTestId('ContactItem/Phone/Title')).toHaveTextContent('+111111111') | ||
expect(tree.queryByTestId('ContactItem/Phone/Subtitle')).toBeNull() | ||
}) | ||
|
||
it('displays only e164PhoneNumber phone if name and displayNumber are not available', () => { | ||
const recipient = { | ||
e164PhoneNumber: '+222222222', | ||
} as Recipient | ||
const tree = render( | ||
<ReviewSummaryItemContact header="Contact" recipient={recipient} testID="ContactItem" /> | ||
) | ||
|
||
// This means phone is the title, no subtitle | ||
expect(tree.getByTestId('ContactItem/Phone/Title')).toHaveTextContent('+222222222') | ||
expect(tree.queryByTestId('ContactItem/Phone/Subtitle')).toBeNull() | ||
}) | ||
|
||
it('displays address if name/phone not available', () => { | ||
const recipient = { | ||
address: '0x123456789', | ||
} as Recipient | ||
const tree = render( | ||
<ReviewSummaryItemContact header="Contact" recipient={recipient} testID="ContactItem" /> | ||
) | ||
|
||
expect(tree.getByTestId('ContactItem/Address/Title')).toHaveTextContent('0x123456789') | ||
}) | ||
|
||
it('displays "unknown" if no name/phone/address exist', () => { | ||
const recipient = {} as Recipient | ||
const tree = render( | ||
<ReviewSummaryItemContact header="Contact" recipient={recipient} testID="ContactItem" /> | ||
) | ||
|
||
// "t('unknown')" returns "mockedTranslation:unknown" as per our mock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait is this true? i don't see the string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kathaypacific ah sorry, that was initial chatgpt generated comment string that I missed to remove 😅 |
||
expect(tree.getByTestId('ContactItem/Unknown/Title')).toHaveTextContent('unknown') | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wonder if these tests would benefit from a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They differ ever so slightly but I might change it. I'll look into it. |
||
}) | ||
|
||
describe('ReviewDetailsItem', () => { | ||
it('renders loading skeleton if isLoading is true', () => { | ||
const tree = render( | ||
<ReviewDetailsItem | ||
isLoading | ||
label="Loading Label" | ||
value="Should not show" | ||
testID="LoadingItem" | ||
/> | ||
) | ||
|
||
expect(tree.getByTestId('LoadingItem/Loader')).toBeTruthy() | ||
// The value text is not displayed | ||
expect(tree.queryByText('Should not show')).toBeNull() | ||
}) | ||
|
||
it('renders value text if isLoading is false', () => { | ||
const tree = render(<ReviewDetailsItem label="Label" value="Value" testID="DetailsItem" />) | ||
expect(tree.queryByTestId('DetailsItem/Loader')).toBeNull() | ||
expect(tree.getByTestId('DetailsItem/Value')).toHaveTextContent('Value') | ||
}) | ||
|
||
it('applies bold variant if specified', () => { | ||
const tree = render( | ||
<ReviewDetailsItem label="Bold Label" value="Bold Value" variant="bold" testID="BoldItem" /> | ||
) | ||
expect(tree.getByTestId('BoldItem/Label')).toHaveStyle(typeScale.labelSemiBoldMedium) | ||
}) | ||
}) |
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.
Addresses are now showed in full, not shortened