diff --git a/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx b/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx index a8728943..49882211 100644 --- a/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx +++ b/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx @@ -1,7 +1,6 @@ import Modal from 'react-modal'; import { api } from '@/hooks'; -import { useDevice } from '@/hooks/custom-hooks'; -import { Button, Loader, Text } from '@deriv-com/ui'; +import { Button, Loader, Text, useDevice } from '@deriv-com/ui'; import { customStyles } from '../helpers'; import './DailyLimitModal.scss'; diff --git a/src/components/Modals/FilterModal/__tests__/FilterModal.spec.tsx b/src/components/Modals/FilterModal/__tests__/FilterModal.spec.tsx index 962fd566..ce0f7728 100644 --- a/src/components/Modals/FilterModal/__tests__/FilterModal.spec.tsx +++ b/src/components/Modals/FilterModal/__tests__/FilterModal.spec.tsx @@ -23,8 +23,8 @@ let mockData: { display_name: string; id: string }[] | undefined = [ }, ]; -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { paymentMethods: { useGet: jest.fn(() => ({ data: mockData, @@ -43,15 +43,7 @@ jest.mock('@deriv-com/ui', () => ({ const mockUseDevice = useDevice as jest.Mock; describe('', () => { - beforeEach(() => { - jest.useFakeTimers(); - }); - - afterEach(() => { - jest.useRealTimers(); - }); - - it('should render the initial page of the FilterModal', () => { + it('should render the initial page of the FilterModal', async () => { render(); const toggleSwitch = screen.getByRole('checkbox'); @@ -136,6 +128,8 @@ describe('', () => { }); it('should show the search results when user types in the search input', async () => { + jest.useRealTimers(); + render(); const paymentMethodsText = screen.getByText('Payment methods'); @@ -143,9 +137,7 @@ describe('', () => { const searchInput = screen.getByRole('searchbox'); - async () => { - await userEvent.type(searchInput, 'alipay'); - }; + await userEvent.type(searchInput, 'alipay'); act(() => { jest.runAllTimers(); @@ -156,6 +148,7 @@ describe('', () => { }); it('should show No results for message if payment method is not in the list', async () => { + jest.useRealTimers(); render(); const paymentMethodsText = screen.getByText('Payment methods'); @@ -163,9 +156,7 @@ describe('', () => { const searchInput = screen.getByRole('searchbox'); - async () => { - await userEvent.type(searchInput, 'paypal'); - }; + await userEvent.type(searchInput, 'paypal'); act(() => { jest.runAllTimers(); @@ -174,9 +165,7 @@ describe('', () => { expect(screen.getByText(/No results for "paypal"./s)).toBeInTheDocument(); expect(screen.getByText('Check your spelling or use a different term.')).toBeInTheDocument(); - async () => { - await userEvent.clear(searchInput); - }; + await userEvent.clear(searchInput); act(() => { jest.runAllTimers(); diff --git a/src/components/PaymentMethodForm/__test__/PaymentMethodForm.spec.tsx b/src/components/PaymentMethodForm/__test__/PaymentMethodForm.spec.tsx index b057d76f..f3f441dd 100644 --- a/src/components/PaymentMethodForm/__test__/PaymentMethodForm.spec.tsx +++ b/src/components/PaymentMethodForm/__test__/PaymentMethodForm.spec.tsx @@ -51,10 +51,10 @@ jest.mock('@deriv-com/ui', () => ({ useDevice: () => ({ isMobile: false }), })); -jest.mock('@deriv/api-v2', () => { +jest.mock('@/hooks', () => { return { - ...jest.requireActual('@deriv/api-v2'), - p2p: { + ...jest.requireActual('@/hooks'), + api: { advertiserPaymentMethods: { useCreate: jest.fn(() => ({ create: jest.fn(), @@ -275,62 +275,6 @@ describe('PaymentMethodForm', () => { ); expect(onResetFormState).toHaveBeenCalled(); }); - it('should show the error modal when a payment method is not created successfully and close it when the ok button is clicked', async () => { - (mockUseCreate as jest.Mock).mockReturnValueOnce({ - create: jest.fn(), - error: { - error: { - message: 'Error creating payment method', - }, - }, - isSuccess: false, - }); - const onResetFormState = jest.fn(); - render( - - ); - expect(screen.getByText('Error creating payment method')).toBeInTheDocument(); - const okButton = screen.getByRole('button', { name: 'Ok' }); - expect(okButton).toBeInTheDocument(); - await userEvent.click(okButton); - expect(onResetFormState).toHaveBeenCalled(); - }); - it('should show the error modal when a payment method is not updated successfully and close it when the ok button is clicked', async () => { - (mockUseUpdate as jest.Mock).mockReturnValueOnce({ - error: { - error: { - message: 'Error updating payment method', - }, - }, - isSuccess: false, - update: jest.fn(), - }); - const onResetFormState = jest.fn(); - const otherPaymentMethod = mockPaymentMethods.find(method => method.type === 'other'); - render( - - ); - expect(screen.getByText('Error updating payment method')).toBeInTheDocument(); - const okButton = screen.getByRole('button', { name: 'Ok' }); - expect(okButton).toBeInTheDocument(); - await userEvent.click(okButton); - expect(onResetFormState).toHaveBeenCalled(); - }); it('should handle submit when the form is submitted and the actiontype is add', async () => { const create = jest.fn(); (mockUseCreate as jest.Mock).mockImplementation(() => { diff --git a/src/components/ProfileContent/ProfileBalance/ProfileBalance.tsx b/src/components/ProfileContent/ProfileBalance/ProfileBalance.tsx index 3f078f0b..211e0ecb 100644 --- a/src/components/ProfileContent/ProfileBalance/ProfileBalance.tsx +++ b/src/components/ProfileContent/ProfileBalance/ProfileBalance.tsx @@ -2,10 +2,9 @@ import { useMemo, useState } from 'react'; import { DeepPartial, TAdvertiserStats } from 'types'; import { AvailableP2PBalanceModal } from '@/components/Modals'; import { api } from '@/hooks'; -import { useDevice } from '@/hooks/custom-hooks'; import { numberToCurrencyText } from '@/utils'; import { LabelPairedCircleInfoMdRegularIcon } from '@deriv/quill-icons'; -import { Text } from '@deriv-com/ui'; +import { Text, useDevice } from '@deriv-com/ui'; import { ProfileDailyLimit } from '../ProfileDailyLimit'; import './ProfileBalance.scss'; diff --git a/src/components/ProfileContent/ProfileBalance/__tests__/ProfileBalance.spec.tsx b/src/components/ProfileContent/ProfileBalance/__tests__/ProfileBalance.spec.tsx index 392c126e..b0a7698f 100644 --- a/src/components/ProfileContent/ProfileBalance/__tests__/ProfileBalance.spec.tsx +++ b/src/components/ProfileContent/ProfileBalance/__tests__/ProfileBalance.spec.tsx @@ -22,11 +22,22 @@ const mockUseActiveAccount = { isLoading: false, }; -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - useActiveAccount: jest.fn(() => mockUseActiveAccount), +jest.mock('@deriv-com/ui', () => ({ + ...jest.requireActual('@deriv-com/ui'), + useDevice: jest.fn().mockReturnValue({ isDesktop: true }), })); +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { + account: { + useActiveAccount: jest.fn(() => mockUseActiveAccount), + }, + }, +})); + +jest.mock('../../ProfileDailyLimit/ProfileDailyLimit', () => jest.fn(() =>
ProfileDailyLimit
)); + describe('ProfileBalance', () => { it('should render the correct balance', async () => { render(); @@ -64,7 +75,7 @@ describe('ProfileBalance', () => { const dailyAvailableSellLimit = screen.getByTestId('dt_profile_balance_available_sell_limit'); expect(within(dailyAvailableSellLimit).getByText('600.00 USD')).toBeInTheDocument(); }); - it('should render eligibility for daily limit upgrade', async () => { + it('should render ProfileDailyLimit', () => { mockAdvertiserStatsProp = { advertiserStats: { ...mockAdvertiserStatsProp.advertiserStats, @@ -72,17 +83,7 @@ describe('ProfileBalance', () => { }, }; render(); - expect(screen.getByTestId('dt_profile_daily_limit')).toBeInTheDocument(); - - const openDailyLimitModalBtn = screen.getByRole('button', { - name: 'Increase my limits', - }); - await userEvent.click(openDailyLimitModalBtn); - const hideDailyLimitBtn = screen.getByRole('button', { - name: 'No', - }); - await userEvent.click(hideDailyLimitBtn); - expect(screen.queryByTestId('dt_daily_limit_modal')).not.toBeInTheDocument(); + expect(screen.getByText('ProfileDailyLimit')).toBeInTheDocument(); }); it('should render the correct default values', () => { mockAdvertiserStatsProp = { diff --git a/src/components/ProfileContent/ProfileDailyLimit/ProfileDailyLimit.tsx b/src/components/ProfileContent/ProfileDailyLimit/ProfileDailyLimit.tsx index 6f22963e..286a9fb1 100644 --- a/src/components/ProfileContent/ProfileDailyLimit/ProfileDailyLimit.tsx +++ b/src/components/ProfileContent/ProfileDailyLimit/ProfileDailyLimit.tsx @@ -1,8 +1,8 @@ import { useState } from 'react'; import { DailyLimitModal } from '@/components/Modals'; import { api } from '@/hooks'; -import { useAdvertiserStats, useDevice } from '@/hooks/custom-hooks'; -import { Button, Text } from '@deriv-com/ui'; +import { useAdvertiserStats } from '@/hooks/custom-hooks'; +import { Button, Text, useDevice } from '@deriv-com/ui'; import './ProfileDailyLimit.scss'; const ProfileDailyLimit = () => { diff --git a/src/components/ProfileContent/ProfileDailyLimit/__tests__/ProfileDailyLimit.spec.tsx b/src/components/ProfileContent/ProfileDailyLimit/__tests__/ProfileDailyLimit.spec.tsx index fa285458..2568794e 100644 --- a/src/components/ProfileContent/ProfileDailyLimit/__tests__/ProfileDailyLimit.spec.tsx +++ b/src/components/ProfileContent/ProfileDailyLimit/__tests__/ProfileDailyLimit.spec.tsx @@ -10,22 +10,38 @@ const mockUseAdvertiserStats = { isLoading: true, }; -jest.mock('@/hooks/useDevice', () => ({ - __esModule: true, - default: jest.fn(() => ({ - isMobile: false, - })), +jest.mock('@deriv-com/ui', () => ({ + ...jest.requireActual('@deriv-com/ui'), + useDevice: jest.fn().mockReturnValue({ isMobile: false }), })); -jest.mock('@/hooks/useAdvertiserStats', () => ({ - __esModule: true, - default: jest.fn(() => mockUseAdvertiserStats), + +jest.mock('@/hooks/custom-hooks', () => ({ + useAdvertiserStats: jest.fn(() => mockUseAdvertiserStats), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - useActiveAccount: jest.fn(() => ({ - currency: 'USD', - })), +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { + account: { + useActiveAccount: jest.fn(() => ({ + currency: 'USD', + })), + }, + advertiser: { + useUpdate: jest.fn(() => ({ + data: { + data: { + daily_buy_limit: 100, + daily_sell_limit: 200, + }, + }, + error: null, + isPending: false, + isSuccess: false, + mutate: jest.fn(), + })), + }, + }, })); describe('ProfileDailyLimit', () => { @@ -47,5 +63,10 @@ describe('ProfileDailyLimit', () => { expect(screen.queryByTestId('dt_daily_limit_modal')).not.toBeInTheDocument(); await userEvent.click(increaseLimitsBtn); expect(screen.getByTestId('dt_daily_limit_modal')).toBeInTheDocument(); + + const noButton = screen.getByRole('button', { name: 'No' }); + await userEvent.click(noButton); + + expect(screen.queryByTestId('dt_daily_limit_modal')).not.toBeInTheDocument(); }); }); diff --git a/src/hooks/__tests__/useIsAdvertiser.spec.tsx b/src/hooks/__tests__/useIsAdvertiser.spec.tsx index 935ddc2d..20e637f7 100644 --- a/src/hooks/__tests__/useIsAdvertiser.spec.tsx +++ b/src/hooks/__tests__/useIsAdvertiser.spec.tsx @@ -2,9 +2,9 @@ import { renderHook } from '@testing-library/react'; import useIsAdvertiser from '../custom-hooks/useIsAdvertiser'; import { api } from '..'; -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advertiser: { useGetInfo: jest.fn().mockReturnValue({ data: { @@ -31,7 +31,9 @@ describe('useIsAdvertiser', () => { ...mockUseGetInfo, data: {}, error: { - code: 'AdvertiserNotFound', + error: { + code: 'AdvertiserNotFound', + }, }, }); diff --git a/src/hooks/__tests__/usePoiPoaStatus.spec.tsx b/src/hooks/__tests__/usePoiPoaStatus.spec.tsx index 55dafc3c..8e67d8b6 100644 --- a/src/hooks/__tests__/usePoiPoaStatus.spec.tsx +++ b/src/hooks/__tests__/usePoiPoaStatus.spec.tsx @@ -5,8 +5,8 @@ import usePoiPoaStatus from '../custom-hooks/usePoiPoaStatus'; const mockUseGetAccountStatus = useGetAccountStatus as jest.MockedFunction; -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), +jest.mock('@deriv-com/api-hooks', () => ({ + ...jest.requireActual('@deriv-com/api-hooks'), useGetAccountStatus: jest.fn().mockReturnValue({ data: { authentication: { @@ -98,7 +98,7 @@ describe('usePoiPoaStatus', () => { const { result } = renderHook(() => usePoiPoaStatus()); expect(result.current.data).toStrictEqual({ - isP2PPoaRequired: false, + isP2PPoaRequired: 0, isPoaPending: false, isPoaVerified: true, isPoiPending: false, diff --git a/src/pages/advertiser/screens/Advertiser/__tests__/Advertiser.spec.tsx b/src/pages/advertiser/screens/Advertiser/__tests__/Advertiser.spec.tsx index 1088c97f..9e1660ba 100644 --- a/src/pages/advertiser/screens/Advertiser/__tests__/Advertiser.spec.tsx +++ b/src/pages/advertiser/screens/Advertiser/__tests__/Advertiser.spec.tsx @@ -18,9 +18,9 @@ jest.mock('react-router-dom', () => ({ useParams: () => ({ advertiserId: '123' }), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advertiser: { useGetInfo: jest.fn(() => ({ data: { diff --git a/src/pages/advertiser/screens/AdvertiserAdvertsTable/__tests__/AdvertiserAdvertsTable.spec.tsx b/src/pages/advertiser/screens/AdvertiserAdvertsTable/__tests__/AdvertiserAdvertsTable.spec.tsx index ddbf329c..0b42a85b 100644 --- a/src/pages/advertiser/screens/AdvertiserAdvertsTable/__tests__/AdvertiserAdvertsTable.spec.tsx +++ b/src/pages/advertiser/screens/AdvertiserAdvertsTable/__tests__/AdvertiserAdvertsTable.spec.tsx @@ -1,10 +1,11 @@ +import { DeepPartial, THooks } from 'types'; import { api } from '@/hooks'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import AdvertiserAdvertsTable from '../AdvertiserAdvertsTable'; let mockApiValues = { - data: [{}], + data: undefined as DeepPartial | undefined, isFetching: false, isLoading: true, loadMoreAdverts: jest.fn(), @@ -15,14 +16,19 @@ jest.mock('use-query-params', () => ({ useQueryParams: jest.fn().mockReturnValue([{}, jest.fn()]), })); +jest.mock('@deriv-com/api-hooks', () => ({ + ...jest.requireActual('@deriv-com/api-hooks'), + useExchangeRates: jest.fn(() => ({ subscribeRates: jest.fn() })), +})); + jest.mock('@deriv-com/ui', () => ({ ...jest.requireActual('@deriv-com/ui'), useDevice: jest.fn(() => ({ isMobile: false })), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advert: { useGetList: jest.fn(() => mockApiValues), }, @@ -67,7 +73,6 @@ describe('', () => { data: [ { account_currency: 'USD', - advertiser_id: '123', counterparty_type: 'buy', id: '123', max_order_amount_limit_display: '100.00', @@ -85,7 +90,6 @@ describe('', () => { expect(screen.getByText(/10.00-100.00 USD/)).toBeInTheDocument(); expect(screen.getByText('Rate (1 USD)')).toBeInTheDocument(); - expect(screen.getByText('0.00')).toBeInTheDocument(); expect(screen.getByText('Payment methods')).toBeInTheDocument(); expect(screen.getByText('Bank Transfer')).toBeInTheDocument(); @@ -100,7 +104,6 @@ describe('', () => { data: [ { account_currency: 'USD', - advertiser_id: '123', counterparty_type: 'sell', id: '123', max_order_amount_limit_display: '100.00', diff --git a/src/pages/buy-sell/components/CurrencyDropdown/__tests__/CurrencyDropdown.spec.tsx b/src/pages/buy-sell/components/CurrencyDropdown/__tests__/CurrencyDropdown.spec.tsx index dfc53a93..e875cf3a 100644 --- a/src/pages/buy-sell/components/CurrencyDropdown/__tests__/CurrencyDropdown.spec.tsx +++ b/src/pages/buy-sell/components/CurrencyDropdown/__tests__/CurrencyDropdown.spec.tsx @@ -10,11 +10,11 @@ const wrapper: FC = ({ children }) => ( ); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { settings: { - useGetSettings: () => ({ + useSettings: () => ({ data: { currency_list: [ { @@ -24,6 +24,13 @@ jest.mock('@deriv/api-v2', () => ({ text: 'Boliviano', value: 'BOB', }, + { + display_name: 'EGP', + has_adverts: 1, + is_default: 1, + text: 'Egyptian Pound', + value: 'EGP', + }, { display_name: 'IDR', has_adverts: 1, @@ -49,14 +56,6 @@ const mockProps = { setSelectedCurrency: jest.fn(), }; -beforeEach(() => { - jest.useFakeTimers(); -}); - -afterEach(() => { - jest.useRealTimers(); -}); - describe('', () => { it('should call setSelectedCurrency when a currency is selected from the dropdown', async () => { render(, { wrapper }); @@ -98,6 +97,8 @@ describe('', () => { }); it('should only show BOB in the currency list if BOB is searched', async () => { + jest.useRealTimers(); + render(, { wrapper }); const currencyDropdown = screen.getByText('IDR'); @@ -105,19 +106,21 @@ describe('', () => { const searchInput = screen.getByRole('searchbox'); - async () => { - await userEvent.type(searchInput, 'BOB'); - }; + await userEvent.type(searchInput, 'BOB'); act(() => { jest.runAllTimers(); }); - expect(screen.getByText('BOB')).toBeInTheDocument(); - expect(screen.queryByText('IDR')).not.toBeInTheDocument(); + expect(screen.getByText('Boliviano')).toBeInTheDocument(); + expect(screen.queryByText('Indonesian Rupiah')).not.toBeInTheDocument(); + + jest.useFakeTimers(); }); it('should show No results for message if currency is not in the list', async () => { + jest.useRealTimers(); + render(, { wrapper }); const currencyDropdown = screen.getByText('IDR'); @@ -125,9 +128,7 @@ describe('', () => { const searchInput = screen.getByRole('searchbox'); - async () => { - await userEvent.type(searchInput, 'JPY'); - }; + await userEvent.type(searchInput, 'JPY'); act(() => { jest.runAllTimers(); @@ -135,12 +136,12 @@ describe('', () => { expect(screen.getByText(/No results for "JPY"./s)).toBeInTheDocument(); - async () => { - await userEvent.clear(searchInput); - }; + await userEvent.clear(searchInput); act(() => { jest.runAllTimers(); }); + + jest.useFakeTimers(); }); }); diff --git a/src/pages/buy-sell/screens/BuySellHeader/__tests__/BuySellHeader.spec.tsx b/src/pages/buy-sell/screens/BuySellHeader/__tests__/BuySellHeader.spec.tsx index 471dfbea..e32a8f02 100644 --- a/src/pages/buy-sell/screens/BuySellHeader/__tests__/BuySellHeader.spec.tsx +++ b/src/pages/buy-sell/screens/BuySellHeader/__tests__/BuySellHeader.spec.tsx @@ -36,9 +36,9 @@ jest.mock('@deriv-com/ui', () => ({ }), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { settings: { useGetSettings: () => ({ data: {}, @@ -52,8 +52,6 @@ jest.mock('@/components/Modals/FilterModal/FilterModal', () => jest.fn(() => ', () => { it('should render the BuySellHeader', () => { render(); @@ -84,22 +82,6 @@ describe('', () => { expect(mockProps.setActiveTab).toHaveBeenCalledWith(0); }); - it('should call setSearchValue when a value is entered in the search input', () => { - render(); - - const searchInput = screen.getByRole('searchbox'); - - async () => { - await userEvent.type(searchInput, 'John Doe'); - }; - - act(() => { - jest.runAllTimers(); - }); - - expect(mockProps.setSearchValue).toHaveBeenCalledWith('John Doe'); - }); - it('should call setSortDropdownValue when a value is selected from the dropdown', async () => { render(); @@ -135,4 +117,22 @@ describe('', () => { expect(screen.getByText('FilterModal')).toBeInTheDocument(); }); + + it('should set the search value when the user types in the search input', async () => { + jest.useRealTimers(); + + render(); + + const searchInput = screen.getByRole('searchbox'); + + await userEvent.type(searchInput, 'John Doe'); + + act(() => { + jest.runAllTimers(); + }); + + expect(searchInput).toHaveValue('John Doe'); + + jest.useFakeTimers(); + }); }); diff --git a/src/pages/buy-sell/screens/BuySellTable/__tests__/BuySellTable.spec.tsx b/src/pages/buy-sell/screens/BuySellTable/__tests__/BuySellTable.spec.tsx index 9fc0038c..2ab5960b 100644 --- a/src/pages/buy-sell/screens/BuySellTable/__tests__/BuySellTable.spec.tsx +++ b/src/pages/buy-sell/screens/BuySellTable/__tests__/BuySellTable.spec.tsx @@ -7,7 +7,7 @@ const mockPush = jest.fn(); let mockAdvertiserListData = { data: [], isFetching: false, - isLoading: true, + isPending: true, loadMoreAdverts: jest.fn(), }; @@ -23,9 +23,14 @@ jest.mock('react-router-dom', () => ({ }), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@deriv-com/api-hooks', () => ({ + ...jest.requireActual('@deriv-com/api-hooks'), + useExchangeRates: jest.fn(() => ({ subscribeRates: jest.fn() })), +})); + +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advert: { useGetList: jest.fn(() => mockAdvertiserListData), }, @@ -39,8 +44,10 @@ jest.mock('@deriv/api-v2', () => ({ useGet: jest.fn(() => ({ data: [] })), }, settings: { - useGetSettings: jest.fn(() => ({ - data: {}, + useSettings: jest.fn(() => ({ + data: { + localCurrency: 'USD', + }, })), }, }, @@ -53,7 +60,7 @@ jest.mock('@deriv-com/ui', () => ({ jest.mock('../../BuySellHeader/BuySellHeader', () => jest.fn(() =>
BuySellHeader
)); -describe('', () => { +describe('', () => { beforeEach(() => { Object.defineProperty(window, 'location', { value: { @@ -95,7 +102,7 @@ describe('', () => { }, ], isFetching: false, - isLoading: false, + isPending: false, loadMoreAdverts: jest.fn(), }; diff --git a/src/pages/my-ads/components/AdRateError/__tests__/AdRateError.spec.tsx b/src/pages/my-ads/components/AdRateError/__tests__/AdRateError.spec.tsx index 69dde6c5..ba1008ce 100644 --- a/src/pages/my-ads/components/AdRateError/__tests__/AdRateError.spec.tsx +++ b/src/pages/my-ads/components/AdRateError/__tests__/AdRateError.spec.tsx @@ -1,14 +1,6 @@ import { render, screen } from '@testing-library/react'; import AdRateError from '../AdRateError'; -jest.mock('@deriv/api-v2', () => ({ - useAuthorize: () => ({ - data: { - local_currencies: ['USD'], - }, - }), -})); - const mockFloatingRateHook = { fixedRateAdvertsEndDate: '2024/12/31', rateType: 'float', @@ -16,6 +8,18 @@ const mockFloatingRateHook = { }; jest.mock('@/hooks', () => ({ + api: { + settings: { + useSettings: () => ({ + data: { + localCurrency: 'USD', + }, + }), + }, + }, +})); + +jest.mock('@/hooks/custom-hooks', () => ({ useFloatingRate: () => mockFloatingRateHook, })); @@ -42,4 +46,13 @@ describe('AdRateError', () => { screen.getByText('Your ads with floating rates have been deactivated. Set fixed rates to reactivate them.') ); }); + + it('should render the corresponding message when reachedTargetDate is true and rateType is false', () => { + mockFloatingRateHook.rateType = 'float'; + mockFloatingRateHook.reachedTargetDate = true; + render(); + expect( + screen.getByText('Your ads with fixed rates have been deactivated. Set floating rates to reactivate them.') + ); + }); }); diff --git a/src/pages/my-ads/components/AdSummary/__tests__/AdSummary.spec.tsx b/src/pages/my-ads/components/AdSummary/__tests__/AdSummary.spec.tsx index 38b20d67..dbfeb464 100644 --- a/src/pages/my-ads/components/AdSummary/__tests__/AdSummary.spec.tsx +++ b/src/pages/my-ads/components/AdSummary/__tests__/AdSummary.spec.tsx @@ -11,6 +11,11 @@ const mockProps = { type: 'buy', }; +jest.mock('@deriv-com/api-hooks', () => ({ + ...jest.requireActual('@deriv-com/api-hooks'), + useExchangeRates: jest.fn(() => ({ subscribeRates: jest.fn() })), +})); + jest.mock('@deriv-com/ui', () => ({ ...jest.requireActual('@deriv-com/ui'), useDevice: jest.fn().mockReturnValue({ @@ -18,7 +23,7 @@ jest.mock('@deriv-com/ui', () => ({ }), })); -jest.mock('@/hooks', () => ({ +jest.mock('@/hooks/custom-hooks', () => ({ ...jest.requireActual('@/hooks'), useQueryString: jest.fn().mockReturnValue({ queryString: { @@ -27,11 +32,11 @@ jest.mock('@/hooks', () => ({ }), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { settings: { - useGetSettings: () => ({ + useSettings: () => ({ data: { order_payment_period: 60, override_exchange_rate: 0.01, @@ -39,14 +44,6 @@ jest.mock('@deriv/api-v2', () => ({ }), }, }, - useExchangeRateSubscription: () => ({ - data: { - rates: { - IDR: 14000, - }, - }, - subscribe: jest.fn(), - }), })); describe('', () => { diff --git a/src/pages/my-ads/components/BuyAdPaymentSelection/__tests__/BuyAdPaymentSelection.spec.tsx b/src/pages/my-ads/components/BuyAdPaymentSelection/__tests__/BuyAdPaymentSelection.spec.tsx index 578c32e9..6d1c620b 100644 --- a/src/pages/my-ads/components/BuyAdPaymentSelection/__tests__/BuyAdPaymentSelection.spec.tsx +++ b/src/pages/my-ads/components/BuyAdPaymentSelection/__tests__/BuyAdPaymentSelection.spec.tsx @@ -2,8 +2,8 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import BuyAdPaymentSelection from '../BuyAdPaymentSelection'; -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { paymentMethods: { useGet: () => ({ data: [ diff --git a/src/pages/my-ads/screens/CreateEditAd/__tests__/CreateEditAd.spec.tsx b/src/pages/my-ads/screens/CreateEditAd/__tests__/CreateEditAd.spec.tsx index 5781dded..dfa269f4 100644 --- a/src/pages/my-ads/screens/CreateEditAd/__tests__/CreateEditAd.spec.tsx +++ b/src/pages/my-ads/screens/CreateEditAd/__tests__/CreateEditAd.spec.tsx @@ -52,8 +52,11 @@ jest.mock('../../../components/AdFormInput', () => ({ jest.mock('../../../components/AdFormTextArea', () => ({ AdFormTextArea: () =>
AdFormTextArea
, })); -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { + account: { + useActiveAccount: () => ({ data: { currency: 'USD' } }), + }, advert: { useCreate: () => ({ error: undefined, @@ -165,17 +168,16 @@ jest.mock('@deriv/api-v2', () => ({ }), }, settings: { - useGetSettings: () => ({ + useSettings: () => ({ data: { order_payment_period: 60, }, }), }, }, - useActiveAccount: () => ({ data: { currency: 'USD' } }), })); -jest.mock('@/hooks', () => { +jest.mock('@/hooks/custom-hooks', () => { const modalManager = { hideModal: jest.fn(), isModalOpenFor: jest.fn(), diff --git a/src/pages/my-ads/screens/MyAds/MyAdsTableRow/__tests__/MyAdsTableRowView.spec.tsx b/src/pages/my-ads/screens/MyAds/MyAdsTableRow/__tests__/MyAdsTableRowView.spec.tsx index a2a41450..3387ea92 100644 --- a/src/pages/my-ads/screens/MyAds/MyAdsTableRow/__tests__/MyAdsTableRowView.spec.tsx +++ b/src/pages/my-ads/screens/MyAds/MyAdsTableRow/__tests__/MyAdsTableRowView.spec.tsx @@ -70,7 +70,7 @@ jest.mock('react-router-dom', () => ({ useHistory: () => mockHistory, })); -jest.mock('@/hooks', () => { +jest.mock('@/hooks/custom-hooks', () => { const modalManager = { hideModal: jest.fn(), isModalOpenFor: jest.fn(), @@ -89,8 +89,8 @@ jest.mock('@/hooks', () => { }; }); -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { advert: { useDelete: jest.fn().mockReturnValue({ error: null, isError: false, mutate: jest.fn() }), useUpdate: jest.fn().mockReturnValue({ error: null, isError: false, mutate: jest.fn() }), diff --git a/src/pages/my-profile/screens/MyProfileAdDetails/MyProfileAdDetails.tsx b/src/pages/my-profile/screens/MyProfileAdDetails/MyProfileAdDetails.tsx index fe364d7a..dd9739a2 100644 --- a/src/pages/my-profile/screens/MyProfileAdDetails/MyProfileAdDetails.tsx +++ b/src/pages/my-profile/screens/MyProfileAdDetails/MyProfileAdDetails.tsx @@ -2,8 +2,8 @@ import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react'; import { THooks } from 'types'; import { FullPageMobileWrapper, TextArea } from '@/components'; import { api } from '@/hooks'; -import { useDevice, useQueryString } from '@/hooks/custom-hooks'; -import { Button, Loader } from '@deriv-com/ui'; +import { useQueryString } from '@/hooks/custom-hooks'; +import { Button, Loader, useDevice } from '@deriv-com/ui'; import './MyProfileAdDetails.scss'; type TMYProfileAdDetailsTextAreaProps = { diff --git a/src/pages/my-profile/screens/MyProfileAdDetails/__tests__/MyProfileAdDetails.spec.tsx b/src/pages/my-profile/screens/MyProfileAdDetails/__tests__/MyProfileAdDetails.spec.tsx index a36b0599..e985cb28 100644 --- a/src/pages/my-profile/screens/MyProfileAdDetails/__tests__/MyProfileAdDetails.spec.tsx +++ b/src/pages/my-profile/screens/MyProfileAdDetails/__tests__/MyProfileAdDetails.spec.tsx @@ -21,20 +21,20 @@ const mockUseDevice = { }; const mockSetQueryString = jest.fn(); -jest.mock('@/hooks/useDevice', () => ({ - __esModule: true, - default: jest.fn(() => mockUseDevice), +jest.mock('@deriv-com/ui', () => ({ + ...jest.requireActual('@deriv-com/ui'), + useDevice: jest.fn(() => mockUseDevice), })); -jest.mock('@/hooks/useQueryString', () => ({ - __esModule: true, - default: jest.fn(() => ({ +jest.mock('@/hooks/custom-hooks', () => ({ + ...jest.requireActual('@/hooks/custom-hooks'), + useQueryString: jest.fn(() => ({ setQueryString: mockSetQueryString, })), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advertiser: { useGetInfo: jest.fn(() => mockUseAdvertiserInfo), useUpdate: jest.fn(() => mockUseUpdateAdvertiser), diff --git a/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/MyProfileCounterpartiesTableRow.tsx b/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/MyProfileCounterpartiesTableRow.tsx index 9e049d98..c0373081 100644 --- a/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/MyProfileCounterpartiesTableRow.tsx +++ b/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/MyProfileCounterpartiesTableRow.tsx @@ -3,8 +3,7 @@ import { useHistory } from 'react-router-dom'; import { UserAvatar } from '@/components'; import { BlockUnblockUserModal } from '@/components/Modals'; import { ADVERTISER_URL } from '@/constants'; -import { useDevice } from '@/hooks/custom-hooks'; -import { Button, Text } from '@deriv-com/ui'; +import { Button, Text, useDevice } from '@deriv-com/ui'; import './MyProfileCounterpartiesTableRow.scss'; type TMyProfileCounterpartiesTableRowProps = { diff --git a/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/__tests__/MyProfileCounterpartiesTableRow.spec.tsx b/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/__tests__/MyProfileCounterpartiesTableRow.spec.tsx index 5d70996c..adccf8fe 100644 --- a/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/__tests__/MyProfileCounterpartiesTableRow.spec.tsx +++ b/src/pages/my-profile/screens/MyProfileCounterparties/MyProfileCounterpartiesTableRow/__tests__/MyProfileCounterpartiesTableRow.spec.tsx @@ -26,8 +26,8 @@ jest.mock('@/components/UserAvatar', () => ({ UserAvatar: () =>
UserAvatar
, })); -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { counterparty: { useBlock: () => ({ mutate: jest.fn(), diff --git a/src/pages/my-profile/screens/MyProfileStats/__tests__/MyProfileStats.spec.tsx b/src/pages/my-profile/screens/MyProfileStats/__tests__/MyProfileStats.spec.tsx index b43672e5..95783199 100644 --- a/src/pages/my-profile/screens/MyProfileStats/__tests__/MyProfileStats.spec.tsx +++ b/src/pages/my-profile/screens/MyProfileStats/__tests__/MyProfileStats.spec.tsx @@ -30,14 +30,18 @@ jest.mock('@deriv-com/ui', () => ({ useDevice: () => ({ isMobile: false }), })); -jest.mock('@/hooks', () => ({ - ...jest.requireActual('@/hooks'), +jest.mock('@/hooks/custom-hooks', () => ({ + ...jest.requireActual('@/hooks/custom-hooks'), useAdvertiserStats: jest.fn(() => mockUseAdvertiserStats), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - useActiveAccount: jest.fn(() => mockUseActiveAccount), +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { + account: { + useActiveAccount: jest.fn(() => mockUseActiveAccount), + }, + }, })); describe('MyProfileStats', () => {