File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ export default (
31
31
BaseComponent ,
32
32
mapStateToProps = defaultMapStateToProps ,
33
33
mapVideoElToProps = defaultMapVideoElToProps ,
34
- mergeProps = defaultMergeProps
34
+ mergeProps = defaultMergeProps ,
35
+ videoId
35
36
) => class Video extends Component {
36
37
constructor ( props ) {
37
38
super ( props ) ;
@@ -95,14 +96,17 @@ export default (
95
96
this . unbindEvents ( ) ;
96
97
}
97
98
98
- // Stop `this.el` from being null briefly on every render ,
99
+ // Stop `this.el` from being null briefly on every rendxwxer ,
99
100
// see: https://github.com/mderrick/react-html5video/pull/65
100
101
setRef ( el ) {
101
102
this . el = findDOMNode ( el ) ;
102
103
}
103
104
104
105
componentDidMount ( ) {
105
- this . videoEl = this . el . getElementsByTagName ( 'video' ) [ 0 ] ;
106
+ const videoEls = this . el . getElementsByTagName ( 'video' ) ;
107
+ this . videoEl = videoId
108
+ ? videoEls . namedItem ( videoId )
109
+ : videoEls [ 0 ] ;
106
110
this . bindEventsToUpdateState ( ) ;
107
111
}
108
112
Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ const TestVideo = ({ video, ...restProps }) => {
20
20
< video { ...restProps } >
21
21
< source src = "1" />
22
22
</ video >
23
+ < video
24
+ id = "video2"
25
+ { ...restProps }
26
+ >
27
+ < source src = "2" />
28
+ </ video >
23
29
< TestControl { ...video } />
24
30
</ div >
25
31
) ;
@@ -228,7 +234,20 @@ describe('video', () => {
228
234
expect ( component . find ( TestVideo ) . prop ( 'duplicateKey' ) ) . toBe ( 'mapVideoElToProps' ) ;
229
235
} ) ;
230
236
} ) ;
231
- } ) ;
232
-
233
-
234
237
238
+ describe ( 'when passing in a video id as the fourth argument to the HOC' , ( ) => {
239
+ const videoEl = { id : 'video2' } ;
240
+ beforeEach ( ( ) => {
241
+ component = shallow (
242
+ < Component />
243
+ ) ;
244
+
245
+ // Emulate videoEl being present
246
+ // e.g. componentDidMount
247
+ component . instance ( ) . videoEl = videoEl ;
248
+ } ) ;
249
+ it ( 'should find the video by id' , ( ) => {
250
+ expect ( videoEl . id ) . toEqual ( 'video2' ) ;
251
+ } ) ;
252
+ } ) ;
253
+ } ) ;
You can’t perform that action at this time.
0 commit comments