forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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 update advert (deriv-com#14509)
* feat: update advert * fix: failing test fix * fix: style fixes * fix: route -changes
- Loading branch information
1 parent
220baf3
commit 0ae2b0a
Showing
31 changed files
with
586 additions
and
188 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/p2p-v2/src/components/Modals/AdCancelCreateEditModal/AdCancelCreateEditModal.scss
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,31 @@ | ||
.p2p-v2-ad-cancel-create-edit-modal { | ||
border-radius: 8px; | ||
width: 44rem; | ||
height: fit-content; | ||
@include mobile { | ||
max-width: calc(100vw - 3.2rem); | ||
} | ||
|
||
&__header { | ||
height: unset; | ||
padding: 2.4rem; | ||
@include mobile { | ||
padding: 1.6rem; | ||
} | ||
} | ||
&__body { | ||
padding: 0.8rem 2.4rem; | ||
@include mobile { | ||
padding: 0.8rem 1.6rem; | ||
} | ||
} | ||
|
||
&__footer { | ||
gap: 0.8rem; | ||
padding-bottom: 2.4rem; | ||
|
||
@include mobile { | ||
padding-bottom: 1.6rem; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/p2p-v2/src/components/Modals/AdCancelCreateEditModal/AdCancelCreateEditModal.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,55 @@ | ||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { MY_ADS_URL } from '@/constants'; | ||
import { useQueryString } from '@/hooks'; | ||
import { Button, Modal, Text, useDevice } from '@deriv-com/ui'; | ||
import './AdCancelCreateEditModal.scss'; | ||
|
||
type TAdCancelCreateEditModalProps = { | ||
isModalOpen: boolean; | ||
onRequestClose: () => void; | ||
}; | ||
|
||
const AdCancelCreateEditModal = ({ isModalOpen, onRequestClose }: TAdCancelCreateEditModalProps) => { | ||
const { isMobile } = useDevice(); | ||
const history = useHistory(); | ||
const { queryString } = useQueryString(); | ||
const { advertId = '' } = queryString; | ||
const isEdit = !!advertId; | ||
const textSize = isMobile ? 'md' : 'sm'; | ||
return ( | ||
<Modal | ||
ariaHideApp={false} | ||
className='p2p-v2-ad-cancel-create-edit-modal' | ||
isOpen={isModalOpen} | ||
shouldCloseOnOverlayClick={false} | ||
> | ||
<Modal.Header className='p2p-v2-ad-cancel-create-edit-modal__header' hideBorder hideCloseIcon> | ||
<Text weight='bold'>{isEdit ? 'Cancel your edits?' : 'Cancel ad creation?'}</Text> | ||
</Modal.Header> | ||
<Modal.Body className='p2p-v2-ad-cancel-create-edit-modal__body'> | ||
<Text size='sm'> | ||
{isEdit | ||
? `If you choose to cancel, the edited details will be lost.` | ||
: `If you choose to cancel, the details you've entered will be lost.`} | ||
</Text> | ||
</Modal.Body> | ||
<Modal.Footer className='p2p-v2-ad-cancel-create-edit-modal__footer' hideBorder> | ||
<Button | ||
color='black' | ||
onClick={() => history.push(MY_ADS_URL)} | ||
size='lg' | ||
textSize={textSize} | ||
variant='outlined' | ||
> | ||
Cancel | ||
</Button> | ||
<Button onClick={onRequestClose} size='lg' textSize={textSize}> | ||
Don’t cancel | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AdCancelCreateEditModal; |
53 changes: 53 additions & 0 deletions
53
.../src/components/Modals/AdCancelCreateEditModal/__tests__/AdCancelCreateEditModal.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,53 @@ | ||
import React from 'react'; | ||
import { MY_ADS_URL } from '@/constants'; | ||
import { useQueryString } from '@/hooks'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import AdCancelCreateEditModal from '../AdCancelCreateEditModal'; | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
...jest.requireActual('@deriv-com/ui'), | ||
useDevice: () => ({ isMobile: false }), | ||
})); | ||
|
||
jest.mock('@/hooks', () => ({ | ||
...jest.requireActual('@/hooks'), | ||
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }), | ||
})); | ||
|
||
const mockUseQueryString = useQueryString as jest.Mock; | ||
|
||
const mockFn = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: () => ({ push: mockFn }), | ||
})); | ||
|
||
const mockProps = { | ||
isModalOpen: true, | ||
onRequestClose: jest.fn(), | ||
}; | ||
|
||
describe('AdCancelCreateEditModal', () => { | ||
it('should render the component as expected', () => { | ||
render(<AdCancelCreateEditModal {...mockProps} />); | ||
expect(screen.getByText('Cancel ad creation?')).toBeInTheDocument(); | ||
}); | ||
it('should render the component as expected when isEdit is true', () => { | ||
mockUseQueryString.mockReturnValueOnce({ queryString: { advertId: '123' } }); | ||
render(<AdCancelCreateEditModal {...mockProps} />); | ||
expect(screen.getByText('Cancel your edits?')).toBeInTheDocument(); | ||
}); | ||
it('should redirect to my ads page on clicking cancel button', () => { | ||
render(<AdCancelCreateEditModal {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Cancel' }); | ||
userEvent.click(button); | ||
expect(mockFn).toHaveBeenCalledWith(MY_ADS_URL); | ||
}); | ||
it("should close the modal on clicking don't cancel button", () => { | ||
render(<AdCancelCreateEditModal {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Don’t cancel' }); | ||
userEvent.click(button); | ||
expect(mockProps.onRequestClose).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/p2p-v2/src/components/Modals/AdCancelCreateEditModal/index.ts
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 @@ | ||
export { default as AdCancelCreateEditModal } from './AdCancelCreateEditModal'; |
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
packages/p2p-v2/src/components/PopoverDropdown/__tests__/PopoverDropdown.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,44 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import PopoverDropdown from '../PopoverDropdown'; | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
...jest.requireActual('@deriv-com/ui'), | ||
useDevice: () => ({ | ||
isMobile: false, | ||
}), | ||
})); | ||
|
||
const mockProps = { | ||
dropdownList: [ | ||
{ | ||
label: 'label 1', | ||
value: 'value 1', | ||
}, | ||
{ | ||
label: 'label 2', | ||
value: 'value 2', | ||
}, | ||
], | ||
onClick: jest.fn(), | ||
tooltipMessage: 'test tooltip message', | ||
}; | ||
|
||
describe('PopoverDropdown', () => { | ||
it('should render', () => { | ||
render(<PopoverDropdown {...mockProps} />); | ||
expect(screen.getByTestId('dt_p2p_v2_popover_dropdown_icon')).toBeInTheDocument(); | ||
}); | ||
it('should render the dropdown list on clicking on the icon', () => { | ||
render(<PopoverDropdown {...mockProps} />); | ||
userEvent.click(screen.getByTestId('dt_p2p_v2_popover_dropdown_icon')); | ||
expect(screen.getByText('label 1')).toBeInTheDocument(); | ||
}); | ||
it('should call onClick when item is clicked', () => { | ||
render(<PopoverDropdown {...mockProps} />); | ||
userEvent.click(screen.getByTestId('dt_p2p_v2_popover_dropdown_icon')); | ||
userEvent.click(screen.getByText('label 1')); | ||
expect(mockProps.onClick).toHaveBeenCalledWith('value 1'); | ||
}); | ||
}); |
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
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
Oops, something went wrong.