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

[FEQ] P2P-V2 My Profile balance test #13398

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
16d8abd
chore: removed responsive root
adrienne-deriv Nov 17, 2023
65d8aec
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 20, 2023
8c91e7b
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 20, 2023
b5027cb
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 20, 2023
79a6f21
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 21, 2023
7956e94
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 22, 2023
e2d06d0
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 22, 2023
4783835
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 22, 2023
a64e58f
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 22, 2023
1200577
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 23, 2023
0e70ed5
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 23, 2023
f11377b
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 24, 2023
07bf6e5
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Nov 30, 2023
2e25182
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 4, 2023
0d432e7
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 5, 2023
bacb384
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 12, 2023
89f0f91
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 12, 2023
b5a3745
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 13, 2023
93526fa
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 14, 2023
56744da
chore: reverted old changes
adrienne-deriv Dec 14, 2023
eb60b51
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Dec 20, 2023
f2eb3ba
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 3, 2024
c90d747
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 3, 2024
a1ab9d8
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 4, 2024
18030ec
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 5, 2024
1c1fdea
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 9, 2024
7e1de5c
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 11, 2024
cbf6c35
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 17, 2024
aa4223d
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 22, 2024
d9e0e7e
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 24, 2024
97addbc
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 24, 2024
b750467
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 31, 2024
eca7237
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Jan 31, 2024
09782fc
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Feb 1, 2024
62f504d
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Feb 2, 2024
e869a75
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Feb 2, 2024
f39bbae
Merge branch 'master' of github.com:binary-com/deriv-app
adrienne-deriv Feb 6, 2024
0cf479f
chore: added tests for profile balance
adrienne-deriv Feb 7, 2024
4652051
Merge branch 'master' of github.com:binary-com/deriv-app into p2p-v2-…
adrienne-deriv Feb 7, 2024
ef734d9
Update MyProfileBalance.spec.tsx
adrienne-deriv Feb 7, 2024
137c6a5
Update MyProfileBalance.spec.tsx
adrienne-deriv Feb 7, 2024
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 @@ -21,6 +21,7 @@ const AvailableP2PBalanceModal = ({ isModalOpen, onRequestClose }: TAvailableP2P
onRequestClose={onRequestClose}
shouldCloseOnOverlayClick={false}
style={customStyles}
testId='dt_p2p_v2_available_p2p_balance_modal'
>
<Text as='p' weight='bold'>
Available Deriv P2P Balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const DailyLimitModal = ({ currency, isModalOpen, onRequestClose }: TDailyLimitM
// TODO: below modal will be rewritten to use @deriv/ui modal
<Modal
className='p2p-v2-daily-limit-modal'
data-testid='dt_p2p_v2_daily_limit_modal'
isOpen={isModalOpen}
onRequestClose={onRequestClose}
style={customStyles}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const MyProfileBalance = () => {
const { data: advertiserInfo } = useAdvertiserStats();
const { data: activeAccount } = useActiveAccount();
const { isDesktop } = useDevice();
const [shouldShowDailyLimitModal, setShouldShowDailyLimitModal] = useState(false);
const [shouldShowAvailableBalanceModal, setShouldShowAvailableBalanceModal] = useState(false);

const currency = activeAccount?.currency || 'USD';
Expand Down Expand Up @@ -44,19 +43,15 @@ const MyProfileBalance = () => {
isModalOpen={shouldShowAvailableBalanceModal}
onRequestClose={() => setShouldShowAvailableBalanceModal(false)}
/>
<DailyLimitModal
currency={currency}
isModalOpen={shouldShowDailyLimitModal}
onRequestClose={() => setShouldShowDailyLimitModal(false)}
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this modal as it was already included in <MyProfileDailyLimit />

<div className='p2p-v2-my-profile-balance'>
<div className='p2p-v2-my-profile-balance__amount'>
<div className='p2p-v2-my-profile-balance__amount' data-testid='dt_p2p_v2_available_balance_amount'>
<div>
<Text color='less-prominent' size={isDesktop ? 'sm' : 'xs'}>
Available Deriv P2P Balance
</Text>
<InfoOutlineIcon
className='cursor-pointer fill-gray-400'
data-testid='dt_p2p_v2_available_balance_icon'
onClick={() => setShouldShowAvailableBalanceModal(true)}
/>
</div>
Expand All @@ -70,7 +65,7 @@ const MyProfileBalance = () => {
<div className='p2p-v2-my-profile-balance__item' key={type}>
<Text size={isDesktop ? 'sm' : 'xs'}>{type}</Text>
<div className='p2p-v2-my-profile-balance__item-limits'>
<div>
<div data-testid={`dt_p2p_v2_profile_balance_daily_${type.toLowerCase()}_limit`}>
<Text color='less-prominent' size={isDesktop ? 'sm' : 'xs'}>
Daily limit
</Text>
Expand All @@ -82,7 +77,9 @@ const MyProfileBalance = () => {
{dailyLimit}
</Text>
</div>
<div>
<div
data-testid={`dt_p2p_v2_profile_balance_available_${type.toLowerCase()}_limit`}
>
<Text color='less-prominent' size={isDesktop ? 'sm' : 'xs'}>
Available
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React from 'react';
import { APIProvider } from '@deriv/api';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MyProfileBalance from '../MyProfileBalance';

const wrapper = ({ children }: { children: JSX.Element }) => (
<APIProvider>
<div id='v2_modal_root' />
{children}
</APIProvider>
);

let mockUseAdvertiserStats = {
data: {
balance_available: 50000,
daily_buy_limit: 500,
daily_sell_limit: 500,
dailyAvailableBuyLimit: 10,
dailyAvailableSellLimit: 10,
fullName: 'Jane Doe',
isEligibleForLimitUpgrade: false,
name: 'Jane',
show_name: 0,
},
isLoading: false,
};
const mockUseActiveAccount = {
data: {
currency: 'USD',
},
isLoading: false,
};

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
useAdvertiserStats: jest.fn(() => mockUseAdvertiserStats),
}));

jest.mock('@deriv/api', () => ({
...jest.requireActual('@deriv/api'),
useActiveAccount: jest.fn(() => mockUseActiveAccount),
}));

describe('MyProfileBalance', () => {
it('should render the correct balance', () => {
render(<MyProfileBalance />, { wrapper });
const availableBalanceNode = screen.getByTestId('dt_p2p_v2_available_balance_amount');
expect(within(availableBalanceNode).getByText('50,000.00 USD')).toBeInTheDocument();

const balanceInfoIcon = screen.getByTestId('dt_p2p_v2_available_balance_icon');
userEvent.click(balanceInfoIcon);
expect(screen.getByTestId('dt_p2p_v2_available_p2p_balance_modal')).toBeInTheDocument();
const okButton = screen.getByRole('button', {
name: 'Ok',
});
userEvent.click(okButton);
expect(screen.queryByTestId('dt_p2p_v2_available_p2p_balance_modal')).not.toBeInTheDocument();
});

it('should render the correct limits', () => {
mockUseAdvertiserStats = {
data: {
...mockUseAdvertiserStats.data,
daily_buy_limit: 500,
daily_sell_limit: 2000,
dailyAvailableBuyLimit: 100,
dailyAvailableSellLimit: 600,
},
isLoading: false,
};
render(<MyProfileBalance />, { wrapper });
const dailyBuyLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_daily_buy_limit');
expect(within(dailyBuyLimitNode).getByText('500 USD')).toBeInTheDocument();
const availableBuyLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_available_buy_limit');
expect(within(availableBuyLimitNode).getByText('100.00 USD')).toBeInTheDocument();

const dailySellLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_daily_sell_limit');
expect(within(dailySellLimitNode).getByText('2000 USD')).toBeInTheDocument();
const dailyAvailableSellLimit = screen.getByTestId('dt_p2p_v2_profile_balance_available_sell_limit');
expect(within(dailyAvailableSellLimit).getByText('600.00 USD')).toBeInTheDocument();
});
it('should render eligibility for daily limit upgrade', () => {
mockUseAdvertiserStats = {
data: {
...mockUseAdvertiserStats.data,
isEligibleForLimitUpgrade: true,
},
isLoading: false,
};
render(<MyProfileBalance />, { wrapper });
expect(screen.getByTestId('dt_p2p_v2_profile_daily_limit')).toBeInTheDocument();

const openDailyLimitModalBtn = screen.getByRole('button', {
name: 'Increase my limits',
});
userEvent.click(openDailyLimitModalBtn);
const hideDailyLimitBtn = screen.getByRole('button', {
name: 'No',
});
userEvent.click(hideDailyLimitBtn);
expect(screen.queryByTestId('dt_p2p_v2_daily_limit_modal')).not.toBeInTheDocument();
});
it('should render the correct default values', () => {
mockUseAdvertiserStats = {
// @ts-expect-error To clear the mocked values and assert the default values
data: {},
isLoading: false,
};
render(<MyProfileBalance />, { wrapper });
const availableBalanceNode = screen.getByTestId('dt_p2p_v2_available_balance_amount');
expect(within(availableBalanceNode).getByText('0.00 USD')).toBeInTheDocument();
const dailyBuyLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_daily_buy_limit');
expect(within(dailyBuyLimitNode).getByText('0.00 USD')).toBeInTheDocument();
const availableBuyLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_available_buy_limit');
expect(within(availableBuyLimitNode).getByText('0.00 USD')).toBeInTheDocument();

const dailySellLimitNode = screen.getByTestId('dt_p2p_v2_profile_balance_daily_sell_limit');
expect(within(dailySellLimitNode).getByText('0.00 USD')).toBeInTheDocument();
const dailyAvailableSellLimit = screen.getByTestId('dt_p2p_v2_profile_balance_available_sell_limit');
expect(within(dailyAvailableSellLimit).getByText('0.00 USD')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const MyProfileDailyLimit = () => {

return (
<>
<div className='p2p-v2-my-profile-daily-limit'>
<div className='p2p-v2-my-profile-daily-limit' data-testid='dt_p2p_v2_profile_daily_limit'>
<Text color='less-prominent' lineHeight='sm' size='xs'>
Want to increase your daily limits to{' '}
<Text color='less-prominent' lineHeight='sm' size='xs' weight='bold'>
Expand Down