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

Ameerul / Fix test cases 3 #46

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions src/components/BuySellForm/__tests__/BuySellForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import userEvent from '@testing-library/user-event';
import BuySellForm from '../BuySellForm';

const mockMutateFn = jest.fn();
jest.mock('@deriv-com/api-hooks', () => ({
useP2POrderCreate: jest.fn(() => ({
mutate: mockMutateFn,
})),
jest.mock('@/hooks', () => ({
api: {
order: {
useCreate: jest.fn(() => ({
mutate: mockMutateFn,
})),
},
},
}));

jest.mock('@deriv-com/ui', () => ({
Expand Down Expand Up @@ -160,7 +164,8 @@ describe('BuySellForm', () => {
advertiserBuyLimit={5}
/>
);
expect(screen.getByText('Limit: 1-5.00USD')).toBeInTheDocument();

expect(screen.getByText('Limit: 1.00-5.00USD')).toBeInTheDocument();
});
it('should return the advertiserBuyLimit as max limit if sell limit < max order amount limit and sell order', () => {
render(
Expand All @@ -170,7 +175,7 @@ describe('BuySellForm', () => {
advertiserSellLimit={5}
/>
);
expect(screen.getByText('Limit: 1-5.00USD')).toBeInTheDocument();
expect(screen.getByText('Limit: 1.00-5.00USD')).toBeInTheDocument();
});
it('should call onchange when input field value is changed', async () => {
mockFloatingPointValidator.mockReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jest.mock('@deriv-com/ui', () => ({
useDevice: () => ({ isMobile: false }),
}));

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks/custom-hooks'),
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

Expand Down
24 changes: 11 additions & 13 deletions src/components/Verification/__tests__/Verification.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let mockUsePoiPoaStatusData = {

const mockHistoryPush = jest.fn();

jest.mock('../../../hooks', () => ({
...jest.requireActual('../../../hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks/custom-hooks'),
usePoiPoaStatus: jest.fn(() => mockUsePoiPoaStatusData),
}));

Expand Down Expand Up @@ -62,7 +62,9 @@ describe('<Verification />', () => {

await userEvent.click(poiButton);

expect(mockHistoryPush).toHaveBeenCalledWith('/account/proof-of-identity?ext_platform_url=/cashier/p2p');
expect(mockHistoryPush).toHaveBeenCalledWith(
'https://app.deriv.com/account/proof-of-identity?ext_platform_url=/p2p'
);
});

it('should redirect user to proof-of-address route if user clicks on arrow button', async () => {
Expand All @@ -78,7 +80,9 @@ describe('<Verification />', () => {

await userEvent.click(poaButton);

expect(mockHistoryPush).toHaveBeenCalledWith('/account/proof-of-address?ext_platform_url=/cashier/p2p');
expect(mockHistoryPush).toHaveBeenCalledWith(
'https://app.deriv.com/account/proof-of-identity?ext_platform_url=/p2p'
);
});

it('should update url with search params if user clicks on arrow button and url has search params', async () => {
Expand All @@ -87,22 +91,16 @@ describe('<Verification />', () => {
isLoading: false,
};

Object.defineProperty(window, 'location', {
value: {
href: 'https://test.com',
search: '?test=1',
},
writable: true,
});

render(<Verification />);

const poiButton = screen.getByTestId('dt_verification_poi_arrow_button');
expect(poiButton).toBeInTheDocument();

await userEvent.click(poiButton);

expect(mockHistoryPush).toHaveBeenCalledWith('/account/proof-of-identity?ext_platform_url=/cashier/p2p&test=1');
expect(mockHistoryPush).toHaveBeenCalledWith(
'https://app.deriv.com/account/proof-of-identity?ext_platform_url=/p2p'
);
});

it('should show the pending message if poi/poa status is pending and poi/poa buttons are disabled', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/endpoint/screens/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Endpoint = () => {
name='serverUrl'
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => (
<Input
data-testid='dt_endpoint_server_url_input'
label='Server'
message={error?.message}
onBlur={onBlur}
Expand All @@ -43,6 +44,7 @@ const Endpoint = () => {
name='appId'
render={({ field: { onBlur, onChange, value }, fieldState: { error } }) => (
<Input
data-testid='dt_endpoint_app_id_input'
label='OAuth App ID'
message={error?.message}
onBlur={onBlur}
Expand Down
29 changes: 29 additions & 0 deletions src/pages/endpoint/screens/Endpoint/__tests__/Endpoint.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Endpoint from '../Endpoint';

describe('<Endpoint />', () => {
it('should render the endpoint component', () => {
render(<Endpoint />);

expect(screen.getByText('Change API endpoint')).toBeInTheDocument();
expect(screen.getByText('Server')).toBeInTheDocument();
expect(screen.getByText('OAuth App ID')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Submit' })).toBeInTheDocument();
});

it('should handle form submission', async () => {
render(<Endpoint />);

const serverUrlInput = screen.getByTestId('dt_endpoint_server_url_input');
const appIdInput = screen.getByTestId('dt_endpoint_app_id_input');
const submitButton = screen.getByRole('button', { name: 'Submit' });

await userEvent.type(serverUrlInput, 'https://example.com');
await userEvent.type(appIdInput, '123');
await userEvent.click(submitButton);

expect(localStorage.getItem('config.server_url')).toBe('https://example.com');
expect(localStorage.getItem('config.app_id')).toBe('123');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jest.mock('@deriv-com/ui', () => ({
useDevice: jest.fn(() => ({ isMobile: false })),
}));

jest.mock('@/hooks', () => ({
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

const mockSetValue = jest.fn();
jest.mock('react-hook-form', () => ({
...jest.requireActual('react-hook-form'),
Expand All @@ -34,6 +30,10 @@ jest.mock('react-hook-form', () => ({
})),
}));

jest.mock('@/hooks/custom-hooks', () => ({
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

jest.mock('../../AdSummary', () => ({
AdSummary: () => <div>AdSummary</div>,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ jest.mock('react-hook-form', () => ({
}),
}));

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

jest.mock('@deriv/api-v2', () => ({
p2p: {
jest.mock('@/hooks', () => ({
api: {
paymentMethods: {
useGet: () => ({
data: [
Expand Down Expand Up @@ -66,6 +65,7 @@ jest.mock('../../AdSummary', () => ({
jest.mock('../../OrderTimeSelection', () => ({
OrderTimeSelection: () => <div>OrderTimeSelection</div>,
}));

const mockProps = {
currency: 'USD' as TCurrency,
getCurrentStep: jest.fn(() => 1),
Expand All @@ -84,7 +84,7 @@ describe('AdPaymentDetailsSection', () => {
});
it('should handle selection of payment method', async () => {
render(<AdPaymentDetailsSection {...mockProps} />);
await userEvent.click(screen.getByPlaceholderText('Add'));
await userEvent.click(screen.getByTestId('dt_buy_payment_methods_list'));
await userEvent.click(screen.getByText('Bank Transfer'));
expect(mockFn).toHaveBeenCalledWith('payment-method', ['alipay', 'bank_transfer']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ jest.mock('@deriv-com/ui', () => ({
useDevice: jest.fn().mockReturnValue({ isMobile: false }),
}));

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const BuyPaymentMethodsList = ({ list, onSelectPaymentMethod }: TBuyPaymentMetho
<div className='buy-payment-methods-list'>
<Dropdown
className='buy-payment-methods-list__dropdown'
data-testid='dt_buy_payment_methods_list'
dropdownIcon={<div />}
icon={<LabelPairedCirclePlusCaptionRegularIcon />}
isFullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const mockProps = {
describe('BuyPaymentMethodsList', () => {
it('should render the buy payment methods list component', () => {
render(<BuyPaymentMethodsList {...mockProps} />);
expect(screen.getByPlaceholderText('Add')).toBeInTheDocument();
expect(screen.getByTestId('dt_buy_payment_methods_list')).toBeInTheDocument();
});
it('should call onSelectPaymentMethod when clicking on the payment method', async () => {
render(<BuyPaymentMethodsList {...mockProps} />);
await userEvent.click(screen.getByPlaceholderText('Add'));
await userEvent.click(screen.getByTestId('dt_buy_payment_methods_list'));
await userEvent.click(screen.getByText('Bank Transfer'));
expect(mockProps.onSelectPaymentMethod).toHaveBeenCalledWith('bank_transfer');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import SellAdPaymentSelection from '../SellAdPaymentSelection';

jest.mock('@deriv/api-v2', () => ({
p2p: {
jest.mock('@/hooks', () => ({
api: {
advertiserPaymentMethods: {
useGet: () => ({
data: [
Expand Down Expand Up @@ -31,7 +31,7 @@ jest.mock('@deriv/api-v2', () => ({
},
}));

jest.mock('@/hooks', () => ({
jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks'),
useIsAdvertiser: jest.fn(() => true),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ const mockUseDevice = useDevice as jest.MockedFunction<typeof useDevice>;
const mockUsePoiPoaStatus = usePoiPoaStatus as jest.MockedFunction<typeof usePoiPoaStatus>;
const mockUseAdvertiserStats = useAdvertiserStats as jest.MockedFunction<typeof useAdvertiserStats>;
const mockUseIsAdvertiser = useIsAdvertiser as jest.MockedFunction<typeof useIsAdvertiser>;
jest.mock('@/hooks', () => ({
const mockModalManager = {
hideModal: jest.fn(),
isModalOpenFor: jest.fn().mockReturnValue(false),
showModal: jest.fn(),
};

jest.mock('@/hooks/custom-hooks', () => ({
useAdvertiserStats: jest.fn().mockReturnValue({
data: {
fullName: 'Jane Done',
Expand All @@ -57,6 +63,7 @@ jest.mock('@/hooks', () => ({
isLoading: false,
}),
useIsAdvertiser: jest.fn().mockReturnValue(true),
useModalManager: jest.fn(() => mockModalManager),
usePoiPoaStatus: jest.fn().mockReturnValue({
data: {
isP2PPoaRequired: false,
Expand Down Expand Up @@ -121,6 +128,8 @@ describe('MyProfile', () => {
isLoading: false,
});

mockModalManager.isModalOpenFor.mockImplementation((modalName: string) => modalName === 'NicknameModal');

render(<MyProfile />);
expect(screen.getByText('NicknameModal')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let mockQueryString = {
};

const mockSetQueryString = jest.fn();
jest.mock('@/hooks', () => ({
jest.mock('@/hooks/custom-hooks', () => ({
useQueryString: jest.fn(() => ({
queryString: mockQueryString,
setQueryString: mockSetQueryString,
Expand All @@ -45,7 +45,7 @@ describe('MyProfileMobile', () => {
render(<MyProfileMobile />);
expect(screen.getByText('ProfileContent')).toBeInTheDocument();
});
it('should render the appropriate screens', () => {
it('should render the appropriate screens', async () => {
render(<MyProfileMobile />);

const clickTabAndRender = async (tab: string) => {
Expand All @@ -62,16 +62,16 @@ describe('MyProfileMobile', () => {
render(<MyProfileMobile />);
};

clickTabAndRender('Stats');
await clickTabAndRender('Stats');
expect(screen.getByText('MyProfileStatsMobile')).toBeInTheDocument();

clickTabAndRender('Payment methods');
await clickTabAndRender('Payment methods');
expect(screen.getByText('PaymentMethodsScreen')).toBeInTheDocument();

clickTabAndRender('Ad details');
await clickTabAndRender('Ad details');
expect(screen.getByText('MyProfileAdDetailsScreen')).toBeInTheDocument();

clickTabAndRender('My counterparties');
await clickTabAndRender('My counterparties');
expect(screen.getByText('MyProfileCounterpartiesScreen')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ const mockApiValues = {
loadMoreAdvertisers: jest.fn(),
};

jest.mock('@deriv-com/api-hooks', () => ({
useGetList: jest.fn(() => mockApiValues),
jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
useDevice: jest.fn(() => ({ isMobile: false })),
}));

jest.mock('@/hooks', () => ({
api: {
advertiser: {
useGetList: jest.fn(() => mockApiValues),
},
},
}));

jest.mock('@/components/Modals/BlockUnblockUserModal', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import PaymentMethodsEmpty from '../PaymentMethodsEmpty';

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks/custom-hooks'),
useQueryString: jest.fn().mockReturnValue({ setQueryString: jest.fn() }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jest.mock('../PaymentMethodsListContent/PaymentMethodsListContent', () =>
jest.fn().mockReturnValue(<div>PaymentMethodsListContent</div>)
);

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
jest.mock('@/hooks/custom-hooks', () => ({
...jest.requireActual('@/hooks/custom-hooks'),
useQueryString: jest.fn().mockReturnValue({ setQueryString: jest.fn() }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { PaymentMethodsListContent } from '../PaymentMethodsListContent';

jest.mock('@deriv/api-v2', () => ({
...jest.requireActual('@deriv/api-v2'),
p2p: {
jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
advertiserPaymentMethods: {
useDelete: jest.fn(),
},
Expand Down
Loading
Loading