/
Facebook.js
102 lines (94 loc) · 2.31 KB
/
Facebook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from 'react'
import test from 'ava'
import sinon from 'sinon'
import { configure, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import testPlayerMethods from '../helpers/testPlayerMethods'
import * as utils from '../../src/utils'
import { Facebook } from '../../src/players/Facebook'
global.document = {
getElementById: () => ({
querySelector: () => ({
style: {}
})
})
}
configure({ adapter: new Adapter() })
const TEST_URL = 'https://www.facebook.com/facebook/videos/10153231379946729'
const TEST_CONFIG = {
facebook: {
appId: '123'
}
}
Facebook.prototype.componentWillMount = function () {
this.playerID = 'mock-player-id'
}
testPlayerMethods(Facebook, {
play: 'play',
pause: 'pause',
stop: null,
seekTo: 'seek',
setVolume: 'setVolume',
mute: 'mute',
unmute: 'unmute',
getDuration: 'getDuration',
getCurrentTime: 'getCurrentPosition',
getSecondsLoaded: null
})
test('load()', async t => {
const FB = {
init: () => null,
Event: {
subscribe: (event, fn) => {
if (event === 'xfbml.ready') {
fn({
type: 'video',
id: 'mock-player-id',
instance: {
subscribe: () => null,
unmute: () => null
}
})
}
}
}
}
const getSDK = sinon.stub(utils, 'getSDK').resolves(FB)
const onReady = () => t.pass()
const instance = shallow(<Facebook config={TEST_CONFIG} onReady={onReady} />).instance()
instance.load(TEST_URL)
t.true(getSDK.calledOnce)
getSDK.restore()
})
test('load() when ready', async t => {
const FB = {
XFBML: {
parse: () => t.pass()
}
}
const getSDK = sinon.stub(utils, 'getSDK').resolves(FB)
const onReady = () => t.pass()
const instance = shallow(<Facebook config={TEST_CONFIG} onReady={onReady} />).instance()
instance.load(TEST_URL, true)
t.true(getSDK.calledOnce)
getSDK.restore()
})
test('render()', t => {
const style = {
width: '100%',
height: '100%',
backgroundColor: 'black'
}
const wrapper = shallow(<Facebook url={TEST_URL} />)
t.true(wrapper.contains(
<div
style={style}
id='mock-player-id'
className='fb-video'
data-href={TEST_URL}
data-autoplay='false'
data-allowfullscreen='true'
data-controls='false'
/>
))
})