-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEQ] P2P-V2 Block unblock user modal test (#13666)
* chore: removed responsive root * chore: reverted old changes * chore: added tests for block unblock user modal
- Loading branch information
1 parent
c13ce90
commit d4005dc
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...p-v2/src/components/Modals/BlockUnblockUserModal/__tests__/BlockUnblockUserModal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |