diff --git a/apps/web/src/app/core/services/audio.service.spec.ts b/apps/web/src/app/core/services/audio.service.spec.ts index d4ad7fd..9fef80a 100644 --- a/apps/web/src/app/core/services/audio.service.spec.ts +++ b/apps/web/src/app/core/services/audio.service.spec.ts @@ -11,6 +11,7 @@ import { API_URL } from '@core/tokens' const mediaPlayerMock: PartiallyMocked = { initialize: vi.fn(), + isPaused: vi.fn(), on: vi.fn(), off: vi.fn(), attachSource: vi.fn(), @@ -58,7 +59,21 @@ describe('AudioService', () => { vi.clearAllMocks() }) - it('should play audio', () => { + it('should not play audio when player is not paused', () => { + // Arrange + mediaPlayerMock.isPaused?.mockImplementation(() => false) + + // Act + audioService.play() + + // Assert + expect(mediaPlayerMock.play).not.toHaveBeenCalled() + }) + + it('should play audio when player is paused', () => { + // Arrange + mediaPlayerMock.isPaused?.mockImplementation(() => true) + // Act audioService.play() @@ -66,7 +81,10 @@ describe('AudioService', () => { expect(mediaPlayerMock.play).toHaveBeenCalled() }) - it('should pause audio', () => { + it('should pause audio when player is not paused', () => { + // Arrange + mediaPlayerMock.isPaused?.mockImplementation(() => false) + // Act audioService.pause() @@ -74,6 +92,17 @@ describe('AudioService', () => { expect(mediaPlayerMock.pause).toHaveBeenCalled() }) + it('should not pause audio when player is paused', () => { + // Arrange + mediaPlayerMock.isPaused?.mockImplementation(() => true) + + // Act + audioService.pause() + + // Assert + expect(mediaPlayerMock.pause).not.toHaveBeenCalled() + }) + it('should seek to specified time', () => { // Arrange const currentTime = 30 @@ -156,14 +185,14 @@ describe('AudioService', () => { ) }) - it('should dispatch audio play action on loaded manifest', () => { + it('should dispatch audio play action on player ready', () => { // Arrange const playSpy = vi.fn() const injectorSpy = vi.spyOn(injector, 'get').mockReturnValue({ play: playSpy }) // Act // eslint-disable-next-line @typescript-eslint/no-explicit-any - ;(audioService as any).onManifestLoaded() + ;(audioService as any).onCanPlay() // Assert expect(injectorSpy).toHaveBeenCalledWith(AudioState) @@ -260,7 +289,7 @@ describe('AudioService', () => { ;(audioService as any).registerEvents() // Assert - expect(mediaPlayerMock.on).toHaveBeenCalledWith(AudioEvents.MANIFEST_LOADED, expect.any(Function)) + expect(mediaPlayerMock.on).toHaveBeenCalledWith(AudioEvents.CAN_PLAY, expect.any(Function)) expect(mediaPlayerMock.on).toHaveBeenCalledWith(AudioEvents.PLAYBACK_TIME_UPDATED, expect.any(Function)) expect(mediaPlayerMock.on).toHaveBeenCalledWith(AudioEvents.PLAYBACK_ENDED, expect.any(Function)) }) @@ -271,7 +300,7 @@ describe('AudioService', () => { ;(audioService as any).removeEvents() // Assert - expect(mediaPlayerMock.off).toHaveBeenCalledWith(AudioEvents.MANIFEST_LOADED, expect.any(Function)) + expect(mediaPlayerMock.off).toHaveBeenCalledWith(AudioEvents.CAN_PLAY, expect.any(Function)) expect(mediaPlayerMock.off).toHaveBeenCalledWith(AudioEvents.PLAYBACK_TIME_UPDATED, expect.any(Function)) expect(mediaPlayerMock.off).toHaveBeenCalledWith(AudioEvents.PLAYBACK_ENDED, expect.any(Function)) }) diff --git a/apps/web/src/app/core/state/playback.state.spec.ts b/apps/web/src/app/core/state/playback.state.spec.ts index fcfb41d..0c0de45 100644 --- a/apps/web/src/app/core/state/playback.state.spec.ts +++ b/apps/web/src/app/core/state/playback.state.spec.ts @@ -63,7 +63,10 @@ describe('PlaybackState', () => { it('should set current track, queue, load audio, and open visualizer when toggling play with new track', () => { // Arrange const trackId = 'track2' - const queue = { source: { name: 'source2' }, tracks: [{ id: 'track1' }, { id: trackId }] } as Queue + const queue = { + source: { name: 'source2', entityId: 'newQueue' }, + tracks: [{ id: 'track1' }, { id: trackId }], + } as Queue // Act playbackState.togglePlay({ queue, trackId }) diff --git a/apps/web/src/app/shared/pipes/image-url.pipe.spec.ts b/apps/web/src/app/shared/pipes/image-url.pipe.spec.ts index 87de003..cdc1e6c 100644 --- a/apps/web/src/app/shared/pipes/image-url.pipe.spec.ts +++ b/apps/web/src/app/shared/pipes/image-url.pipe.spec.ts @@ -10,10 +10,10 @@ describe('ImageUrlPipe', () => { pipe = new ImageUrlPipe() }) - it('should return undefined for empty or undefined input', () => { + it('should return empty string for empty or undefined input', () => { // Act & Assert - expect(pipe.transform(undefined)).toBeUndefined() - expect(pipe.transform([])).toBeUndefined() + expect(pipe.transform(undefined)).toBe('') + expect(pipe.transform([])).toBe('') }) it('should return the correct URL for the default size (SMALL)', () => {