import WaveSurfer from '../src/wavesurfer.js'; /** @test {WaveSurfer} */ describe('WaveSurfer/playback:', function () { var wavesurfer; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; /* * Handle creating wavesurfer ui requirements */ function __createWaveform() { var waveformDiv = document.createElement('div'); waveformDiv.id = 'waveform'; document.getElementsByTagName('body')[0].appendChild(waveformDiv); return WaveSurfer.create({ container: '#waveform', waveColor: 'violet', progressColor: 'purple' }); } beforeAll(function (done) { wavesurfer = __createWaveform(); wavesurfer.load('/base/spec/support/demo.wav'); wavesurfer.on('ready', function () { done(); }); }); beforeEach(function () { wavesurfer.seekTo(0); }); afterAll(function () { wavesurfer.destroy(); }); /** * @test {WaveSurfer#play} * @test {WaveSurfer#isPlaying} */ it('should play', function () { wavesurfer.play(); expect(wavesurfer.isPlaying()).toBeTrue(); }); /** * @test {WaveSurfer#play} * @test {WaveSurfer#isPlaying} * @test {WaveSurfer#pause} */ it('should pause', function () { wavesurfer.play(); expect(wavesurfer.isPlaying()).toBeTrue(); wavesurfer.pause(); expect(wavesurfer.isPlaying()).toBeFalse(); }); /** * @test {WaveSurfer#playPause} * @test {WaveSurfer#isPlaying} */ it('should play or pause', function () { wavesurfer.playPause(); expect(wavesurfer.isPlaying()).toBeTrue(); wavesurfer.playPause(); expect(wavesurfer.isPlaying()).toBeFalse(); }); /** @test {WaveSurfer#getDuration} */ it('should get duration', function () { var duration = parseInt(wavesurfer.getDuration(), 10); expect(duration).toBeNumber(); }); /** @test {WaveSurfer#toggleMute} */ it('should toggle mute', function () { wavesurfer.toggleMute(); expect(wavesurfer.isMuted).toBeTrue(); wavesurfer.toggleMute(); expect(wavesurfer.isMuted).toBeFalse(); }); /** @test {WaveSurfer#setMute} */ it('should set mute', function () { wavesurfer.setMute(true); expect(wavesurfer.isMuted).toBeTrue(); wavesurfer.setMute(false); expect(wavesurfer.isMuted).toBeFalse(); }); /** @test {WaveSurfer#zoom} */ it('should set zoom parameters', function () { wavesurfer.zoom(20); expect(wavesurfer.params.minPxPerSec).toEqual(20); expect(wavesurfer.params.scrollParent).toBe(true); }); /** @test {WaveSurfer#zoom} */ it('should set unzoom parameters', function () { wavesurfer.zoom(false); expect(wavesurfer.params.minPxPerSec).toEqual(wavesurfer.defaultParams.minPxPerSec); expect(wavesurfer.params.scrollParent).toBe(false); }); });