From 2e88e5e771fe4c6fc08ff681820e62e5b7d45fec Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Tue, 5 Dec 2017 22:26:19 +0000 Subject: [PATCH] Add more tests --- test/specs/ReactPlayer.js | 32 ++++++++++++++++++++++++++++++++ test/specs/utils.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/test/specs/ReactPlayer.js b/test/specs/ReactPlayer.js index 28fe8a42..211a59de 100644 --- a/test/specs/ReactPlayer.js +++ b/test/specs/ReactPlayer.js @@ -249,6 +249,38 @@ describe('ReactPlayer', () => { }) } + describe('playbackRate change', () => { + it('updates correctly', () => { + let player + const updatePlayer = () => { + render( + { + const p = player.getInternalPlayer() + if (p && p.playbackRate === 0.5) { + updatePlayer() + } + }} + />, + div) + } + render( + { player = p }} + url='http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4' + onProgress={() => { + const p = player.getInternalPlayer() + if (p && p.playbackRate === 1) { + updatePlayer() + } + }} + />, + div) + }) + }) + describe('instance methods', () => { let player beforeEach(done => { diff --git a/test/specs/utils.js b/test/specs/utils.js index 470eeeab..f82505db 100644 --- a/test/specs/utils.js +++ b/test/specs/utils.js @@ -1,4 +1,4 @@ -import { parseStartTime, randomString, omit, getConfig } from '../../src/utils' +import { parseStartTime, randomString, omit, getConfig, callPlayer } from '../../src/utils' const { describe, it, expect } = window @@ -143,3 +143,36 @@ describe('getConfig', () => { }) }) }) + +describe('callPlayer', () => { + it('calls a player method', () => { + const fakePlayer = { + player: { + testMethod: () => 'result' + } + } + expect(callPlayer.call(fakePlayer, 'testMethod')).to.equal('result') + }) + + it('returns null when player is not available', () => { + const fakePlayer = { + constructor: { + displayName: 'TestPlayer' + }, + player: null + } + expect(callPlayer.call(fakePlayer, 'testMethod')).to.equal(null) + }) + + it('returns null when method is not available', () => { + const fakePlayer = { + constructor: { + displayName: 'TestPlayer' + }, + player: { + testMethod: null + } + } + expect(callPlayer.call(fakePlayer, 'testMethod')).to.equal(null) + }) +})