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.
[DTRA] / Kate / DTRA-253 / Create a custom video player (deriv-com#12443
) * feat: create play stop controller * refactor: improve volume controller * fix: ui and volume bugs * refactor: functions helpers * refactor: remove extra animation * refactor: apply first part of suggestions * refactor: upgrade dropdown component * refactor: remove inline style * refactor: add more ref * refactor: add flag for animation instead of inline style * refactor: add extra ref and remove inline style for volume control * fix: revert browser check * feat: add scroll functionality * refactor: recalculate scroll heigh * chore: fix typo * chore: apply suggestions * refactor: make srcrollbar visible for player * refactor: add tests for overlay, volume and playback rate files * refactor: add tests for video control file and apply suggestion * refactor: style nesting * refactor: remove sonarcloud smell * refactor: get rid of extra ref usage * refactor: add tests for browser detect function * refactor: add tests for formatduration function * refactor: typos * Maryia/test: VideoPlayer + optimization (#48) * test: VideoPlayer * refactor: type TMockedStreamProps * test: VideoPlayer * chore: optimization & improvements * test: add test for video player (replay feature) * refactor: rename refs * chore: voluma and animation fixes * chore: volume control functions refactor * refactor: change rounding * fix: autoplaying after switching tabs * refactor: improve animation * fix: gap berween drag dot and progress bar * refactor: reworked animationframe * refactor: remove use effect * refactor: improve perfomance * fix: Safari issues for long living tabs * refactor: ad debounce and cleaning * refactor: ad debounce and cleaning * refactor: fix tests * fix: mobile control pannel * fix: first launch time issue * refactor: change type of th check for rewind * refactor: apply suggestions --------- Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com>
- Loading branch information
1 parent
db4e225
commit f8aedb6
Showing
32 changed files
with
1,503 additions
and
203 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
1 change: 1 addition & 0 deletions
1
packages/components/src/components/icon/common/ic-playback-rate.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.
1 change: 1 addition & 0 deletions
1
packages/components/src/components/icon/common/ic-sound-off.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.
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
43 changes: 43 additions & 0 deletions
43
packages/shared/src/utils/browser/__tests__/browser_detect.spec.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,43 @@ | ||
import { isSafariBrowser } from '../browser_detect'; | ||
|
||
describe('isSafariBrowser', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return false for Chrome browser', () => { | ||
Object.defineProperty(window.navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | ||
configurable: true, | ||
}); | ||
|
||
expect(isSafariBrowser()).toBe(false); | ||
}); | ||
|
||
it('should detect Safari browser', () => { | ||
Object.defineProperty(window.navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15', | ||
configurable: true, | ||
}); | ||
|
||
expect(isSafariBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for FireFox browser', () => { | ||
Object.defineProperty(window.navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0', | ||
configurable: true, | ||
}); | ||
|
||
expect(isSafariBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return false for Opera browser', () => { | ||
Object.defineProperty(window.navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Opera/121.0', | ||
configurable: true, | ||
}); | ||
|
||
expect(isSafariBrowser()).toBe(false); | ||
}); | ||
}); |
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
47 changes: 47 additions & 0 deletions
47
...s/trader/src/App/Components/Elements/VideoPlayer/__tests__/playback-rate-control.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,47 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import PlaybackRateControl from '../playback-rate-control'; | ||
|
||
const mocked_props = { | ||
onPlaybackRateChange: jest.fn(), | ||
playback_rate: 1, | ||
}; | ||
|
||
const default_selected_item = 'Normal'; | ||
const playback_rate_list = ['0.25x', '0.5x', '0.75x', default_selected_item, '1.5x', '2.0x']; | ||
|
||
describe('<PlaybackRateControl />', () => { | ||
it('should render the component', () => { | ||
const { container } = render(<PlaybackRateControl {...mocked_props} />); | ||
|
||
expect(container).not.toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render all available options of playback rate if user clicked on default one', () => { | ||
render(<PlaybackRateControl {...mocked_props} />); | ||
|
||
playback_rate_list.forEach(item => | ||
item === default_selected_item | ||
? expect(screen.getByText(item)).toBeInTheDocument() | ||
: expect(screen.queryByText(item)).not.toBeInTheDocument() | ||
); | ||
userEvent.click(screen.getByText(default_selected_item)); | ||
|
||
playback_rate_list.forEach(item => | ||
item === default_selected_item | ||
? expect(screen.getAllByText(item)).toHaveLength(2) | ||
: expect(screen.getByText(item)).toBeInTheDocument() | ||
); | ||
}); | ||
|
||
it('should call onPlaybackRateChange if user chooses another option', () => { | ||
render(<PlaybackRateControl {...mocked_props} />); | ||
|
||
expect(mocked_props.onPlaybackRateChange).not.toBeCalled(); | ||
userEvent.click(screen.getByText(default_selected_item)); | ||
userEvent.click(screen.getByText(playback_rate_list[0])); | ||
|
||
expect(mocked_props.onPlaybackRateChange).toBeCalled(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/trader/src/App/Components/Elements/VideoPlayer/__tests__/video-controls.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,63 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import VideoControls from '../video-controls'; | ||
|
||
const mocked_props: React.ComponentProps<typeof VideoControls> = { | ||
current_time: 3, | ||
dragStartHandler: jest.fn(), | ||
is_animated: true, | ||
is_ended: false, | ||
is_playing: true, | ||
is_muted: false, | ||
onRewind: jest.fn(), | ||
onVolumeChange: jest.fn(), | ||
onPlaybackRateChange: jest.fn(), | ||
progress_bar_filled_ref: { current: null }, | ||
progress_bar_ref: { current: null }, | ||
progress_dot_ref: { current: null }, | ||
show_controls: true, | ||
togglePlay: jest.fn(), | ||
toggleMute: jest.fn(), | ||
video_duration: 33, | ||
volume: 0.5, | ||
playback_rate: 1, | ||
}; | ||
|
||
const volume_control = 'VolumeControl component'; | ||
const playback_rate_control = 'PlaybackRateControl component'; | ||
const progress_bar = 'dt_progress_bar'; | ||
const progress_bar_filled = 'dt_progress_bar_filled'; | ||
const progress_bar_dot = 'dt_progress_bar_dot'; | ||
|
||
jest.mock('../volume-control', () => jest.fn(() => <div>{volume_control}</div>)); | ||
jest.mock('../playback-rate-control', () => jest.fn(() => <div>{playback_rate_control}</div>)); | ||
|
||
describe('<VideoControls />', () => { | ||
it('should render the component', () => { | ||
render(<VideoControls {...mocked_props} />); | ||
|
||
expect(screen.getByTestId(progress_bar)).toBeInTheDocument(); | ||
expect(screen.getByTestId(progress_bar_filled)).toBeInTheDocument(); | ||
expect(screen.getByText(/00:03 \/ 00:33/i)).toBeInTheDocument(); | ||
expect(screen.getByText(volume_control)).toBeInTheDocument(); | ||
expect(screen.getByText(playback_rate_control)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render drag dot on progress bar mouseover event and hide it on mouseleave event', () => { | ||
render(<VideoControls {...mocked_props} />); | ||
const progress = screen.getByTestId(progress_bar); | ||
|
||
expect(screen.queryByTestId(progress_bar_dot)).not.toBeInTheDocument(); | ||
fireEvent.mouseOver(progress); | ||
expect(screen.getByTestId(progress_bar_dot)).toBeInTheDocument(); | ||
|
||
fireEvent.mouseLeave(progress); | ||
expect(screen.queryByTestId(progress_bar_dot)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should always render drag dot on mobile', () => { | ||
render(<VideoControls {...mocked_props} is_mobile />); | ||
|
||
expect(screen.getByTestId(progress_bar_dot)).toBeInTheDocument(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/trader/src/App/Components/Elements/VideoPlayer/__tests__/video-overlay.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,29 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import VideoOverlay from '../video-overlay'; | ||
|
||
const mocked_props = { | ||
onClick: jest.fn(), | ||
}; | ||
|
||
const icon_testid = 'dt_player_overlay_icon'; | ||
|
||
describe('<VideoOverlay />', () => { | ||
it('should render the component', () => { | ||
const { container } = render(<VideoOverlay {...mocked_props} />); | ||
|
||
expect(container).not.toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should pass correct size to icon for desktop', () => { | ||
render(<VideoOverlay {...mocked_props} />); | ||
|
||
expect(screen.getByTestId(icon_testid)).toHaveAttribute('height', '128'); | ||
}); | ||
|
||
it('should pass correct size to icon for mobile', () => { | ||
render(<VideoOverlay {...mocked_props} is_mobile />); | ||
|
||
expect(screen.getByTestId(icon_testid)).toHaveAttribute('height', '88'); | ||
}); | ||
}); |
Oops, something went wrong.