forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WALL] Farhan/WALL-2888/Unit test for WalletCard component (deriv-com…
…#12137) * chore: ✨ unit tests for wallet card * refactor: 🥸☝️ data-testid * chore: 🧹update tests * refactor: update data-testid
- Loading branch information
1 parent
7fab93c
commit 6a2c14c
Showing
3 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
124 changes: 124 additions & 0 deletions
124
packages/wallets/src/components/WalletCard/__tests__/WalletCard.spec.tsx
This file contains 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,124 @@ | ||
import React, { ComponentProps } from 'react'; | ||
import { APIProvider, useBalance } from '@deriv/api'; | ||
import { render, screen } from '@testing-library/react'; | ||
import WalletCard from '../WalletCard'; | ||
|
||
jest.mock('@deriv/api', () => ({ | ||
...jest.requireActual('@deriv/api'), | ||
useBalance: jest.fn(), | ||
})); | ||
|
||
describe('WalletCard', () => { | ||
let mockProps: ComponentProps<typeof WalletCard> = { | ||
balance: '100 USD', | ||
currency: 'USD', | ||
iconSize: 'lg', | ||
landingCompanyName: 'SVG', | ||
}; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
(useBalance as jest.Mock).mockImplementation(() => ({ | ||
...jest.requireActual('@deriv/api').useBalance(), | ||
isLoading: true, | ||
})); | ||
mockProps = { | ||
balance: '100 USD', | ||
currency: 'USD', | ||
iconSize: 'lg', | ||
landingCompanyName: 'SVG', | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should render the correct wallet card and gradient background for USD wallet', () => { | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
expect(screen.getByText('USD Wallet')).toBeInTheDocument(); | ||
const gradient = screen.getByTestId('dt_wallet_gradient_background'); | ||
expect(gradient).toHaveClass('wallets-gradient--USD-mobile-card-light'); | ||
}); | ||
|
||
it('should render the correct wallet card and gradient background for BTC wallet', () => { | ||
mockProps = { | ||
balance: '100 BTC', | ||
currency: 'BTC', | ||
landingCompanyName: 'Deriv', | ||
}; | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
expect(screen.getByText('BTC Wallet')).toBeInTheDocument(); | ||
const gradient = screen.getByTestId('dt_wallet_gradient_background'); | ||
expect(gradient).toHaveClass('wallets-gradient--BTC-mobile-card-light'); | ||
}); | ||
|
||
it('should render the correct wallet card and gradient background for demo wallet', () => { | ||
mockProps = { | ||
balance: '100 USD', | ||
currency: 'USD', | ||
isDemo: true, | ||
landingCompanyName: 'Deriv', | ||
}; | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
const gradient = screen.getByTestId('dt_wallet_gradient_background'); | ||
expect(gradient).toHaveClass('wallets-gradient--demo-mobile-card-light'); | ||
}); | ||
|
||
it('should show balance loader when balance is loading', () => { | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
const balanceLoader = screen.getByTestId('dt_wallet_card_balance_loader'); | ||
expect(balanceLoader).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show balance when balance is loaded', () => { | ||
(useBalance as jest.Mock).mockImplementation(() => ({ | ||
...jest.requireActual('@deriv/api').useBalance(), | ||
isLoading: false, | ||
})); | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
expect(screen.getByText('100 USD')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show the landing company name when provided', () => { | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
expect(screen.getByText('SVG')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show the icon with the correct size', () => { | ||
mockProps = { | ||
...mockProps, | ||
iconSize: 'sm', | ||
}; | ||
render( | ||
<APIProvider> | ||
<WalletCard {...mockProps} /> | ||
</APIProvider> | ||
); | ||
const icon = screen.getByTestId('dt_wallet_card_icon'); | ||
expect(icon).toHaveAttribute('width', '16'); | ||
}); | ||
}); |
This file contains 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