diff --git a/packages/p2p-v2/src/components/Modals/BlockUnblockUserModal/__tests__/BlockUnblockUserModal.spec.tsx b/packages/p2p-v2/src/components/Modals/BlockUnblockUserModal/__tests__/BlockUnblockUserModal.spec.tsx new file mode 100644 index 000000000000..5bb7d4dbebbd --- /dev/null +++ b/packages/p2p-v2/src/components/Modals/BlockUnblockUserModal/__tests__/BlockUnblockUserModal.spec.tsx @@ -0,0 +1,108 @@ +import React from 'react'; +import { APIProvider } from '@deriv/api'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import BlockUnblockUserModal from '../BlockUnblockUserModal'; + +const wrapper = ({ children }: { children: JSX.Element }) => ( + +
+ {children} + +); + +const mockOnRequestClose = jest.fn(); +const mockUseBlockMutate = jest.fn(); +const mockUseUnblockMutate = jest.fn(); + +jest.mock('@deriv/api', () => ({ + ...jest.requireActual('@deriv/api'), + p2p: { + counterparty: { + useBlock: jest.fn(() => ({ + mutate: mockUseBlockMutate, + })), + useUnblock: jest.fn(() => ({ + mutate: mockUseUnblockMutate, + })), + }, + }, +})); + +describe('BlockUnblockUserModal', () => { + it('should render the modal with correct title and behaviour for blocking user', () => { + render( + , + { + wrapper, + } + ); + + expect( + screen.queryByText( + `You won't see Jane Doe's ads anymore and they won't be able to place orders on your ads.` + ) + ).toBeVisible(); + + const blockBtn = screen.getByRole('button', { + name: 'Block', + }); + userEvent.click(blockBtn); + + expect(mockUseBlockMutate).toBeCalledWith([1]); + }); + it('should render the modal with correct title and behaviour for unblocking user', () => { + render( + , + { + wrapper, + } + ); + + expect( + screen.queryByText( + `You will be able to see Hu Tao's ads. They'll be able to place orders on your ads, too.` + ) + ).toBeVisible(); + + const unblockBtn = screen.getByRole('button', { + name: 'Unblock', + }); + userEvent.click(unblockBtn); + + expect(mockUseUnblockMutate).toBeCalledWith([2]); + }); + it('should hide the modal when user clicks cancel', () => { + render( + , + { + wrapper, + } + ); + + const cancelBtn = screen.getByRole('button', { + name: 'Cancel', + }); + userEvent.click(cancelBtn); + + expect(mockOnRequestClose).toBeCalled(); + }); +});