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.
chore: added test cases, fixed clipboard issue, refactored icons to s…
…ocials
- Loading branch information
1 parent
9aa35e4
commit faec3f1
Showing
13 changed files
with
218 additions
and
44 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
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
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: 0 additions & 4 deletions
4
...es/p2p/src/components/modal-manager/modals/share-my-ads-modal/share-my-ads-icons/index.ts
This file was deleted.
Oops, something went wrong.
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
32 changes: 32 additions & 0 deletions
32
...anager/modals/share-my-ads-modal/share-my-ads-popup/__tests__/share-my-ads-popup.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,32 @@ | ||
import React from 'react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ShareMyAdsPopup from '../share-my-ads-popup'; | ||
|
||
const mock_on_close = jest.fn(); | ||
|
||
describe('<ShareMyAdsPopup />', () => { | ||
it('should call closePopup function when clicking on cross icon', () => { | ||
jest.useFakeTimers(); | ||
|
||
const el_modal = document.createElement('div'); | ||
el_modal.setAttribute('id', 'modal_root'); | ||
document.body.appendChild(el_modal); | ||
|
||
render(<ShareMyAdsPopup onClose={mock_on_close} />); | ||
|
||
const close_icon = screen.getByTestId('dt-close-popup-icon'); | ||
userEvent.click(close_icon); | ||
|
||
jest.runAllTimers(); | ||
|
||
expect(mock_on_close).toHaveBeenCalled(); | ||
document.body.removeChild(el_modal); | ||
}); | ||
|
||
it('should return null if modal_root is not found', () => { | ||
render(<ShareMyAdsPopup onClose={mock_on_close} />); | ||
|
||
expect(screen.queryByText('Share my ads')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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
15 changes: 15 additions & 0 deletions
15
...ager/modals/share-my-ads-modal/share-my-ads-socials/__tests__/share-my-ads-icons.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,15 @@ | ||
import React from 'react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import ShareMyAdsSocials from '../share-my-ads-socials'; | ||
|
||
describe('<ShareMyAdsSocials />', () => { | ||
it('should render all the social media platforms', () => { | ||
render(<ShareMyAdsSocials />); | ||
|
||
expect(screen.getByText('WhatsApp')).toBeInTheDocument(); | ||
expect(screen.getByText('Facebook')).toBeInTheDocument(); | ||
expect(screen.getByText('Telegram')).toBeInTheDocument(); | ||
expect(screen.getByText('Twitter')).toBeInTheDocument(); | ||
expect(screen.getByText('Gmail')).toBeInTheDocument(); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
.../p2p/src/components/modal-manager/modals/share-my-ads-modal/share-my-ads-socials/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 ShareMyAdsSocials from './share-my-ads-socials'; | ||
import './share-my-ads-socials.scss'; | ||
|
||
export default ShareMyAdsSocials; |
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.