2018-12-03 22:31:23 +02:00
|
|
|
/* eslint-env qunit */
|
|
|
|
import TestHelpers from './test-helpers.js';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import computedStyle from '../../src/js/utils/computed-style.js';
|
2020-03-10 21:53:17 +02:00
|
|
|
import { createTimeRange } from '../../src/js/utils/time-ranges.js';
|
2018-12-03 22:31:23 +02:00
|
|
|
|
2020-03-30 23:27:45 +02:00
|
|
|
QUnit.module('SeekToLive', {
|
|
|
|
beforeEach() {
|
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
this.player = TestHelpers.makePlayer();
|
|
|
|
this.seekToLive = this.player.controlBar.seekToLive;
|
|
|
|
this.getComputedDisplay = () => {
|
|
|
|
return computedStyle(this.seekToLive.el(), 'display');
|
|
|
|
};
|
|
|
|
|
|
|
|
this.mockLiveui = () => {
|
|
|
|
this.player.paused = () => false;
|
|
|
|
this.player.hasStarted = () => true;
|
|
|
|
this.player.options_.liveui = true;
|
2020-03-10 21:53:17 +02:00
|
|
|
this.player.seekable = () => createTimeRange(0, 45);
|
2020-03-30 23:27:45 +02:00
|
|
|
this.player.currentTime = () => this.player.liveTracker.liveCurrentTime();
|
|
|
|
this.player.duration(Infinity);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
this.player.dispose();
|
|
|
|
this.clock.restore();
|
|
|
|
}
|
|
|
|
});
|
2018-12-03 22:31:23 +02:00
|
|
|
|
2020-03-30 23:27:45 +02:00
|
|
|
QUnit.test('liveui enabled, can switch between at and behind live edge ', function(assert) {
|
|
|
|
this.mockLiveui();
|
2018-12-03 22:31:23 +02:00
|
|
|
|
2020-03-30 23:27:45 +02:00
|
|
|
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
|
|
|
|
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
|
2018-12-03 22:31:23 +02:00
|
|
|
|
2020-03-30 23:27:45 +02:00
|
|
|
this.player.currentTime = () => 0;
|
|
|
|
this.player.seekable = () => createTimeRange(0, 38);
|
|
|
|
this.clock.tick(30);
|
2018-12-03 22:31:23 +02:00
|
|
|
|
2020-03-30 23:27:45 +02:00
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('liveui enabled can show/hide on durationchange', function(assert) {
|
|
|
|
// start out non-live
|
|
|
|
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
|
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
|
|
|
|
|
|
|
// switch to live
|
|
|
|
this.mockLiveui();
|
|
|
|
|
|
|
|
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
|
|
|
|
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
|
|
|
|
|
|
|
|
// switch to non-live
|
|
|
|
this.player.duration(20);
|
|
|
|
|
|
|
|
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
|
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
|
|
|
|
|
|
|
// back to live again.
|
|
|
|
this.mockLiveui();
|
|
|
|
|
|
|
|
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
|
|
|
|
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('liveui disabled live window is never shown', function(assert) {
|
|
|
|
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
|
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
|
|
|
|
|
|
|
this.player.paused = () => false;
|
|
|
|
this.player.hasStarted = () => true;
|
|
|
|
this.player.currentTime = () => this.player.liveTracker.liveCurrentTime();
|
|
|
|
|
|
|
|
// liveui false, seekable range is good though
|
|
|
|
this.player.options_.liveui = false;
|
|
|
|
this.player.duration(Infinity);
|
|
|
|
|
|
|
|
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
|
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
|
|
|
|
|
|
|
this.player.duration(10);
|
|
|
|
|
|
|
|
// liveui false
|
|
|
|
this.player.options_.liveui = false;
|
2021-11-09 17:13:51 +02:00
|
|
|
this.player.seekable = () => createTimeRange(0, 19);
|
2020-03-30 23:27:45 +02:00
|
|
|
this.player.duration(Infinity);
|
|
|
|
|
|
|
|
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
|
|
|
|
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
|
2018-12-03 22:31:23 +02:00
|
|
|
});
|