-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a640bc0
commit b0cbe5d
Showing
44 changed files
with
2,342 additions
and
2,608 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const useActiveTrack = jest.fn(); | ||
export const useIsPlaying = jest.fn(() => ({})); | ||
export const usePlaybackState = jest.fn(); | ||
export const useProgress = jest.fn(() => ({})); | ||
|
||
export const State = { | ||
Paused: 'paused', | ||
Ready: 'ready', | ||
Ended: 'ended', | ||
}; | ||
|
||
export default { | ||
add: jest.fn(), | ||
remove: jest.fn(), | ||
load: jest.fn(), | ||
skip: jest.fn(), | ||
seekTo: jest.fn(), | ||
seekBy: jest.fn(), | ||
setupPlayer: jest.fn(() => Promise.resolve()), | ||
destroy: jest.fn(), | ||
reset: jest.fn(), | ||
play: jest.fn(), | ||
pause: jest.fn(), | ||
stop: jest.fn(), | ||
getQueue: jest.fn(() => Promise.resolve([])), | ||
setQueue: jest.fn(() => Promise.resolve()), | ||
getActiveTrackIndex: jest.fn(() => Promise.resolve(undefined)), | ||
}; |
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
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,10 @@ | ||
import TrackPlayer from 'react-native-track-player'; | ||
|
||
module.exports = async function () { | ||
TrackPlayer.addEventListener('remote-play', () => TrackPlayer.play()); | ||
TrackPlayer.addEventListener('remote-pause', () => TrackPlayer.pause()); | ||
TrackPlayer.addEventListener('remote-next', () => TrackPlayer.skipToNext()); | ||
TrackPlayer.addEventListener('remote-previous', () => | ||
TrackPlayer.skipToPrevious(), | ||
); | ||
}; |
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,3 @@ | ||
async function AudioService() {} | ||
|
||
export default AudioService; |
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
146 changes: 146 additions & 0 deletions
146
src/modules/audio-player/components/AudioQueueItem.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,146 @@ | ||
import { fireEvent, render, waitFor } from '@testing-library/react-native'; | ||
import sp from '~/services/serviceProvider'; | ||
import TrackPlayer, { Track, useIsPlaying } from 'react-native-track-player'; | ||
import { AudioQueueItem } from './AudioQueueItem'; | ||
import useIsTrackDownloaded from '../hooks/useIsTrackDownloaded'; | ||
|
||
jest.mock('~/services/serviceProvider'); | ||
sp.mockService('styles'); | ||
const audioPlayerMock = sp.mockService('audioPlayer'); | ||
sp.mockService('api'); | ||
sp.mockService('settings'); | ||
|
||
jest.mock('../hooks/useIsTrackDownloaded'); | ||
|
||
const mockTrack: Track = { | ||
id: '123', | ||
url: 'https://fake-track', | ||
}; | ||
|
||
describe('AudioQueueItem', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render component', () => { | ||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={0} | ||
track={mockTrack} | ||
onRemoveTrack={() => {}} | ||
/>, | ||
); | ||
expect(comp).toBeTruthy(); | ||
}); | ||
|
||
it('should remove track from the queue', async () => { | ||
const removedCallbackFn = jest.fn(); | ||
|
||
jest.spyOn(TrackPlayer, 'remove'); | ||
|
||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={0} | ||
track={mockTrack} | ||
onRemoveTrack={removedCallbackFn} | ||
/>, | ||
); | ||
const rmvQueueTrackBtn = comp.getByTestId('remove-track'); | ||
|
||
fireEvent.press(rmvQueueTrackBtn); | ||
|
||
await waitFor(() => { | ||
expect(TrackPlayer.remove).toHaveBeenCalledWith(0); | ||
expect(removedCallbackFn).toHaveBeenCalledWith(mockTrack); | ||
}); | ||
}); | ||
|
||
it('should skip to, and play, track if not already playing', async () => { | ||
jest.spyOn(TrackPlayer, 'skip'); | ||
jest.spyOn(TrackPlayer, 'play'); | ||
|
||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={1} | ||
track={mockTrack} | ||
onRemoveTrack={jest.fn()} | ||
/>, | ||
); | ||
const playBtn = comp.getByTestId('play-track'); | ||
|
||
fireEvent.press(playBtn); | ||
|
||
await waitFor(() => { | ||
expect(TrackPlayer.skip).toHaveBeenCalledWith(1); | ||
expect(TrackPlayer.play).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should pause track if already playing', async () => { | ||
jest.spyOn(TrackPlayer, 'skip'); | ||
jest.spyOn(TrackPlayer, 'play'); | ||
jest.spyOn(TrackPlayer, 'pause'); | ||
|
||
(TrackPlayer.getActiveTrackIndex as jest.Mock).mockResolvedValue(1); | ||
(useIsPlaying as jest.Mock).mockReturnValue({ playing: true }); | ||
|
||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={1} | ||
track={mockTrack} | ||
onRemoveTrack={jest.fn()} | ||
/>, | ||
); | ||
const playBtn = comp.getByTestId('play-track'); | ||
|
||
await waitFor(() => {}); | ||
|
||
fireEvent.press(playBtn); | ||
|
||
await waitFor(() => { | ||
expect(TrackPlayer.pause).toHaveBeenCalled(); | ||
expect(TrackPlayer.skip).not.toHaveBeenCalled(); | ||
expect(TrackPlayer.play).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should download a track', async () => { | ||
jest.spyOn(audioPlayerMock, 'downloadTrack'); | ||
|
||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={1} | ||
track={mockTrack} | ||
onRemoveTrack={jest.fn()} | ||
/>, | ||
); | ||
const downloadBtn = comp.getByTestId('download-track'); | ||
|
||
fireEvent.press(downloadBtn); | ||
|
||
await waitFor(() => { | ||
expect(audioPlayerMock.downloadTrack).toHaveBeenCalledWith(mockTrack); | ||
}); | ||
}); | ||
|
||
it('should delete a downloaded a track', async () => { | ||
jest.spyOn(audioPlayerMock, 'deleteTrack'); | ||
|
||
(useIsTrackDownloaded as jest.Mock).mockReturnValue(true); | ||
|
||
const comp = render( | ||
<AudioQueueItem | ||
trackIndex={1} | ||
track={mockTrack} | ||
onRemoveTrack={jest.fn()} | ||
/>, | ||
); | ||
const downloadBtn = comp.getByTestId('download-track'); | ||
|
||
fireEvent.press(downloadBtn); | ||
|
||
await waitFor(() => { | ||
expect(audioPlayerMock.deleteTrack).toHaveBeenCalledWith(mockTrack); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.