Skip to content

Commit

Permalink
[FEQ] P2P-V2 Block unblock user modal test (#13666)
Browse files Browse the repository at this point in the history
* chore: removed responsive root

* chore: reverted old changes

* chore: added tests for block unblock user modal
  • Loading branch information
adrienne-deriv authored Feb 19, 2024
1 parent c13ce90 commit d4005dc
Showing 1 changed file with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 }) => (
<APIProvider>
<div id='v2_modal_root' />
{children}
</APIProvider>
);

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(
<BlockUnblockUserModal
advertiserName='Jane Doe'
id='1'
isBlocked={false}
isModalOpen={true}
onRequestClose={mockOnRequestClose}
/>,
{
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(
<BlockUnblockUserModal
advertiserName='Hu Tao'
id='2'
isBlocked={true}
isModalOpen={true}
onRequestClose={mockOnRequestClose}
/>,
{
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(
<BlockUnblockUserModal
advertiserName='Hu Tao'
id='2'
isBlocked={true}
isModalOpen={true}
onRequestClose={mockOnRequestClose}
/>,
{
wrapper,
}
);

const cancelBtn = screen.getByRole('button', {
name: 'Cancel',
});
userEvent.click(cancelBtn);

expect(mockOnRequestClose).toBeCalled();
});
});

0 comments on commit d4005dc

Please sign in to comment.