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.
DTRA-1815 / Kate / [DTrader-V2]: Add Onboarding video for Draggable c…
…omponent (Trade types selection) (binary-com#16759) * refactor: prepare folder structure * refactor: change structure of flags on clocalstorage * chore: remove code smells * refactor: create reusable stream iframe component * refactor: add tests * chore: remove coed smalls * refactor: add id for teh video * refactor: apply suggestions * chore: remove extra waitfor in tests * chore: fix test case
- Loading branch information
1 parent
b0aafe6
commit f4f9bf9
Showing
27 changed files
with
315 additions
and
71 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
14 changes: 3 additions & 11 deletions
14
packages/trader/src/AppV2/Components/AccumulatorStats/accumulator-stats-description.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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions
64
...s/OnboardingGuide/TradeTypesSelectionGuide/__tests__/trade-types-selection-guide.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,64 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import TradeTypesSelectionGuide from '../trade-types-selection-guide'; | ||
|
||
const modal_text = 'Pin, rearrange, or remove your favorite trade types for easy access.'; | ||
const localStorage_key = 'guide_dtrader_v2'; | ||
const video = 'Video'; | ||
|
||
jest.mock('../../../StreamIframe', () => jest.fn(() => <div>{video}</div>)); | ||
|
||
describe('TradeTypesSelectionGuide', () => { | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it('should render Modal with correct content after 800ms after mounting', async () => { | ||
jest.useFakeTimers(); | ||
render(<TradeTypesSelectionGuide />); | ||
|
||
await waitFor(() => jest.advanceTimersByTime(800)); | ||
|
||
expect(screen.getByText(video)).toBeInTheDocument(); | ||
expect(screen.getByText(modal_text)).toBeInTheDocument(); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should not render Modal if there is a flag in the localStorage equal to true', async () => { | ||
const field = { trade_types_selection: true }; | ||
localStorage.setItem(localStorage_key, JSON.stringify(field)); | ||
|
||
jest.useFakeTimers(); | ||
render(<TradeTypesSelectionGuide />); | ||
|
||
await waitFor(() => jest.advanceTimersByTime(800)); | ||
|
||
expect(screen.queryByText(video)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(modal_text)).not.toBeInTheDocument(); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should close the Modal and set flag to localStorage equal to true after user clicks on "Got it" button', async () => { | ||
const field = 'trade_types_selection'; | ||
jest.useFakeTimers(); | ||
render(<TradeTypesSelectionGuide />); | ||
|
||
await waitFor(() => jest.advanceTimersByTime(800)); | ||
|
||
expect(screen.getByText(video)).toBeInTheDocument(); | ||
expect(screen.getByText(modal_text)).toBeInTheDocument(); | ||
expect(JSON.parse(localStorage.getItem(localStorage_key) as string)[field]).toBe(false); | ||
|
||
userEvent.click(screen.getByRole('button')); | ||
await waitFor(() => jest.advanceTimersByTime(300)); | ||
|
||
expect(screen.queryByText(video)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(modal_text)).not.toBeInTheDocument(); | ||
expect(JSON.parse(localStorage.getItem(localStorage_key) as string)[field]).toBe(true); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/trader/src/AppV2/Components/OnboardingGuide/TradeTypesSelectionGuide/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,3 @@ | ||
import TradeTypesSelectionGuide from './trade-types-selection-guide'; | ||
|
||
export default TradeTypesSelectionGuide; |
53 changes: 53 additions & 0 deletions
53
...AppV2/Components/OnboardingGuide/TradeTypesSelectionGuide/trade-types-selection-guide.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 { Modal } from '@deriv-com/quill-ui'; | ||
import { useLocalStorageData } from '@deriv/hooks'; | ||
import { Localize } from '@deriv/translations'; | ||
import { UNIFIED_MODE_VIDEO_ID } from 'Modules/Trading/Helpers/video-config'; | ||
import StreamIframe from '../../StreamIframe'; | ||
|
||
const TradeTypesSelectionGuide = () => { | ||
const [is_modal_open, setIsModalOpen] = React.useState(false); | ||
const guide_timeout_ref = React.useRef<ReturnType<typeof setTimeout>>(); | ||
|
||
const [guide_dtrader_v2, setGuideDtraderV2] = useLocalStorageData<Record<string, boolean>>('guide_dtrader_v2', { | ||
trade_types_selection: false, | ||
trade_page: false, | ||
positions_page: false, | ||
}); | ||
const { trade_types_selection } = guide_dtrader_v2 || {}; | ||
|
||
const onFinishGuide = () => { | ||
setIsModalOpen(false); | ||
setGuideDtraderV2({ ...guide_dtrader_v2, trade_types_selection: true }); | ||
}; | ||
|
||
React.useEffect(() => { | ||
if (!trade_types_selection) guide_timeout_ref.current = setTimeout(() => setIsModalOpen(true), 800); | ||
|
||
return () => clearTimeout(guide_timeout_ref.current); | ||
}, [trade_types_selection]); | ||
|
||
if (trade_types_selection) return null; | ||
|
||
return ( | ||
<Modal | ||
isOpened={is_modal_open} | ||
isNonExpandable | ||
isMobile | ||
showHandleBar={false} | ||
toggleModal={onFinishGuide} | ||
primaryButtonLabel={<Localize i18n_default_text='Got it' />} | ||
primaryButtonCallback={onFinishGuide} | ||
> | ||
<Modal.Header | ||
image={<StreamIframe src={UNIFIED_MODE_VIDEO_ID.trade_type_selection} title='trade_types_selection' />} | ||
title={<Localize i18n_default_text='Manage your trade types' />} | ||
/> | ||
<Modal.Body> | ||
<Localize i18n_default_text='Pin, rearrange, or remove your favorite trade types for easy access.' /> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default React.memo(TradeTypesSelectionGuide); |
56 changes: 56 additions & 0 deletions
56
packages/trader/src/AppV2/Components/StreamIframe/__tests__/stream-iframe.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,56 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { UNIFIED_MODE_VIDEO_ID } from 'Modules/Trading/Helpers/video-config'; | ||
import StreamIframe from '../stream-iframe'; | ||
|
||
const video_stream_testid = 'dt_video_stream'; | ||
|
||
const mocked_props = { | ||
src: UNIFIED_MODE_VIDEO_ID.accumulator_stats, | ||
test_id: video_stream_testid, | ||
title: 'accumulator_stats', | ||
}; | ||
|
||
describe('StreamIframe component', () => { | ||
it('should render iframe with a video with no controls & autoplay & looped & muted & preloaded & letterbox_color === transparent & width and height === 100% by default', () => { | ||
render(<StreamIframe {...mocked_props} />); | ||
const iframe = screen.getByTestId(video_stream_testid); | ||
const iframe_src = iframe.getAttribute('src'); | ||
|
||
expect( | ||
iframe_src?.includes( | ||
'letterboxColor=transparent&muted=true&preload=auto&loop=true&autoplay=true&controls=false' | ||
) | ||
).toBeTruthy(); | ||
expect(iframe).toHaveAttribute('width', '100%'); | ||
expect(iframe).toHaveAttribute('height', '100%'); | ||
}); | ||
|
||
it('should render iframe with a video with controls if a proper prop was passed', () => { | ||
render(<StreamIframe {...mocked_props} controls />); | ||
const iframe_src = screen.getByTestId(video_stream_testid).getAttribute('src'); | ||
|
||
expect(iframe_src?.includes('controls=true')).toBeTruthy(); | ||
}); | ||
|
||
it('should render iframe with a non-looped video if a proper prop was passed', () => { | ||
render(<StreamIframe {...mocked_props} loop={false} />); | ||
const iframe_src = screen.getByTestId(video_stream_testid).getAttribute('src'); | ||
|
||
expect(iframe_src?.includes('loop=false')).toBeTruthy(); | ||
}); | ||
|
||
it('should render iframe with a non-autoplaying video if a proper prop was passed', () => { | ||
render(<StreamIframe {...mocked_props} autoplay={false} />); | ||
const iframe_src = screen.getByTestId(video_stream_testid).getAttribute('src'); | ||
|
||
expect(iframe_src?.includes('autoplay=false')).toBeTruthy(); | ||
}); | ||
|
||
it('should render iframe with a non-muted video if a proper prop was passed', () => { | ||
render(<StreamIframe {...mocked_props} muted={false} />); | ||
const iframe_src = screen.getByTestId(video_stream_testid).getAttribute('src'); | ||
|
||
expect(iframe_src?.includes('muted=false')).toBeTruthy(); | ||
}); | ||
}); |
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 './stream-iframe.scss'; | ||
import StreamIframe from './stream-iframe'; | ||
|
||
export default StreamIframe; |
15 changes: 15 additions & 0 deletions
15
packages/trader/src/AppV2/Components/StreamIframe/stream-iframe.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,15 @@ | ||
.stream { | ||
&__iframe { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
&__wrapper { | ||
position: relative; | ||
width: 100%; | ||
padding-top: 56.25%; // 16:9 aspect ratio (9/16 = 0.5625 or 56.25%) | ||
overflow: hidden; | ||
} | ||
} |
Oops, something went wrong.