Skip to content

Commit a5bd749

Browse files
authored
chore: Added unit test for WalletCurrencyIcon (deriv-com#14889)
1 parent 39f3954 commit a5bd749

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import WalletCurrencyIcon, { defaultIconWidth, roundedIconWidth } from '../WalletCurrencyIcon';
4+
5+
describe('WalletCurrencyIcon', () => {
6+
it('renders the correct icon for a given currency', () => {
7+
render(<WalletCurrencyIcon currency='USD' />);
8+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
9+
expect(iconElement).toBeInTheDocument();
10+
});
11+
12+
it('renders with rounded icons when rounded prop is true', () => {
13+
render(<WalletCurrencyIcon currency='USD' rounded />);
14+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
15+
expect(iconElement).toBeInTheDocument();
16+
});
17+
18+
it('renders with default icons when rounded prop is false', () => {
19+
render(<WalletCurrencyIcon currency='BTC' />);
20+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
21+
expect(iconElement).toBeInTheDocument();
22+
});
23+
24+
it('renders with the correct size when size prop is provided and rounded is true', () => {
25+
render(<WalletCurrencyIcon currency='BTC' rounded size='lg' />);
26+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
27+
expect(iconElement).toHaveAttribute('width', roundedIconWidth.lg.toString());
28+
});
29+
30+
it('renders with the correct size when size prop is provided and rounded is false', () => {
31+
render(<WalletCurrencyIcon currency='BTC' rounded={false} size='lg' />);
32+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
33+
expect(iconElement).toHaveAttribute('width', defaultIconWidth.lg.toString());
34+
});
35+
36+
it('renders with the correct size when size prop is provided for FIAT and rounded is false', () => {
37+
render(<WalletCurrencyIcon currency='USD' rounded={false} size='lg' />);
38+
const iconElement = screen.getByTestId('dt_wallet_currency_icon');
39+
expect(iconElement).toHaveAttribute('width', roundedIconWidth.lg.toString());
40+
});
41+
42+
it('renders null if an unknown currency is being passed', () => {
43+
const { container } = render(<WalletCurrencyIcon currency='MYR' />);
44+
expect(container).toBeEmptyDOMElement();
45+
});
46+
});

0 commit comments

Comments
 (0)