Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libs/blocks/preflight/checks/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions test/blocks/preflight/checks/assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading