wavesurfer.spec.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import WaveSurfer from '../src/wavesurfer.js';
  2. /** @test {WaveSurfer} */
  3. describe('WaveSurfer/playback:', function () {
  4. var wavesurfer;
  5. jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
  6. /*
  7. * Handle creating wavesurfer ui requirements
  8. */
  9. function __createWaveform() {
  10. var waveformDiv = document.createElement('div');
  11. waveformDiv.id = 'waveform';
  12. document.getElementsByTagName('body')[0].appendChild(waveformDiv);
  13. return WaveSurfer.create({
  14. container: '#waveform',
  15. waveColor: 'violet',
  16. progressColor: 'purple'
  17. });
  18. }
  19. beforeAll(function (done) {
  20. wavesurfer = __createWaveform();
  21. wavesurfer.load('/base/spec/support/demo.wav');
  22. wavesurfer.on('ready', function () {
  23. done();
  24. });
  25. });
  26. beforeEach(function () {
  27. wavesurfer.seekTo(0);
  28. });
  29. afterAll(function () {
  30. wavesurfer.destroy();
  31. });
  32. /**
  33. * @test {WaveSurfer#play}
  34. * @test {WaveSurfer#isPlaying}
  35. */
  36. it('should play', function () {
  37. wavesurfer.play();
  38. expect(wavesurfer.isPlaying()).toBeTrue();
  39. });
  40. /**
  41. * @test {WaveSurfer#play}
  42. * @test {WaveSurfer#isPlaying}
  43. * @test {WaveSurfer#pause}
  44. */
  45. it('should pause', function () {
  46. wavesurfer.play();
  47. expect(wavesurfer.isPlaying()).toBeTrue();
  48. wavesurfer.pause();
  49. expect(wavesurfer.isPlaying()).toBeFalse();
  50. });
  51. /**
  52. * @test {WaveSurfer#playPause}
  53. * @test {WaveSurfer#isPlaying}
  54. */
  55. it('should play or pause', function () {
  56. wavesurfer.playPause();
  57. expect(wavesurfer.isPlaying()).toBeTrue();
  58. wavesurfer.playPause();
  59. expect(wavesurfer.isPlaying()).toBeFalse();
  60. });
  61. /** @test {WaveSurfer#getDuration} */
  62. it('should get duration', function () {
  63. var duration = parseInt(wavesurfer.getDuration(), 10);
  64. expect(duration).toBeNumber();
  65. });
  66. /** @test {WaveSurfer#toggleMute} */
  67. it('should toggle mute', function () {
  68. wavesurfer.toggleMute();
  69. expect(wavesurfer.isMuted).toBeTrue();
  70. wavesurfer.toggleMute();
  71. expect(wavesurfer.isMuted).toBeFalse();
  72. });
  73. /** @test {WaveSurfer#setMute} */
  74. it('should set mute', function () {
  75. wavesurfer.setMute(true);
  76. expect(wavesurfer.isMuted).toBeTrue();
  77. wavesurfer.setMute(false);
  78. expect(wavesurfer.isMuted).toBeFalse();
  79. });
  80. /** @test {WaveSurfer#zoom} */
  81. it('should set zoom parameters', function () {
  82. wavesurfer.zoom(20);
  83. expect(wavesurfer.params.minPxPerSec).toEqual(20);
  84. expect(wavesurfer.params.scrollParent).toBe(true);
  85. });
  86. /** @test {WaveSurfer#zoom} */
  87. it('should set unzoom parameters', function () {
  88. wavesurfer.zoom(false);
  89. expect(wavesurfer.params.minPxPerSec).toEqual(wavesurfer.defaultParams.minPxPerSec);
  90. expect(wavesurfer.params.scrollParent).toBe(false);
  91. });
  92. });