@@ -173,6 +173,50 @@ describe('HlsjsPlayback', () => {
173173 } )
174174 } )
175175
176+ describe ( '_ready method' , ( ) => {
177+ test ( 'avoid to run internal logic if _isReadyState flag is true' , ( ) => {
178+ const playback = new HlsjsPlayback ( { src : 'http://clappr.io/video.m3u8' } )
179+ playback . _isReadyState = true
180+ jest . spyOn ( playback , '_setup' )
181+ playback . _ready ( )
182+
183+ expect ( playback . _setup ) . not . toHaveBeenCalled ( )
184+ } )
185+
186+ test ( 'call _setup method if HLS.JS internal don\'t exists' , ( ) => {
187+ const playback = new HlsjsPlayback ( { src : 'http://clappr.io/video.m3u8' } )
188+ jest . spyOn ( playback , '_setup' )
189+ playback . _ready ( )
190+
191+ expect ( playback . _setup ) . toHaveBeenCalledTimes ( 1 )
192+
193+ playback . _ready ( )
194+ expect ( playback . _setup ) . toHaveBeenCalledTimes ( 1 )
195+ } )
196+
197+ test ( 'update _isReadyState flag value to true' , ( ) => {
198+ const playback = new HlsjsPlayback ( { src : 'http://clappr.io/video.m3u8' } )
199+
200+ expect ( playback . _isReadyState ) . toBeFalsy ( )
201+
202+ playback . _ready ( )
203+
204+ expect ( playback . _isReadyState ) . toBeTruthy ( )
205+ } )
206+
207+ test ( 'triggers PLAYBACK_READY event' , done => {
208+ const cb = jest . fn ( )
209+ const playback = new HlsjsPlayback ( { src : 'http://clappr.io/video.m3u8' } )
210+
211+ playback . listenTo ( playback , Events . PLAYBACK_READY , cb )
212+ playback . listenTo ( playback , Events . PLAYBACK_READY , ( ) => {
213+ expect ( cb ) . toHaveBeenCalledTimes ( 1 )
214+ done ( )
215+ } )
216+ playback . _ready ( )
217+ } )
218+ } )
219+
176220 describe ( 'play method' , ( ) => {
177221 test ( 'calls this._hls.loadSource if _manifestParsed flag and options.hlsPlayback.preload are falsy' , ( ) => {
178222 const playback = new HlsjsPlayback ( { src : 'http://clappr.io/foo.m3u8' , hlsPlayback : { preload : true } } )
0 commit comments