Skip to content
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

[WALL] Lubega / WALL-2991 / TransferFormAccountCard unit test #15140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const WalletsAppLinkedWithWalletIcon = ({ appIcon, currency, isDemo = false, siz
return (
<div
className={`wallets-app-linked-with-wallet-icon wallets-app-linked-with-wallet-icon--${size}`}
data-testid='wallets-app-linked-with-wallet-icon'
data-testid='dt_wallets_app_linked_with_wallet_icon'
>
{/* Wallet Icon */}
<div className='wallets-app-linked-with-wallet-icon__wallet-icon'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import WalletsAppLinkedWithWalletIcon from '../WalletsAppLinkedWithWalletIcon';

describe('<WalletsAppLinkedWithWalletIcon/>', () => {
it('renders', () => {
render(<WalletsAppLinkedWithWalletIcon appIcon='IcWalletOptionsLight' currency='LTC' size='large' />);
render(
<WalletsAppLinkedWithWalletIcon appIcon='IcWalletOptionsLight' currency='USD' isDemo size={undefined} />
);

const divElement = screen.getByTestId('wallets-app-linked-with-wallet-icon');
const divElement = screen.getByTestId('dt_wallets_app_linked_with_wallet_icon');

expect(divElement).toBeInTheDocument();
});
Expand All @@ -25,7 +27,7 @@ describe('<WalletsAppLinkedWithWalletIcon/>', () => {
it('applies correct size', () => {
render(<WalletsAppLinkedWithWalletIcon appIcon='IcWalletOptionsLight' currency='LTC' size='large' />);

const divElement = screen.getByTestId('wallets-app-linked-with-wallet-icon');
const divElement = screen.getByTestId('dt_wallets_app_linked_with_wallet_icon');

expect(divElement).toHaveClass('wallets-app-linked-with-wallet-icon--large');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TProps = {
type?: 'input' | 'modal';
};

const WalletTransferFormAccountCard: React.FC<TProps> = ({ account, activeWallet, type = 'modal' }) => {
const TransferFormAccountCard: React.FC<TProps> = ({ account, activeWallet, type = 'modal' }) => {
const { isMobile } = useDevice();
const isInput = type === 'input';
const isModal = type === 'modal';
Expand Down Expand Up @@ -74,4 +74,4 @@ const WalletTransferFormAccountCard: React.FC<TProps> = ({ account, activeWallet
);
};

export default WalletTransferFormAccountCard;
export default TransferFormAccountCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import useDevice from '../../../../../../../hooks/useDevice';
import { getTradingAppIcon } from '../../../../../helpers';
import TransferFormAccountCard from '../TransferFormAccountCard';

jest.mock('../../../../../../../hooks/useDevice', () => jest.fn());

jest.mock('../../../../../helpers', () => ({
getTradingAppIcon: jest.fn(),
}));

describe('TransferFormAccountCard', () => {
const mockAccount = {
account_category: 'wallet',
account_type: 'type1',
accountName: 'Test Account',
displayBalance: '1000 USD',
landingCompanyName: 'SVG',
mt5_group: 'group1',
};

const mockActiveWallet = {
currency: 'USD',
landingCompanyName: 'SVG',
};

beforeEach(() => {
(useDevice as jest.Mock).mockReturnValue({ isMobile: false });
(getTradingAppIcon as jest.Mock).mockReturnValue('appIcon');
});

afterEach(() => {
jest.clearAllMocks();
});

it('should render without crashing', () => {
render(<TransferFormAccountCard account={undefined} activeWallet={undefined} type={undefined} />);

expect(screen.queryByText('Test Account')).not.toBeInTheDocument();
expect(screen.queryByText('Balance: 1000 USD')).not.toBeInTheDocument();
});

it('should render content for demo account card correctly', () => {
const mockNewAccount = { ...mockAccount, currencyConfig: {}, demo_account: true };

render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='modal'
/>
);

expect(screen.getByText('Test Account')).toBeInTheDocument();
expect(screen.getByText('Balance: 1000 USD')).toBeInTheDocument();
expect(screen.getByText('Demo')).toBeInTheDocument();
expect(screen.queryByTestId('dt_wallets_app_linked_with_wallet_icon')).not.toBeInTheDocument();
});

it('should render content for real account card correctly', () => {
const mockNewAccount = { ...mockAccount, currencyConfig: { display_code: 'USD' }, demo_account: false };

render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='modal'
/>
);

expect(screen.getByText('Test Account')).toBeInTheDocument();
expect(screen.getByText('Balance: 1000 USD')).toBeInTheDocument();
expect(screen.getByText('SVG')).toBeInTheDocument();
expect(screen.queryByTestId('dt_wallets_app_linked_with_wallet_icon')).not.toBeInTheDocument();
});

it('should render content for non-wallet account card correctly', () => {
const mockNewAccount = {
...mockAccount,
account_category: 'trading',
};

render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='modal'
/>
);

expect(screen.getByText('Test Account')).toBeInTheDocument();
expect(screen.getByText('Balance: 1000 USD')).toBeInTheDocument();
expect(screen.getByText('SVG')).toBeInTheDocument();
expect(screen.getByTestId('dt_wallets_app_linked_with_wallet_icon')).toBeInTheDocument();
});

it('should display content for demo account in mobile input type correctly', () => {
const mockNewAccount = { ...mockAccount, demo_account: true };
(useDevice as jest.Mock).mockReturnValue({ isMobile: true });

render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='input'
/>
);

expect(screen.getByText('Test Account')).toBeInTheDocument();
expect(screen.getByText('Balance: 1000 USD')).toBeInTheDocument();
expect(screen.getByText('Demo')).toBeInTheDocument();
});

it('should display content for real account in mobile input type correctly', () => {
const mockNewAccount = { ...mockAccount, demo_account: false };
(useDevice as jest.Mock).mockReturnValue({ isMobile: true });

render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='input'
/>
);

expect(screen.getByText('Test Account')).toBeInTheDocument();
expect(screen.getByText('Balance: 1000 USD')).toBeInTheDocument();
expect(screen.getByText('SVG')).toBeInTheDocument();
});

it('should display different layouts for modal and input types', () => {
const mockNewAccount = { ...mockAccount, demo_account: true };

const { rerender } = render(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='modal'
/>
);

expect(screen.getByText('Demo')).toBeInTheDocument();

rerender(
<TransferFormAccountCard
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
account={mockNewAccount}
// @ts-expect-error - since this is a mock, we only need partial properties of the hook
activeWallet={mockActiveWallet}
type='input'
/>
);

expect(screen.queryByText('Demo')).not.toBeInTheDocument();
});
});
Loading