From efc3e40a5933148c26b68ba45e15d10abab9331e Mon Sep 17 00:00:00 2001 From: skalthoff <32023561+skalthoff@users.noreply.github.com> Date: Thu, 12 Mar 2026 09:00:11 -0700 Subject: [PATCH] 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. --- jest.config.js | 2 +- jest/functional/Player/controls.test.ts | 31 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/jest.config.js b/jest.config.js index 532428c8..ae6c6fac 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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'], diff --git a/jest/functional/Player/controls.test.ts b/jest/functional/Player/controls.test.ts index 4bbdb5c0..74a96231 100644 --- a/jest/functional/Player/controls.test.ts +++ b/jest/functional/Player/controls.test.ts @@ -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', })