1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/test/unit/seek-to-live.test.js

102 lines
3.0 KiB
JavaScript
Raw Normal View History

/* eslint-env qunit */
import TestHelpers from './test-helpers.js';
import sinon from 'sinon';
import computedStyle from '../../src/js/utils/computed-style.js';
import { createTimeRange } from '../../src/js/utils/time-ranges.js';
QUnit.module('SeekToLive', () => {
QUnit.module('live with liveui', {
beforeEach() {
this.clock = sinon.useFakeTimers();
this.player = TestHelpers.makePlayer({liveui: true});
this.seekToLive = this.player.controlBar.seekToLive;
this.player.seekable = () => createTimeRange(0, 45);
this.getComputedDisplay = () => {
return computedStyle(this.seekToLive.el(), 'display');
};
// mock live state
this.player.duration(Infinity);
},
afterEach() {
this.player.dispose();
this.clock.restore();
}
});
QUnit.test('at live edge if liveTracker says we are', function(assert) {
this.player.liveTracker.behindLiveEdge = () => false;
this.player.liveTracker.trigger('liveedgechange');
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
});
QUnit.test('behind live edge if liveTracker says we are', function(assert) {
this.player.liveTracker.behindLiveEdge = () => true;
this.player.liveTracker.trigger('liveedgechange');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have live edge class');
});
QUnit.test('switch to non live', function(assert) {
this.player.duration(4);
this.player.trigger('durationchange');
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
});
QUnit.module('live without liveui', {
beforeEach() {
this.clock = sinon.useFakeTimers();
this.player = TestHelpers.makePlayer();
this.seekToLive = this.player.controlBar.seekToLive;
this.player.seekable = () => createTimeRange(0, 45);
this.getComputedDisplay = () => {
return computedStyle(this.seekToLive.el(), 'display');
};
// mock live state
this.player.duration(Infinity);
},
afterEach() {
this.player.dispose();
this.clock.restore();
}
});
QUnit.test('should be hidden', function(assert) {
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
});
QUnit.module('not live', {
beforeEach() {
this.player = TestHelpers.makePlayer({liveui: true});
this.seekToLive = this.player.controlBar.seekToLive;
this.getComputedDisplay = () => {
return computedStyle(this.seekToLive.el(), 'display');
};
},
afterEach() {
this.player.dispose();
}
});
QUnit.test('should not show or track', function(assert) {
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
});
QUnit.test('switch to live', function(assert) {
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
this.player.seekable = () => createTimeRange(0, 45);
this.player.duration(Infinity);
this.player.trigger('durationchange');
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
});
});