Skip to content

Commit

Permalink
add audio-only test
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Apr 30, 2018
1 parent 8c17837 commit 58a878c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
31 changes: 30 additions & 1 deletion test/test-helpers.js
Expand Up @@ -53,7 +53,7 @@ const TestHelpers = {
wavesurfer: {
src: "live",
waveColor: "#36393b",
progressColor: "#black",
progressColor: "black",
debug: true,
cursorWidth: 1,
msDisplayMax: 20,
Expand All @@ -71,6 +71,35 @@ const TestHelpers = {
return videojs(elementTag.id, playerOptions);
},

makeAudioOnlyPlayer() {
var tag = TestHelpers.makeTag('audio', 'audioOnly');
return this.makePlayer(tag, {
controls: true,
autoplay: false,
fluid: false,
loop: false,
width: 500,
height: 400,
plugins: {
wavesurfer: {
src: "live",
waveColor: "#36393b",
progressColor: "black",
debug: true,
cursorWidth: 1,
msDisplayMax: 20,
hideScrollbar: true
},
record: {
audio: true,
video: false,
maxLength: 5,
debug: true
}
}
});
},

makeVideoOnlyPlayer() {
var tag = TestHelpers.makeTag('video', 'videoOnly');
return this.makePlayer(tag, {
Expand Down
39 changes: 37 additions & 2 deletions test/videojs.record.spec.js
Expand Up @@ -73,15 +73,15 @@ describe('Record', function() {
});

/** @test {Record} */
it('should run as a image-only plugin', function(done) {
it('should run as an image-only plugin', function(done) {
// create image-only plugin
player = TestHelpers.makeImageOnlyPlayer();
// workaround weird test TypeError: Cannot read property 'videoWidth' of null tech error
player.recordCanvas.el().firstChild.videoWidth = 320;
player.recordCanvas.el().firstChild.videoHeight = 240;

player.one('finishRecord', function() {
// received an base-64 encoded PNG string
// received a base-64 encoded PNG string
expect(player.recordedData.startsWith('data:image/png;base64,i')).toBeTrue();
});

Expand All @@ -105,4 +105,39 @@ describe('Record', function() {
player.record().getDevice();
});
});

/** @test {Record} */
it('should run as an audio-only plugin', function(done) {
// create audio-only plugin
player = TestHelpers.makeAudioOnlyPlayer();

player.one('finishRecord', function() {
// received a blob file
expect(player.recordedData instanceof Blob).toBeTruthy();

// wait till it's loaded before destroying
// (XXX: create new event for this)
setTimeout(done, 1000);
});

player.one('startRecord', function() {
// record some audio
setTimeout(function() {
player.record().stop();
}, 2000);
});

player.one('deviceReady', function() {
// create snapshot
player.record().start();
});

player.one('ready', function() {
// correct device button icon
expect(player.deviceButton.buildCSSClass().endsWith('audio-perm')).toBeTrue();

// start device
player.record().getDevice();
});
});
});

0 comments on commit 58a878c

Please sign in to comment.