diff --git a/src/lib/viewers/controls/media/SubtitlesToggle.tsx b/src/lib/viewers/controls/media/SubtitlesToggle.tsx index b3392ac13..63ad5b92b 100644 --- a/src/lib/viewers/controls/media/SubtitlesToggle.tsx +++ b/src/lib/viewers/controls/media/SubtitlesToggle.tsx @@ -5,12 +5,14 @@ import { Subtitle } from './MediaSettingsMenuSubtitles'; import './SubtitlesToggle.scss'; export type Props = { + isAutoGeneratedSubtitles?: boolean; isShowingSubtitles?: boolean; onSubtitlesToggle?: (isShowingSubtitles: boolean) => void; subtitles?: Array; }; export default function SubtitlesToggle({ + isAutoGeneratedSubtitles, isShowingSubtitles, onSubtitlesToggle = noop, subtitles = [], @@ -19,13 +21,15 @@ export default function SubtitlesToggle({ return null; } + const title = isAutoGeneratedSubtitles ? __('media_auto_generated_captions') : __('media_subtitles_cc'); + return ( onSubtitlesToggle(!isShowingSubtitles)} - title={__('media_subtitles_cc')} + title={title} >
CC
diff --git a/src/lib/viewers/controls/media/__tests__/SubtitlesToggle-test.tsx b/src/lib/viewers/controls/media/__tests__/SubtitlesToggle-test.tsx index 2da402deb..2a3bf8eef 100644 --- a/src/lib/viewers/controls/media/__tests__/SubtitlesToggle-test.tsx +++ b/src/lib/viewers/controls/media/__tests__/SubtitlesToggle-test.tsx @@ -40,5 +40,18 @@ describe('SubtitlesToggle', () => { expect(wrapper.prop('aria-pressed')).toBe(isShowingSubtitles); }, ); + + test.each` + isAutoGeneratedSubtitles | title + ${true} | ${__('media_auto_generated_captions')} + ${false} | ${__('media_subtitles_cc')} + `( + 'should set the title accordingly when isAutoGeneratedSubtitles is $isAutoGeneratedSubtitles', + ({ isAutoGeneratedSubtitles, title }) => { + const wrapper = getWrapper({ isAutoGeneratedSubtitles, title }); + + expect(wrapper.prop('title')).toBe(title); + }, + ); }); }); diff --git a/src/lib/viewers/media/DashControls.tsx b/src/lib/viewers/media/DashControls.tsx index 3221462d8..d47e3ce3c 100644 --- a/src/lib/viewers/media/DashControls.tsx +++ b/src/lib/viewers/media/DashControls.tsx @@ -25,6 +25,7 @@ export default function DashControls({ bufferedRange, currentTime, durationTime, + isAutoGeneratedSubtitles, isPlaying, isPlayingHD, onAudioTrackChange, @@ -62,6 +63,7 @@ export default function DashControls({
{ test('should render SubtitlesToggle if subtitles exist', () => { const onSubtitlesToggle = jest.fn(); - const wrapper = getWrapper({ onSubtitlesToggle, subtitles }); + const wrapper = getWrapper({ isAutoGeneratedSubtitles: true, onSubtitlesToggle, subtitles }); expect(wrapper.find(SubtitlesToggle).props()).toMatchObject({ + isAutoGeneratedSubtitles: true, isShowingSubtitles: true, onSubtitlesToggle, }); diff --git a/src/lib/viewers/media/__tests__/DashViewer-test.js b/src/lib/viewers/media/__tests__/DashViewer-test.js index 5f7435797..ab47a48ce 100644 --- a/src/lib/viewers/media/__tests__/DashViewer-test.js +++ b/src/lib/viewers/media/__tests__/DashViewer-test.js @@ -966,6 +966,26 @@ describe('lib/viewers/media/DashViewer', () => { dash.loadAutoGeneratedCaptions(transcript); expect(dash.setupAutoCaptionDisplayer).toBeCalledWith(cues); }); + + describe('With React controls', () => { + beforeEach(() => { + jest.spyOn(dash, 'getViewerOption').mockImplementation(() => true); + jest.spyOn(dash, 'initSubtitles').mockImplementation(); + jest.spyOn(dash.mediaControls, 'setLabel').mockImplementation(); + jest.spyOn(dash.mediaControls, 'initSubtitles').mockImplementation(); + }); + + test('should update textTracks and call initSubtitles', () => { + dash.autoCaptionDisplayer = null; + dash.createTextCues.mockReturnValue(cues); + dash.loadAutoGeneratedCaptions(transcript); + + expect(dash.initSubtitles).toBeCalled(); + expect(dash.textTracks).toEqual([{ id: 0, language: __('auto_generated') }]); + expect(dash.mediaControls.setLabel).not.toBeCalled(); + expect(dash.mediaControls.initSubtitles).not.toBeCalled(); + }); + }); }); describe('createTextCues()', () => {