forked from binary-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.
Merge pull request #10 from ameerul-deriv/P2PS-1303-create-modal-comp…
…onent Ameerul /P2PS 1303 Create modal component + P2PS 1304 implement functionality
- Loading branch information
Showing
33 changed files
with
918 additions
and
8 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/components/src/components/icon/common/ic-share-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/components/src/components/icon/common/ic-whatsapp-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
115 changes: 115 additions & 0 deletions
115
.../components/modal-manager/modals/share-my-ads-modal/__tests__/share-my-ads-modal.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,115 @@ | ||
import React from 'react'; | ||
import { toPng } from 'html-to-image'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { base64_images } from 'Constants/base64-images'; | ||
import ShareMyAdsModal from '../share-my-ads-modal'; | ||
|
||
const el_modal = document.createElement('div'); | ||
|
||
const mock_advert = { | ||
account_currency: 'USD', | ||
id: '128812781', | ||
max_order_amount_limit_display: '2.00', | ||
min_order_amount_limit_display: '1.00', | ||
rate_display: '+0.16', | ||
type: 'buy', | ||
}; | ||
|
||
const mock_modal_manager = { | ||
hideModal: jest.fn(), | ||
is_modal_open: true, | ||
}; | ||
|
||
jest.mock('html-to-image', () => ({ | ||
toPng: jest.fn(), | ||
})); | ||
|
||
jest.mock('react-qrcode-logo', () => ({ QRCode: () => <div>QR code</div> })); | ||
|
||
jest.mock('@deriv/components', () => ({ | ||
...jest.requireActual('@deriv/components'), | ||
DesktopWrapper: jest.fn(({ children }) => children), | ||
MobileWrapper: jest.fn(({ children }) => children), | ||
})); | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context', () => ({ | ||
...jest.requireActual('Components/modal-manager/modal-manager-context'), | ||
useModalManagerContext: jest.fn(() => mock_modal_manager), | ||
})); | ||
|
||
describe('<ShareMyAdsModal />', () => { | ||
beforeAll(() => { | ||
el_modal.setAttribute('id', 'modal_root'); | ||
document.body.appendChild(el_modal); | ||
}); | ||
|
||
afterAll(() => { | ||
document.body.removeChild(el_modal); | ||
}); | ||
|
||
it('should render the ShareMyAdsModal', () => { | ||
render(<ShareMyAdsModal advert={mock_advert} />); | ||
|
||
expect(screen.getByText('Share this ad')).toBeInTheDocument(); | ||
expect(screen.getByText('Promote your ad by sharing the QR code and link.')).toBeInTheDocument(); | ||
expect(screen.getByText('QR code')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should toggle the modal', () => { | ||
render(<ShareMyAdsModal advert={mock_advert} />); | ||
|
||
const close_icon = screen.getByTestId('dt-close-modal-icon'); | ||
userEvent.click(close_icon); | ||
|
||
expect(mock_modal_manager.hideModal).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call setShowPopup when clicking on Share link', () => { | ||
render(<ShareMyAdsModal advert={mock_advert} />); | ||
|
||
const share_link_button = screen.getByRole('button', { name: 'Share link' }); | ||
|
||
userEvent.click(share_link_button); | ||
|
||
expect(screen.getByTestId('dt_share_my-ads_popup')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onCopy function when clicking on copy icon', async () => { | ||
const writeText = jest.fn(); | ||
|
||
Object.assign(navigator, { | ||
clipboard: { | ||
writeText, | ||
}, | ||
}); | ||
|
||
jest.useFakeTimers(); | ||
|
||
render(<ShareMyAdsModal advert={mock_advert} />); | ||
|
||
const copy_button = screen.getByRole('button', { name: 'Copy link' }); | ||
|
||
userEvent.click(copy_button); | ||
|
||
await act(async () => { | ||
jest.runAllTimers(); | ||
await Promise.resolve(); | ||
}); | ||
|
||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(window.location.href); | ||
}); | ||
|
||
it('should call handleGenerateImage function when clicking on Download this QR code button', async () => { | ||
const dataUrl = base64_images.dp2p_logo; | ||
|
||
(toPng as jest.MockedFunction<typeof toPng>).mockResolvedValueOnce(dataUrl); | ||
|
||
render(<ShareMyAdsModal advert={mock_advert} />); | ||
|
||
const download_button = screen.getByRole('button', { name: 'Download this QR code' }); | ||
userEvent.click(download_button); | ||
|
||
expect(toPng).toHaveBeenCalled(); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/p2p/src/components/modal-manager/modals/share-my-ads-modal/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,4 @@ | ||
import ShareMyAdsModal from './share-my-ads-modal'; | ||
import './share-my-ads-modal.scss'; | ||
|
||
export default ShareMyAdsModal; |
4 changes: 4 additions & 0 deletions
4
...ges/p2p/src/components/modal-manager/modals/share-my-ads-modal/share-my-ads-card/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,4 @@ | ||
import ShareMyAdsCard from './share-my-ads-card'; | ||
import './share-my-ads-card.scss'; | ||
|
||
export default ShareMyAdsCard; |
76 changes: 76 additions & 0 deletions
76
...mponents/modal-manager/modals/share-my-ads-modal/share-my-ads-card/share-my-ads-card.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,76 @@ | ||
.share-my-ads-card { | ||
background: linear-gradient(349deg, var(--general-section-1) 36%, var(--brand-red-coral) 25%); | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
margin-bottom: 1.5rem; | ||
padding: 2rem; | ||
position: relative; | ||
|
||
@include mobile { | ||
width: 90%; | ||
} | ||
|
||
&__icon { | ||
height: 16px; | ||
width: max-content; | ||
margin: 1rem 0 3rem; | ||
|
||
@include mobile { | ||
margin-top: 0; | ||
} | ||
} | ||
|
||
&__numbers { | ||
display: flex; | ||
flex-direction: row; | ||
|
||
&-text { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 1rem; | ||
|
||
&:first-child { | ||
margin-right: 1rem; | ||
} | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
&__qr { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
margin-top: 2rem; | ||
|
||
@include mobile { | ||
margin-top: 1rem; | ||
} | ||
|
||
&-container { | ||
background-color: #fff; | ||
display: flex; | ||
padding: 0.4rem; | ||
border: 0.1rem solid var(--general-active); | ||
border-radius: 1rem; | ||
position: relative; | ||
width: fit-content; | ||
} | ||
|
||
&-text { | ||
margin: 1.5rem 0 2rem; | ||
|
||
@include mobile { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
&__title { | ||
margin-bottom: 2rem; | ||
} | ||
} |
Oops, something went wrong.