diff --git a/libs/blocks/preflight/checks/assets.js b/libs/blocks/preflight/checks/assets.js index be4c6ebc656..78af42a4dac 100644 --- a/libs/blocks/preflight/checks/assets.js +++ b/libs/blocks/preflight/checks/assets.js @@ -20,7 +20,12 @@ function loadVideo(asset) { return new Promise((resolve) => { if (!asset.querySelector('source')) { - asset.appendChild(createTag('source', { src: asset.getAttribute('data-video-source'), type: 'video/mp4' })); + const videoSource = asset.getAttribute('data-video-source'); + if (!videoSource) { + resolve(); + return; + } + asset.appendChild(createTag('source', { src: videoSource, type: 'video/mp4' })); } ['loadedmetadata', 'error'].forEach((evt) => asset.addEventListener(evt, resolve, { once: true })); asset.load(); diff --git a/test/blocks/preflight/checks/assets.test.js b/test/blocks/preflight/checks/assets.test.js index d1ea87cd7a6..6b371fd398b 100644 --- a/test/blocks/preflight/checks/assets.test.js +++ b/test/blocks/preflight/checks/assets.test.js @@ -129,6 +129,34 @@ describe('Preflight Asset Checks', () => { }); }); + describe('Video Loading', () => { + it('should resolve immediately when video has no data-video-source attribute', async () => { + const mockVideo = { + tagName: 'VIDEO', + querySelector: sinon.stub().returns(null), + getAttribute: sinon.stub(), + appendChild: sinon.stub(), + addEventListener: sinon.stub(), + load: sinon.stub(), + checkVisibility: sinon.stub().returns(false), + closest: sinon.stub().returns(null), + }; + + mockVideo.getAttribute.withArgs('data-video-source').returns(null); + + mockDocument.querySelectorAll + .withArgs('main picture img, main video, :is(main, .dialog-modal:not(#preflight)) .adobetv') + .returns([mockVideo]); + + window.createTag = () => ({ append: sinon.stub() }); + + await checkImageDimensions('test-url-video', mockDocument); + + expect(mockVideo.appendChild.called).to.be.false; + expect(mockVideo.load.called).to.be.false; + }); + }); + describe('Additional Coverage', () => { it('tests isViewportTooSmall function', () => { expect(typeof isViewportTooSmall()).to.equal('boolean');