-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store "paused" instead of "isPlaying" in media state
BREAKING CHANGE: now media players return "paused" instead of "isPlaying" in their state.
- Loading branch information
Showing
4 changed files
with
51 additions
and
9 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,42 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import useAudio from '../useAudio'; | ||
const setUp = ( | ||
src: string = 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3', | ||
autoPlay: boolean = true | ||
) => renderHook(() => useAudio({ src, autoPlay })); | ||
|
||
it('should init audio and utils', () => { | ||
global.console.error = jest.fn(); | ||
|
||
const MOCK_AUDIO_SRC = 'MOCK_AUDIO_SRC'; | ||
const MOCK_AUTO_PLAY_STATE = true; | ||
const { result } = setUp(MOCK_AUDIO_SRC, MOCK_AUTO_PLAY_STATE); | ||
const [audio, state, controls, ref] = result.current; | ||
// if not production mode, it will show the error message, cause audio do not render | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
|
||
// Test the audio comp | ||
expect(audio.type).toBe('audio'); | ||
expect(audio.props.src).toBe(MOCK_AUDIO_SRC); | ||
expect(audio.props.autoPlay).toBe(MOCK_AUTO_PLAY_STATE); | ||
|
||
// Test state value | ||
expect(state.time).toBe(0); | ||
expect(state.paused).toBe(true); | ||
expect(state.muted).toBe(false); | ||
expect(state.volume).toBe(1); | ||
|
||
// Test controls | ||
ref.current = document.createElement('audio'); | ||
// Mock ref current for controls testing | ||
|
||
expect(ref.current.muted).toBe(false); | ||
controls.mute(); | ||
expect(ref.current.muted).toBe(true); | ||
controls.unmute(); | ||
expect(ref.current.muted).toBe(false); | ||
|
||
expect(ref.current.volume).toBe(1); | ||
controls.volume(0.5); | ||
expect(ref.current.volume).toBe(0.5); | ||
}); |
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