From 728f7d2c71ed97a6ca6b372a860374f84396a526 Mon Sep 17 00:00:00 2001 From: Ahtisham Shahid Date: Fri, 7 Feb 2020 16:07:21 +0500 Subject: [PATCH] Updated Trascript functionality removed extras fixed initial state of transcript Fixed js tests fixed js tests created and fixed tests Updated Trascript functionality updated v name fixed spacing --- .../xmodule/js/src/video/09_video_caption.js | 32 +++++++++++++++++-- .../tests/video/test_studio_video_module.py | 16 ++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js b/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js index aa638cf938..af67bef637 100644 --- a/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js +++ b/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js @@ -36,13 +36,15 @@ 'previousLanguageMenuItem', 'nextLanguageMenuItem', 'handleCaptionToggle', 'showClosedCaptions', 'hideClosedCaptions', 'toggleClosedCaptions', 'updateCaptioningCookie', 'handleCaptioningCookie', 'handleTranscriptToggle', - 'listenForDragDrop' + 'listenForDragDrop', 'handleTranscriptCookie', 'updateTranscriptCookie' ); + this.state = state; this.state.videoCaption = this; this.renderElements(); this.handleCaptioningCookie(); this.listenForDragDrop(); + this.handleTranscriptCookie(); return $.Deferred().resolve().promise(); }; @@ -1142,11 +1144,12 @@ */ toggle: function(event) { event.preventDefault(); - if (this.state.el.hasClass('closed')) { this.hideCaptions(false, true, true); + this.updateTranscriptCookie(true); } else { this.hideCaptions(true, true, true); + this.updateTranscriptCookie(false); } }, @@ -1232,6 +1235,31 @@ }); } }, + handleTranscriptCookie: function() { + if ($.cookie('show_transcript') === null) { + return; + } + if ($.cookie('show_transcript') !== 'false') { + this.state.hideCaptions = false; + // keep it going until turned off or in case of null initially change to true + this.updateTranscriptCookie(true); + } else { + this.state.hideCaptions = true; + } + this.hideCaptions(this.state.hideCaptions, true, true); + }, + updateTranscriptCookie: function(showTranscript) { + if (showTranscript) { + $.cookie('show_transcript', 'true', { + expires: 3650, + path: '/' + }); + } else { + $.cookie('show_transcript', 'false', { + path: '/' + }); + } + }, listenForDragDrop: function() { var captions = this.captionDisplayEl['0']; diff --git a/common/test/acceptance/tests/video/test_studio_video_module.py b/common/test/acceptance/tests/video/test_studio_video_module.py index e2e2abcd0a..0cbd37e374 100644 --- a/common/test/acceptance/tests/video/test_studio_video_module.py +++ b/common/test/acceptance/tests/video/test_studio_video_module.py @@ -288,6 +288,22 @@ class CMSVideoTest(CMSVideoBaseTest): self.assertTrue(self.video.is_captions_visible()) + def test_transcript_state_is_saved_on_reload(self): + """ + Scenario: Transcripts state is preserved + Given I have created a Video component with subtitles + And I have toggled off the transcript + After page reload transcript is already off + Then when I view the video it does show the captions + """ + self._create_course_unit(subtitles=True) + self.video.click_player_button('transcript_button') + self.assertFalse(self.video.is_captions_visible()) + self.video.click_player_button('transcript_button') + self.assertTrue(self.video.is_captions_visible()) + self.browser.refresh() + self.assertTrue(self.video.is_captions_visible()) + def test_caption_line_focus(self): """ Scenario: When enter key is pressed on a caption, an outline shows around it