fix: update jest config path and controls tests for Zustand store migration

Update tamagui.config.ts path in jest.config.js after it was moved to
src/configs/. Update controls tests to set up Zustand stores
(usePlayerPlaybackStore, usePlayerQueueStore) instead of mocking
TrackPlayer.getState for position/currentIndex, matching the refactored
controls.ts implementation.
This commit is contained in:
skalthoff
2026-03-12 09:00:11 -07:00
parent e944f217f3
commit efc3e40a59
2 changed files with 25 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ module.exports = {
'./jest/setup/nitro-image.ts',
'./jest/setup/nitro-ota.ts',
'./jest/setup/nitro-player.ts',
'./tamagui.config.ts',
'./src/configs/tamagui.config.ts',
'./jest/setup/native-modules.ts',
],
extensionsToTreatAsEsm: ['.ts', '.tsx'],

View File

@@ -1,16 +1,20 @@
import { TrackPlayer } from 'react-native-nitro-player'
import { previous, skip } from '../../../src/hooks/player/functions/controls'
import { SKIP_TO_PREVIOUS_THRESHOLD } from '../../../src/configs/player.config'
import { usePlayerQueueStore } from '../../../src/stores/player/queue'
import { usePlayerPlaybackStore } from '../../../src/stores/player/playback'
describe('Player Controls', () => {
beforeEach(() => {
jest.clearAllMocks()
usePlayerQueueStore.setState({ currentIndex: 0 })
usePlayerPlaybackStore.setState({ position: 0 })
})
describe('previous()', () => {
it('should skip to previous track when position is below threshold and start playback', async () => {
usePlayerPlaybackStore.setState({ position: SKIP_TO_PREVIOUS_THRESHOLD - 1 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentPosition: SKIP_TO_PREVIOUS_THRESHOLD - 1,
currentState: 'playing',
})
@@ -21,8 +25,8 @@ describe('Player Controls', () => {
})
it('should seek to beginning when position is at or above threshold and start playback', async () => {
usePlayerPlaybackStore.setState({ position: SKIP_TO_PREVIOUS_THRESHOLD + 1 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentPosition: SKIP_TO_PREVIOUS_THRESHOLD + 1,
currentState: 'playing',
})
@@ -34,8 +38,8 @@ describe('Player Controls', () => {
})
it('should not resume playback if player was paused', async () => {
usePlayerPlaybackStore.setState({ position: 1 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentPosition: 1,
currentState: 'paused',
})
@@ -46,8 +50,8 @@ describe('Player Controls', () => {
})
it('should skip to previous at exactly the threshold boundary and start playback', async () => {
usePlayerPlaybackStore.setState({ position: SKIP_TO_PREVIOUS_THRESHOLD })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentPosition: SKIP_TO_PREVIOUS_THRESHOLD,
currentState: 'playing',
})
@@ -58,12 +62,25 @@ describe('Player Controls', () => {
expect(TrackPlayer.skipToPrevious).not.toHaveBeenCalled()
expect(TrackPlayer.play).toHaveBeenCalled()
})
it('should return early when currentIndex is undefined', async () => {
usePlayerQueueStore.setState({ currentIndex: undefined })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentState: 'playing',
})
await previous()
expect(TrackPlayer.skipToPrevious).not.toHaveBeenCalled()
expect(TrackPlayer.seek).not.toHaveBeenCalled()
expect(TrackPlayer.play).not.toHaveBeenCalled()
})
})
describe('skip()', () => {
it('should skip to specific index when provided and start playback', async () => {
usePlayerQueueStore.setState({ currentIndex: 2 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentIndex: 2,
currentState: 'playing',
})
@@ -75,8 +92,8 @@ describe('Player Controls', () => {
})
it('should skip to next track when index is undefined and start playback', async () => {
usePlayerQueueStore.setState({ currentIndex: 2 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentIndex: 2,
currentState: 'paused',
})
@@ -88,8 +105,8 @@ describe('Player Controls', () => {
})
it('should skip to index 0 and start playback', async () => {
usePlayerQueueStore.setState({ currentIndex: 2 })
;(TrackPlayer.getState as jest.Mock).mockResolvedValue({
currentIndex: 2,
currentState: 'paused',
})