2016-08-04 17:49:32 +02:00
/* eslint-env qunit */
2015-04-14 22:08:32 +02:00
import VolumeControl from '../../src/js/control-bar/volume-control/volume-control.js' ;
2015-03-26 06:43:41 +02:00
import MuteToggle from '../../src/js/control-bar/mute-toggle.js' ;
2017-02-21 22:53:56 +02:00
import VolumeBar from '../../src/js/control-bar/volume-control/volume-bar.js' ;
2015-04-14 22:08:32 +02:00
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js' ;
import Slider from '../../src/js/slider/slider.js' ;
2016-08-15 23:44:01 +02:00
import FullscreenToggle from '../../src/js/control-bar/fullscreen-toggle.js' ;
2015-03-26 06:43:41 +02:00
import TestHelpers from './test-helpers.js' ;
import document from 'global/document' ;
2017-02-01 00:15:56 +02:00
import Html5 from '../../src/js/tech/html5.js' ;
2017-02-21 22:53:56 +02:00
import sinon from 'sinon' ;
QUnit . module ( 'Controls' , {
beforeEach ( assert ) {
this . clock = sinon . useFakeTimers ( ) ;
} ,
afterEach ( assert ) {
this . clock . restore ( ) ;
}
} ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
QUnit . test ( 'should hide volume control if it\'s not supported' , function ( assert ) {
assert . expect ( 2 ) ;
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = false ;
2013-04-09 23:18:55 +03:00
2016-08-04 17:49:32 +02:00
const volumeControl = new VolumeControl ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
2013-03-02 01:11:20 +03:00
2017-01-27 03:53:53 +02:00
assert . ok ( volumeControl . hasClass ( 'vjs-hidden' ) , 'volumeControl is not hidden' ) ;
assert . ok ( muteToggle . hasClass ( 'vjs-hidden' ) , 'muteToggle is not hidden' ) ;
2018-01-30 20:26:21 +02:00
2017-01-27 03:53:53 +02:00
player . dispose ( ) ;
2013-03-02 01:11:20 +03:00
} ) ;
2016-08-12 19:51:31 +02:00
QUnit . test ( 'should test and toggle volume control on `loadstart`' , function ( assert ) {
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = true ;
2013-04-09 23:18:55 +03:00
2016-08-04 17:49:32 +02:00
const volumeControl = new VolumeControl ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , false , 'volumeControl is hidden initially' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , false , 'muteToggle is hidden initially' ) ;
2013-03-02 01:11:20 +03:00
2016-08-04 17:49:32 +02:00
player . tech _ . featuresVolumeControl = false ;
2017-01-27 03:53:53 +02:00
player . trigger ( 'loadstart' ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , true , 'volumeControl does not hide itself' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , true , 'muteToggle does not hide itself' ) ;
2013-03-02 01:11:20 +03:00
2016-08-04 17:49:32 +02:00
player . tech _ . featuresVolumeControl = true ;
2017-01-27 03:53:53 +02:00
player . trigger ( 'loadstart' ) ;
2013-03-02 01:11:20 +03:00
2016-08-12 19:51:31 +02:00
assert . equal ( volumeControl . hasClass ( 'vjs-hidden' ) , false , 'volumeControl does not show itself' ) ;
assert . equal ( muteToggle . hasClass ( 'vjs-hidden' ) , false , 'muteToggle does not show itself' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2013-03-02 01:11:20 +03:00
} ) ;
2013-04-22 20:57:42 +03:00
2016-08-12 19:51:31 +02:00
QUnit . test ( 'calculateDistance should use changedTouches, if available' , function ( assert ) {
2017-01-27 03:53:53 +02:00
const player = TestHelpers . makePlayer ( ) ;
player . tech _ . featuresVolumeControl = true ;
2016-08-04 17:49:32 +02:00
const slider = new Slider ( player ) ;
2013-04-22 20:57:42 +03:00
document . body . appendChild ( slider . el _ ) ;
slider . el _ . style . position = 'absolute' ;
slider . el _ . style . width = '200px' ;
slider . el _ . style . left = '0px' ;
2016-08-04 17:49:32 +02:00
const event = {
2013-04-22 20:57:42 +03:00
pageX : 10 ,
changedTouches : [ {
pageX : 100
} ]
} ;
2016-08-12 19:51:31 +02:00
assert . equal ( slider . calculateDistance ( event ) , 0.5 , 'we should have touched exactly in the center, so, the ratio should be half' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2013-04-22 20:57:42 +03:00
} ) ;
2014-05-14 00:02:02 +03:00
2016-08-12 19:51:31 +02:00
QUnit . test ( 'should hide playback rate control if it\'s not supported' , function ( assert ) {
assert . expect ( 1 ) ;
2014-05-14 00:02:02 +03:00
2016-08-04 17:49:32 +02:00
const player = TestHelpers . makePlayer ( ) ;
const playbackRate = new PlaybackRateMenuButton ( player ) ;
2014-05-14 00:02:02 +03:00
2016-08-12 19:51:31 +02:00
assert . ok ( playbackRate . el ( ) . className . indexOf ( 'vjs-hidden' ) >= 0 , 'playbackRate is not hidden' ) ;
2018-01-30 20:26:21 +02:00
2016-08-25 16:58:42 +02:00
player . dispose ( ) ;
2014-05-14 00:02:02 +03:00
} ) ;
2016-08-15 23:44:01 +02:00
2017-11-17 01:12:09 +02:00
QUnit . test ( 'Fullscreen control text should be correct when fullscreenchange is triggered' , function ( assert ) {
2016-08-15 23:44:01 +02:00
const player = TestHelpers . makePlayer ( ) ;
const fullscreentoggle = new FullscreenToggle ( player ) ;
2016-08-16 00:20:47 +02:00
2016-08-15 23:44:01 +02:00
player . isFullscreen ( true ) ;
player . trigger ( 'fullscreenchange' ) ;
2017-11-17 01:12:09 +02:00
assert . equal ( fullscreentoggle . controlText ( ) , 'Non-Fullscreen' , 'Control Text is correct while switching to fullscreen mode' ) ;
2018-01-30 20:26:21 +02:00
2016-08-15 23:44:01 +02:00
player . isFullscreen ( false ) ;
player . trigger ( 'fullscreenchange' ) ;
2017-11-17 01:12:09 +02:00
assert . equal ( fullscreentoggle . controlText ( ) , 'Fullscreen' , 'Control Text is correct while switching back to normal mode' ) ;
2018-01-30 20:26:21 +02:00
2016-08-25 16:58:42 +02:00
player . dispose ( ) ;
2016-08-16 00:20:47 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
// only run these tests if Html5 is supported.
// IE8 can't run the Html5 tech and to test this functionality otherwith the the tech faker,
// we'd need to implement volume functionality into tech faker
if ( Html5 . isSupported ( ) ) {
QUnit . test ( 'Clicking MuteToggle when volume is above 0 should toggle muted property and not change volume' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is above 0' ) ;
assert . equal ( player . muted ( ) , false , 'player is not muted' ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is same' ) ;
assert . equal ( player . muted ( ) , true , 'player is muted' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-02-01 00:15:56 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0 and muted is false should set volume to lastVolume and keep muted false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
player . volume ( 0 ) ;
assert . equal ( player . lastVolume _ ( ) , 1 , 'lastVolume is set' ) ;
assert . equal ( player . muted ( ) , false , 'player is muted' ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
assert . equal ( player . volume ( ) , 1 , 'volume is set to lastVolume' ) ;
assert . equal ( player . muted ( ) , false , 'muted remains false' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-02-01 00:15:56 +02:00
} ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0 and muted is true should set volume to lastVolume and sets muted to false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
player . volume ( 0 ) ;
player . muted ( true ) ;
player . lastVolume _ ( 0.5 ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
muteToggle . handleClick ( ) ;
2017-01-31 22:29:07 +02:00
2017-02-01 00:15:56 +02:00
assert . equal ( player . volume ( ) , 0.5 , 'volume is set to lastVolume' ) ;
assert . equal ( player . muted ( ) , false , 'muted is set to false' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-02-01 00:15:56 +02:00
} ) ;
2017-02-21 22:53:56 +02:00
2017-03-24 21:14:41 +02:00
QUnit . test ( 'Clicking MuteToggle when volume is 0, lastVolume is less than 0.1, and muted is true sets volume to 0.1 and muted to false' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const muteToggle = new MuteToggle ( player ) ;
player . volume ( 0 ) ;
player . muted ( true ) ;
player . lastVolume _ ( 0.05 ) ;
muteToggle . handleClick ( ) ;
2017-03-25 00:26:28 +02:00
// `Number.prototype.toFixed()` is used here to circumvent IE9 rounding issues
assert . equal ( player . volume ( ) . toFixed ( 1 ) , ( 0.1 ) . toFixed ( 1 ) , 'since lastVolume is less than 0.1, volume is set to 0.1' ) ;
2017-03-24 21:14:41 +02:00
assert . equal ( player . muted ( ) , false , 'muted is set to false' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-03-24 21:14:41 +02:00
} ) ;
2017-02-21 22:53:56 +02:00
QUnit . test ( 'ARIA value of VolumeBar should start at 100' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const volumeBar = new VolumeBar ( player ) ;
this . clock . tick ( 1 ) ;
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 100 , 'ARIA value of VolumeBar is 100' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-02-21 22:53:56 +02:00
} ) ;
QUnit . test ( 'Muting with MuteToggle should set ARIA value of VolumeBar to 0' , function ( assert ) {
const player = TestHelpers . makePlayer ( { techOrder : [ 'html5' ] } ) ;
const volumeBar = new VolumeBar ( player ) ;
const muteToggle = new MuteToggle ( player ) ;
this . clock . tick ( 1 ) ;
assert . equal ( player . volume ( ) , 1 , 'Volume is 1' ) ;
assert . equal ( player . muted ( ) , false , 'Muted is false' ) ;
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 100 , 'ARIA value of VolumeBar is 100' ) ;
muteToggle . handleClick ( ) ;
// Because `volumechange` is triggered asynchronously, it doesn't end up
// getting fired on `player` in the test environment, so we run it
// manually.
player . trigger ( 'volumechange' ) ;
assert . equal ( player . volume ( ) , 1 , 'Volume remains 1' ) ;
assert . equal ( player . muted ( ) , true , 'Muted is true' ) ;
assert . equal ( volumeBar . el _ . getAttribute ( 'aria-valuenow' ) , 0 , 'ARIA value of VolumeBar is 0' ) ;
2018-01-30 20:26:21 +02:00
player . dispose ( ) ;
2017-02-21 22:53:56 +02:00
} ) ;
2017-02-01 00:15:56 +02:00
}