From 7972c23a55fb820b1b7fd47eadd674e3be058c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <34163393+amtins@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:38:41 +0100 Subject: [PATCH] fix(error-display): component remains displayed after player reset (#8482) When `player.reset` is called, the `errorDisplay` component is not reset, and neither is `player.error`. - Sets `player.error` to `null`, so that the `player.errorDisplay` and `player.error` are correctly reset. - Adds an `error` function to the `testPlayer` stub to prevent tests from failing. --- src/js/player.js | 3 +++ test/unit/player.test.js | 2 ++ test/unit/reset-ui.test.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/js/player.js b/src/js/player.js index e872644b9d..df362e3b6f 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -3604,6 +3604,9 @@ class Player extends Component { this.loadTech_(this.options_.techOrder[0], null); this.techCall_('reset'); this.resetControlBarUI_(); + + this.error(null); + if (isEvented(this)) { this.trigger('playerreset'); } diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 3b77360594..7253a8fd0f 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1910,6 +1910,7 @@ QUnit.test('player#reset loads the Html5 tech and then techCalls reset', functio options_: { techOrder: ['html5', 'youtube'] }, + error() {}, resetCache_() {}, loadTech_(tech, source) { loadedTech = tech; @@ -1942,6 +1943,7 @@ QUnit.test('player#reset loads the first item in the techOrder and then techCall options_: { techOrder: ['youtube', 'html5'] }, + error() {}, resetCache_() {}, loadTech_(tech, source) { loadedTech = tech; diff --git a/test/unit/reset-ui.test.js b/test/unit/reset-ui.test.js index 9d0b4f97b2..a09808fd5d 100644 --- a/test/unit/reset-ui.test.js +++ b/test/unit/reset-ui.test.js @@ -144,3 +144,19 @@ QUnit.test('Calling resetVolumeBar player method should reset volume bar', funct player.dispose(); }); + +QUnit.test('Calling reset player method should reset both error display and player error', function(assert) { + const player = TestHelpers.makePlayer({techOrder: ['html5']}); + + player.error('ERROR'); + + assert.notOk(player.errorDisplay.hasClass('vjs-hidden'), 'ErrorDisplay is displayed if there is an error'); + assert.strictEqual(player.error().message, 'ERROR', 'player error has content'); + + player.reset(); + + assert.ok(player.errorDisplay.hasClass('vjs-hidden'), 'ErrorDisplay is not displayed if there is no error'); + assert.strictEqual(player.error(), null, 'player error has content'); + + player.dispose(); +});