Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Dec 5, 2017
1 parent a1b6a6e commit 2e88e5e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
32 changes: 32 additions & 0 deletions test/specs/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ describe('ReactPlayer', () => {
})
}

describe('playbackRate change', () => {
it('updates correctly', () => {
let player
const updatePlayer = () => {
render(
<ReactPlayer
url='http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
playbackRate={0.5}
onProgress={() => {
const p = player.getInternalPlayer()
if (p && p.playbackRate === 0.5) {
updatePlayer()
}
}}
/>,
div)
}
render(
<ReactPlayer
ref={p => { 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 => {
Expand Down
35 changes: 34 additions & 1 deletion test/specs/utils.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
})
})

0 comments on commit 2e88e5e

Please sign in to comment.