Skip to content

Commit

Permalink
chore: added tests for block unblock user modal
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienne-deriv committed Feb 19, 2024
1 parent 173f7bc commit f5de736
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 f5de736

Please sign in to comment.