From ec0e907ba6c4ea750851c76cda65bc915906243d Mon Sep 17 00:00:00 2001 From: irfanuddinahmad Date: Wed, 2 Dec 2026 10:35:03 +0500 Subject: [PATCH] test: restore Video JS spec assertions weakened during extraction Restore the original openedx-platform assertions for the Video player Karma specs that were weakened when they were ported in #189: - video_player_spec: import Hls from 'hls.js' (the same module the player source imports). The spec imported the 'hls' webpack alias, which resolves to hls.js/dist/hls.js, while the player's 'hls.js' import resolves to dist/hls.mjs. The two are separate module instances, so spyOn(HLS, 'isSupported') never reached the player. - video_player_spec: 'can use native hls playback support' asserts unconditionally again. - video_player_spec: 'shows error message if hls is not supported' is it() again instead of xit(). - html5_video_spec: [play] uses the real video.play() and the 'player state was changed' / 'callback was called' tests wait for the state change again; [pause] no longer fakes play() and waits on !== PLAYING as before. - video_volume_control_spec: 'render the volume control' checks again that the control renders inside .secondary-controls. Fixes openedx/xblocks-core#353 Co-Authored-By: Claude Opus 5.5 --- src/xblock_video/tests/js/html5_video_spec.js | 38 +++++++++++-------- .../tests/js/video_player_spec.js | 17 ++++----- .../tests/js/video_volume_control_spec.js | 14 ++++++- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/xblock_video/tests/js/html5_video_spec.js b/src/xblock_video/tests/js/html5_video_spec.js index 967034d8..67b0a909 100644 --- a/src/xblock_video/tests/js/html5_video_spec.js +++ b/src/xblock_video/tests/js/html5_video_spec.js @@ -85,11 +85,9 @@ }); describe('[play]', function() { + // Restored from openedx-platform xmodule/js/spec/video/html5_video_spec.js (removed in openedx/openedx-platform#38750) beforeEach(function() { - spyOn(state.videoPlayer.player.video, 'play').and.callFake(function() { - jasmine.fireEvent(state.videoPlayer.player.video, 'play'); - return Promise.resolve(); - }); + spyOn(state.videoPlayer.player.video, 'play').and.callThrough(); state.videoPlayer.player.playerState = STATUS.PAUSED; state.videoPlayer.player.playVideo(); }); @@ -98,24 +96,31 @@ expect(state.videoPlayer.player.video.play).toHaveBeenCalled(); }); - it('player state was changed', function() { - expect([STATUS.BUFFERING, STATUS.PLAYING]).toContain( - state.videoPlayer.player.getPlayerState() - ); + // Restored from openedx-platform xmodule/js/spec/video/html5_video_spec.js (removed in openedx/openedx-platform#38750) + it('player state was changed', function(done) { + jasmine.waitUntil(function() { + return state.videoPlayer.player.getPlayerState() !== STATUS.PAUSED; + }).then(function() { + expect([STATUS.BUFFERING, STATUS.PLAYING]).toContain( + state.videoPlayer.player.getPlayerState() + ); + }).always(done); }); - it('callback was called', function() { - expect(state.videoPlayer.player.callStateChangeCallback) - .toHaveBeenCalled(); + // Restored from openedx-platform xmodule/js/spec/video/html5_video_spec.js (removed in openedx/openedx-platform#38750) + it('callback was called', function(done) { + jasmine.waitUntil(function() { + return state.videoPlayer.player.getPlayerState() !== STATUS.PAUSED; + }).then(function() { + expect(state.videoPlayer.player.callStateChangeCallback) + .toHaveBeenCalled(); + }).always(done); }); }); describe('[pause]', function() { + // Restored from openedx-platform xmodule/js/spec/video/html5_video_spec.js (removed in openedx/openedx-platform#38750) beforeEach(function(done) { - spyOn(state.videoPlayer.player.video, 'play').and.callFake(function() { - jasmine.fireEvent(state.videoPlayer.player.video, 'play'); - return Promise.resolve(); - }); spyOn(state.videoPlayer.player.video, 'pause').and.callThrough(); state.videoPlayer.player.playerState = STATUS.UNSTARTED; state.videoPlayer.player.playVideo(); @@ -131,9 +136,10 @@ expect(state.videoPlayer.player.video.pause).toHaveBeenCalled(); }); + // Restored from openedx-platform xmodule/js/spec/video/html5_video_spec.js (removed in openedx/openedx-platform#38750) it('player state was changed', function(done) { jasmine.waitUntil(function() { - return state.videoPlayer.player.getPlayerState() === STATUS.PAUSED; + return state.videoPlayer.player.getPlayerState() !== STATUS.PLAYING; }).then(function() { expect(state.videoPlayer.player.getPlayerState()) .toBe(STATUS.PAUSED); diff --git a/src/xblock_video/tests/js/video_player_spec.js b/src/xblock_video/tests/js/video_player_spec.js index 3079710b..741cfb19 100644 --- a/src/xblock_video/tests/js/video_player_spec.js +++ b/src/xblock_video/tests/js/video_player_spec.js @@ -1,7 +1,7 @@ /* global YT */ import VideoPlayer from "../../assets/js/src/03_video_player.js"; -import HLS from 'hls'; +import Hls from 'hls.js'; import _ from 'underscore'; (function() { @@ -979,30 +979,27 @@ import _ from 'underscore'; describe('on safari', function() { beforeEach(function() { - spyOn(HLS, 'isSupported').and.returnValue(false); + spyOn(Hls, 'isSupported').and.returnValue(false); state = jasmine.initializeHLSPlayer(); state.canPlayHLS = true; state.browserIsSafari = true; }); + // Restored from openedx-platform xmodule/js/spec/video/video_player_spec.js (removed in openedx/openedx-platform#38750) it('can use native hls playback support', function() { - // When HLS is not supported and browser reports Safari, native playback may be used - // The assertion depends on init order - skip if hls.js was already chosen - if (state.videoPlayer.player && state.videoPlayer.player.hls === undefined) { - expect(state.videoPlayer.player.hls).toBeUndefined(); - } + expect(state.videoPlayer.player.hls).toBeUndefined(); }); }); }); describe('HLS Video Errors', function() { beforeEach(function() { - spyOn(HLS, 'isSupported').and.returnValue(false); + spyOn(Hls, 'isSupported').and.returnValue(false); state = jasmine.initializeHLSPlayer({sources: ['/base/fixtures/hls/hls.m3u8']}); }); - xit('shows error message if hls is not supported', function() { - // Skipped: error message visibility is async/env-dependent in headless Firefox + // Restored from openedx-platform xmodule/js/spec/video/video_player_spec.js (removed in openedx/openedx-platform#38750) + it('shows error message if hls is not supported', function() { expect($('.video-hls-error')).not.toHaveClass('is-hidden'); expect($('.video-hls-error').text().trim()).toEqual( 'Your browser does not support this video format. Try using a different browser.' diff --git a/src/xblock_video/tests/js/video_volume_control_spec.js b/src/xblock_video/tests/js/video_volume_control_spec.js index c8693160..2fa8ea0c 100644 --- a/src/xblock_video/tests/js/video_volume_control_spec.js +++ b/src/xblock_video/tests/js/video_volume_control_spec.js @@ -42,8 +42,18 @@ expect(volumeControl.volume).toEqual(75); }); - it('render the volume control', function() { - expect($('.volume')).toExist(); + // Restored from openedx-platform xmodule/js/spec/video/video_volume_control_spec.js (removed in openedx/openedx-platform#38750) + it('render the volume control', function(done) { + jasmine.waitUntil(function() { + return state.videoVolumeControl && + state.videoVolumeControl.el && + state.videoVolumeControl.el.closest('.secondary-controls').length === 1; + }).then(function() { + expect(state.videoVolumeControl.el).toBeInDOM(); + done(); + }).fail(function() { + done.fail('VideoVolumeControl did not render into .secondary-controls before the test timed out.'); + }); }); it('create the slider', function() {