Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr2github committed Mar 26, 2024
1 parent c6821e2 commit c805883
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ export const Default: Story = {
*/
export const Fallback: Story = {
args: {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
name: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
fiatPrice: 3654.76,
amount: 0,
priceChange: 0,
},
render: (props) => (
<DataList.Root entityLabel="Assets">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,40 @@ describe('<AssetDataListItem.Structure /> component', () => {
expect(screen.getByText(props.symbol)).toBeInTheDocument();
});

it('handles zero priceChange as neutral', () => {
it('renders amount, fiat price', async () => {
const props = {
priceChange: 0,
amount: 420.69,
fiatPrice: 3654.76,
};

render(createTestComponent(props));
expect(screen.getByText('$0.00')).toBeInTheDocument(); // Assuming component shows '0' for zero changedAmount
expect(screen.getByText('0%')).toBeInTheDocument(); // Assuming Tag component renders '0%' for zero changedPercentage
const USDAmount = await screen.findByText(/1.54/);
expect(USDAmount).toHaveTextContent('$1.54M');
expect(screen.getByText(props.amount)).toBeInTheDocument();
});

it('handle not passing changedAmount and changedPercentage', async () => {
it('handles zero priceChange as neutral', () => {
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
name: 'Ethereum',
amount: 420.69,
symbol: 'ETH',
fiatPrice: 3654.76,
amount: 0,
priceChange: 0,
};

render(createTestComponent(props));
expect(screen.getByText('0%')).toBeInTheDocument();
const USDAmount = await screen.findByText(/1.23/);
expect(USDAmount).toHaveTextContent('$1.23M');
const elements = screen.queryAllByText('$0.00');
expect(elements.length).toBeGreaterThan(0); // assuming both asset price and changed price amount are 0.00
expect(screen.getByText('0%')).toBeInTheDocument(); // Assuming Tag component renders '0%' for zero changedPercentage
});

it('handle not passing changedPercentage', async () => {
it('handle not passing priceChange', async () => {
const props = {
logoSrc: 'https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628',
name: 'Ethereum',
amount: -420.69,
amount: 420.69,
symbol: 'ETH',
fiatPrice: 3654.76,
};

render(createTestComponent(props));
const tagElement = await screen.findByText(/\+ 5%/);
expect(tagElement).toHaveTextContent('+ 5%');
expect(screen.getByText('0%')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IAssetDataListItemStructureProps extends IDataListItemProps {
}

export const AssetDataListItemStructure: React.FC<IAssetDataListItemStructureProps> = (props) => {
const { logoSrc, name, amount, symbol, fiatPrice, priceChange = 0, ...otherProps } = props;
const { logoSrc, name = '-', amount = 0, symbol, fiatPrice = 0, priceChange = 0, ...otherProps } = props;

const usdAmountChanged = useMemo(() => {
const usdAmount = (amount ? Number(amount) : 0) * (fiatPrice ? Number(fiatPrice) : 0);
Expand Down

0 comments on commit c805883

Please sign in to comment.