diff --git a/src/components/Modals/BlockUnblockUserModal/BlockUnblockUserModal.tsx b/src/components/Modals/BlockUnblockUserModal/BlockUnblockUserModal.tsx index 7b21a207..28d90254 100644 --- a/src/components/Modals/BlockUnblockUserModal/BlockUnblockUserModal.tsx +++ b/src/components/Modals/BlockUnblockUserModal/BlockUnblockUserModal.tsx @@ -41,6 +41,7 @@ const BlockUnblockUserModal = ({ return ( ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { counterparty: { useBlock: jest.fn(() => ({ mutate: mockUseBlockMutate, diff --git a/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx b/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx index 5dd8a8ae..a8728943 100644 --- a/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx +++ b/src/components/Modals/DailyLimitModal/DailyLimitModal.tsx @@ -76,6 +76,7 @@ const DailyLimitModal = ({ currency, isModalOpen, onRequestClose }: TDailyLimitM return ( // TODO: below modal will be rewritten to use @deriv/ui modal ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advertiser: { useUpdate: jest.fn(() => mockUseAdvertiserUpdate), }, @@ -25,7 +25,7 @@ jest.mock('@deriv/api-v2', () => ({ })); describe('DailyLimitModal', () => { - it('should render loader when data is not ready', () => { + it('should render loader when data is not ready', async () => { render(); expect(screen.getByTestId('dt_derivs-loader')).toBeVisible(); @@ -33,7 +33,7 @@ describe('DailyLimitModal', () => { it('should render the correct title and behaviour', async () => { mockUseAdvertiserUpdate = { ...mockUseAdvertiserUpdate, - isLoading: false, + isPending: false, isSuccess: false, }; render(); @@ -55,7 +55,7 @@ describe('DailyLimitModal', () => { it('should render the successful limits increase', async () => { mockUseAdvertiserUpdate = { ...mockUseAdvertiserUpdate, - isLoading: false, + isPending: false, isSuccess: true, }; render(); diff --git a/src/components/Modals/MyAdsDeleteModal/__tests__/MyAdsDeleteModal.spec.tsx b/src/components/Modals/MyAdsDeleteModal/__tests__/MyAdsDeleteModal.spec.tsx index 239d5542..e7992cfc 100644 --- a/src/components/Modals/MyAdsDeleteModal/__tests__/MyAdsDeleteModal.spec.tsx +++ b/src/components/Modals/MyAdsDeleteModal/__tests__/MyAdsDeleteModal.spec.tsx @@ -17,8 +17,8 @@ const mockUseGet = { isLoading: false, }; -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { advert: { useGet: jest.fn(() => mockUseGet), }, diff --git a/src/components/Modals/NicknameModal/NicknameModal.tsx b/src/components/Modals/NicknameModal/NicknameModal.tsx index 97e1cd56..4302917f 100644 --- a/src/components/Modals/NicknameModal/NicknameModal.tsx +++ b/src/components/Modals/NicknameModal/NicknameModal.tsx @@ -40,7 +40,7 @@ const NicknameModal = ({ isModalOpen, onRequestClose }: TNicknameModalProps) => useEffect(() => { if (isSuccess) { - onRequestClose; + onRequestClose(); setHasCreatedAdvertiser(true); } else if (isError) { debouncedReset(); @@ -90,7 +90,7 @@ const NicknameModal = ({ isModalOpen, onRequestClose }: TNicknameModalProps) => color='black' onClick={() => { history.push(BUY_SELL_URL); - onRequestClose; + onRequestClose(); }} size='lg' textSize={textSize} diff --git a/src/components/Modals/NicknameModal/__tests__/NicknameModal.spec.tsx b/src/components/Modals/NicknameModal/__tests__/NicknameModal.spec.tsx index deb88a39..db49c14f 100644 --- a/src/components/Modals/NicknameModal/__tests__/NicknameModal.spec.tsx +++ b/src/components/Modals/NicknameModal/__tests__/NicknameModal.spec.tsx @@ -29,9 +29,9 @@ jest.mock('@deriv-com/ui', () => ({ }), })); -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { advertiser: { useCreate: jest.fn(() => ({ error: undefined, @@ -78,7 +78,7 @@ describe('NicknameModal', () => { expect(mockedMutate).toHaveBeenCalledWith({ name: 'Nahida', }); - expect(mockUseAdvertiserInfoState().setHasCreatedAdvertiser).toBeCalledWith(true); + expect(mockUseAdvertiserInfoState().setHasCreatedAdvertiser).toHaveBeenCalledWith(true); }); it('should invoke reset when there is an error from creating advertiser', async () => { (mockedUseAdvertiserCreate as jest.Mock).mockImplementationOnce(() => ({ @@ -89,11 +89,9 @@ describe('NicknameModal', () => { reset: mockedReset, })); - await (() => { - render(); - }); + render(); - expect(mockedReset).toBeCalled(); + expect(mockedReset).toHaveBeenCalled(); }); it('should close the modal when Cancel button is clicked', async () => { (mockedUseAdvertiserCreate as jest.Mock).mockImplementationOnce(() => ({ @@ -111,7 +109,7 @@ describe('NicknameModal', () => { }); await userEvent.click(cancelBtn); - expect(mockPush).toBeCalledWith('/buy-sell'); - expect(mockProps.onRequestClose).toBeCalledWith(false); + expect(mockPush).toHaveBeenCalledWith('/buy-sell'); + expect(mockProps.onRequestClose).toHaveBeenCalled(); }); }); diff --git a/src/components/Modals/OrderDetailsComplainModal/__tests__/OrderDetailsComplainModal.spec.tsx b/src/components/Modals/OrderDetailsComplainModal/__tests__/OrderDetailsComplainModal.spec.tsx index e510c872..b6547fca 100644 --- a/src/components/Modals/OrderDetailsComplainModal/__tests__/OrderDetailsComplainModal.spec.tsx +++ b/src/components/Modals/OrderDetailsComplainModal/__tests__/OrderDetailsComplainModal.spec.tsx @@ -14,9 +14,9 @@ const mockUseDispute = { mutate: jest.fn(), }; -jest.mock('@deriv/api-v2', () => ({ - ...jest.requireActual('@deriv/api-v2'), - p2p: { +jest.mock('@/hooks', () => ({ + ...jest.requireActual('@/hooks'), + api: { orderDispute: { useDispute: () => mockUseDispute, }, diff --git a/src/components/Modals/ShareAdsModal/__tests__/ShareAdsModal.spec.tsx b/src/components/Modals/ShareAdsModal/__tests__/ShareAdsModal.spec.tsx index d76f394c..67e82122 100644 --- a/src/components/Modals/ShareAdsModal/__tests__/ShareAdsModal.spec.tsx +++ b/src/components/Modals/ShareAdsModal/__tests__/ShareAdsModal.spec.tsx @@ -1,6 +1,6 @@ import html2canvas from 'html2canvas'; import { useDevice } from '@deriv-com/ui'; -import { act, render, screen, waitFor } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import ShareAdsModal from '../ShareAdsModal'; @@ -24,8 +24,8 @@ const mockUseGet = { isLoading: false, }; -jest.mock('@deriv/api-v2', () => ({ - p2p: { +jest.mock('@/hooks', () => ({ + api: { advert: { useGet: jest.fn(() => mockUseGet), }, @@ -50,8 +50,8 @@ jest.mock('@deriv-com/ui', () => ({ })); const mockCopyFn = jest.fn(); -jest.mock('@/hooks', () => ({ - ...jest.requireActual('@/hooks'), +jest.mock('@/hooks/custom-hooks', () => ({ + ...jest.requireActual('@/hooks/custom-hooks'), useCopyToClipboard: jest.fn(() => [true, mockCopyFn, jest.fn()]), })); @@ -77,21 +77,26 @@ describe('ShareAdsModal', () => { }); it('should call onCopy function when clicking on copy icon', async () => { - jest.useFakeTimers(); + mockUseDevice.mockReturnValue({ + isDesktop: false, + isMobile: true, + }); render(); + screen.debug(undefined, 1000000); const copyButton = screen.getByRole('button', { name: 'Copy link' }); await userEvent.click(copyButton); - await act(async () => { - jest.runAllTimers(); - await Promise.resolve(); - }); expect(mockCopyFn).toHaveBeenCalledWith( `${window.location.href}advertiser/${mockUseGet.data.advertiser_details.id}?advert_id=${mockProps.id}` ); }); it('should call html2canvas function when clicking on Download this QR code button', async () => { + mockUseDevice.mockReturnValue({ + isDesktop: false, + isMobile: true, + }); + render(); const downloadButton = screen.getByRole('button', { name: 'Download this QR code' });