2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-04-14 22:08:32 +02:00
|
|
|
import PosterImage from '../../src/js/poster-image.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import TestHelpers from './test-helpers.js';
|
|
|
|
import document from 'global/document';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('PosterImage', {
|
2016-08-12 19:51:31 +02:00
|
|
|
beforeEach() {
|
2014-10-16 22:59:41 +03:00
|
|
|
// Store the original background support so we can test different vals
|
2015-08-25 02:46:54 +02:00
|
|
|
this.poster1 = '#poster1';
|
|
|
|
this.poster2 = '#poster2';
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2020-11-11 01:09:37 +02:00
|
|
|
this.mockPlayer = TestHelpers.makePlayer({
|
|
|
|
poster: this.poster1
|
|
|
|
});
|
2014-10-16 22:59:41 +03:00
|
|
|
},
|
2019-08-30 20:56:41 +02:00
|
|
|
afterEach() {}
|
2014-10-16 22:59:41 +03:00
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should create and update a poster image', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
2022-08-22 18:15:02 +02:00
|
|
|
let pictureImg = posterImage.$('img').src;
|
2016-08-03 21:27:03 +02:00
|
|
|
|
2022-08-22 18:15:02 +02:00
|
|
|
assert.notEqual(pictureImg.indexOf(this.poster1), -1, 'Background image used');
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Update with a new poster source and check the new value
|
|
|
|
this.mockPlayer.poster_ = this.poster2;
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2022-08-22 18:15:02 +02:00
|
|
|
pictureImg = posterImage.$('img').src;
|
|
|
|
assert.notEqual(pictureImg.indexOf(this.poster2), -1, 'Background image updated');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2014-10-16 22:59:41 +03:00
|
|
|
});
|
2013-11-27 03:53:23 +03:00
|
|
|
|
2022-08-22 18:15:02 +02:00
|
|
|
QUnit.test('should mirror crossOrigin', function(assert) {
|
|
|
|
assert.strictEqual(this.mockPlayer.posterImage.$('img').crossOrigin, null, 'crossOrigin not set when not present in options');
|
|
|
|
assert.strictEqual(this.mockPlayer.posterImage.crossOrigin(), null, 'crossOrigin not set from getter when not present in options');
|
|
|
|
|
|
|
|
this.mockPlayer.crossOrigin('anonymous');
|
|
|
|
|
|
|
|
assert.strictEqual(this.mockPlayer.posterImage.$('img').crossOrigin, 'anonymous', 'crossOrigin updated');
|
|
|
|
assert.strictEqual(this.mockPlayer.posterImage.crossOrigin(), 'anonymous', 'crossOrigin getter returns updated value');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-01-24 10:59:27 +02:00
|
|
|
QUnit.test('should populate an alt attribute', function(assert) {
|
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
|
|
|
|
assert.ok(posterImage.$('img').hasAttribute('alt'), 'img has alt atttribute');
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should remove itself from the document flow when there is no poster', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(posterImage.el().style.display, '', 'Poster image shows by default');
|
2013-12-02 19:11:22 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Update with an empty string
|
|
|
|
this.mockPlayer.poster_ = '';
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
posterImage.hasClass('vjs-hidden'),
|
|
|
|
true,
|
|
|
|
'Poster image hides with an empty source'
|
|
|
|
);
|
2023-02-20 11:04:39 +02:00
|
|
|
assert.equal(posterImage.$('img'), null, 'Poster image with no source has no img el');
|
2013-12-02 19:11:22 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Updated with a valid source
|
|
|
|
this.mockPlayer.poster_ = this.poster2;
|
|
|
|
this.mockPlayer.trigger('posterchange');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
posterImage.hasClass('vjs-hidden'),
|
|
|
|
false,
|
|
|
|
'Poster image shows again when there is a source'
|
|
|
|
);
|
2023-02-20 11:04:39 +02:00
|
|
|
assert.ok(posterImage.$('img'), 'Poster image with source restores img el');
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2013-11-27 03:53:23 +03:00
|
|
|
});
|
2014-10-01 04:34:51 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should hide the poster in the appropriate player states', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const posterImage = new PosterImage(this.mockPlayer);
|
|
|
|
const playerDiv = document.createElement('div');
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
const el = posterImage.el();
|
2014-10-01 04:34:51 +03:00
|
|
|
|
2014-10-16 22:59:41 +03:00
|
|
|
// Remove the source so when we add to the DOM it doesn't throw an error
|
|
|
|
// We want to poster to still think it has a real source so it doesn't hide itself
|
|
|
|
posterImage.setSrc('');
|
|
|
|
|
|
|
|
// Add the elements to the DOM so styles are computed
|
|
|
|
playerDiv.appendChild(el);
|
|
|
|
fixture.appendChild(playerDiv);
|
|
|
|
|
|
|
|
playerDiv.className = 'video-js vjs-has-started';
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
TestHelpers.getComputedStyle(el, 'display'),
|
|
|
|
'none',
|
|
|
|
'The poster hides when the video has started (CSS may not be loaded)'
|
|
|
|
);
|
2014-10-16 22:59:41 +03:00
|
|
|
|
|
|
|
playerDiv.className = 'video-js vjs-has-started vjs-audio';
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
TestHelpers.getComputedStyle(el, 'display'),
|
|
|
|
'block',
|
|
|
|
'The poster continues to show when playing audio'
|
|
|
|
);
|
2018-01-30 20:26:21 +02:00
|
|
|
|
|
|
|
posterImage.dispose();
|
2014-10-01 04:34:51 +03:00
|
|
|
});
|