WIP: Fixed audio context issues - ReferenceError in useWaveform, enhanced cleanup, improved playback switching

This commit is contained in:
Mistral Vibe
2026-04-08 17:00:28 +02:00
parent 5f95d88741
commit 9c032d0774
3 changed files with 79 additions and 14 deletions

View File

@@ -223,4 +223,37 @@ describe('initializeAudioContext', () => {
});
});
describe('cleanup', () => {
it('should stop playback and clean up properly', () => {
// Mock a playing wavesurfer instance
const mockWavesurfer = {
isPlaying: vi.fn(() => true),
pause: vi.fn(),
unAll: vi.fn(),
destroy: vi.fn()
};
audioService['wavesurfer'] = mockWavesurfer;
audioService['currentPlayingSongId'] = 'song-123';
audioService['currentPlayingBandId'] = 'band-456';
audioService.cleanup();
expect(mockWavesurfer.pause).toHaveBeenCalled();
expect(mockWavesurfer.unAll).toHaveBeenCalled();
expect(mockWavesurfer.destroy).toHaveBeenCalled();
expect(audioService['wavesurfer']).toBeNull();
expect(audioService['currentPlayingSongId']).toBeNull();
expect(audioService['currentPlayingBandId']).toBeNull();
});
it('should handle cleanup when no wavesurfer instance exists', () => {
audioService['wavesurfer'] = null;
audioService['currentPlayingSongId'] = 'song-123';
expect(() => audioService.cleanup()).not.toThrow();
expect(audioService['currentPlayingSongId']).toBeNull();
});
});
});