From 717397e2010a7c2a9d2bbb543e3390ee9be94e9c Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Tue, 12 Sep 2017 22:12:35 +0100 Subject: [PATCH] Clean up tests Remove assertions from async tests, and move them to separate tests with a setup step Add onPause tests --- test/specs/ReactPlayer.js | 122 ++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/test/specs/ReactPlayer.js b/test/specs/ReactPlayer.js index c91e9b10..d21fa548 100644 --- a/test/specs/ReactPlayer.js +++ b/test/specs/ReactPlayer.js @@ -106,27 +106,37 @@ describe('ReactPlayer', () => { let player render( { player = p }} + ref={p => { player = p || player }} url={test.url} playing - onReady={() => { - expect(player).to.exist - expect(player.getInternalPlayer()).to.exist - bump('onReady') - }} + onReady={() => bump('onReady')} onStart={() => bump('onStart')} onPlay={() => bump('onPlay')} - onDuration={secs => { - expect(secs).to.be.a('number') - expect(secs).to.be.above(0) - expect(player.getDuration()).to.be.a('number') - bump('onDuration') - }} - onProgress={progress => { - expect(progress).to.be.an('object') - if (progress.played) { - expect(player.getCurrentTime()).to.be.a('number') - bump('onProgress') + onDuration={secs => bump('onDuration')} + onProgress={progress => bump('onProgress')} + />, + div) + }) + + it('onPause', done => { + const onPause = () => done() + const pausePlayer = () => { + render( + , + div) + } + render( + { + if (p.playedSeconds >= 3) { + pausePlayer() } }} />, @@ -150,17 +160,15 @@ describe('ReactPlayer', () => { let player render( { player = p }} + ref={p => { player = p || player }} url={test.url} playing - onPlay={() => { - player.seekTo(5) - }} - onSeek={seconds => { - expect(seconds).to.be.a('number') - expect(seconds).to.equal(5) - done() + onProgress={p => { + if (p.playedSeconds >= 3) { + player.seekTo(10) + } }} + onSeek={() => done()} />, div) }) @@ -168,27 +176,53 @@ describe('ReactPlayer', () => { }) } - it('renders with preload config', done => { - const ref = p => { - if (!p) return - expect(p.wrapper).to.be.a('HTMLDivElement') - expect(p.wrapper.childNodes).to.have.length(3) - for (let div of p.wrapper.childNodes) { + describe('instance methods', () => { + let player + beforeEach(done => { + render( + { player = p || player }} + url='http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4' + onReady={() => done()} + />, + div) + }) + + it('returns correctly', () => { + expect(player.getInternalPlayer()).to.exist + expect(player.getCurrentTime()).to.be.a('number') + expect(player.getDuration()).to.be.a('number') + }) + }) + + describe('preloading', () => { + let player + beforeEach(done => { + render( + { + if (p) { + player = p + done() + } + }} + url={null} + config={{ + youtube: { preload: true }, + vimeo: { preload: true }, + dailymotion: { preload: true } + }} + />, + div) + }) + + it('renders with preload config', () => { + expect(player.wrapper).to.be.a('HTMLDivElement') + expect(player.wrapper.childNodes).to.have.length(3) + for (let div of player.wrapper.childNodes) { expect(div.style.display).to.equal('none') } - done() - } - render( - , - div) + }) }) it('canPlay returns false', () => {