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 (
3131 BaseComponent ,
3232 mapStateToProps = defaultMapStateToProps ,
3333 mapVideoElToProps = defaultMapVideoElToProps ,
34- mergeProps = defaultMergeProps
34+ mergeProps = defaultMergeProps ,
35+ videoId
3536) => class Video extends Component {
3637 constructor ( props ) {
3738 super ( props ) ;
@@ -95,14 +96,17 @@ export default (
9596 this . unbindEvents ( ) ;
9697 }
9798
98- // Stop `this.el` from being null briefly on every render ,
99+ // Stop `this.el` from being null briefly on every rendxwxer ,
99100 // see: https://github.com/mderrick/react-html5video/pull/65
100101 setRef ( el ) {
101102 this . el = findDOMNode ( el ) ;
102103 }
103104
104105 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 ] ;
106110 this . bindEventsToUpdateState ( ) ;
107111 }
108112
Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ const TestVideo = ({ video, ...restProps }) => {
2020 < video { ...restProps } >
2121 < source src = "1" />
2222 </ video >
23+ < video
24+ id = "video2"
25+ { ...restProps }
26+ >
27+ < source src = "2" />
28+ </ video >
2329 < TestControl { ...video } />
2430 </ div >
2531 ) ;
@@ -228,7 +234,20 @@ describe('video', () => {
228234 expect ( component . find ( TestVideo ) . prop ( 'duplicateKey' ) ) . toBe ( 'mapVideoElToProps' ) ;
229235 } ) ;
230236 } ) ;
231- } ) ;
232-
233-
234237
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