WIP: Fixed audio context issues - ReferenceError in useWaveform, enhanced cleanup, improved playback switching
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user