Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controls): Default to show CC #1405

Merged
merged 1 commit into from
Jun 23, 2021
Merged
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
6 changes: 6 additions & 0 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@ class DashViewer extends VideoBaseViewer {
*/
initSubtitles() {
const clientLanguage = getLanguageName(this.options.location.locale.substring(0, 2));
const showSubtitles = this.cache.get('media-subtitles-toggle');

// If no entry in the cache (nor localstorage) default to showing CC
if (showSubtitles === undefined) {
this.cache.set('media-subtitles-toggle', true, true);
}

this.textTracks = this.textTracks.map(track => ({
...track,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,8 @@ describe('lib/viewers/media/DashViewer', () => {
beforeEach(() => {
jest.spyOn(dash, 'getSubtitleId').mockImplementation();
jest.spyOn(dash, 'setSubtitle').mockImplementation();
jest.spyOn(dash.cache, 'get').mockImplementation();
jest.spyOn(dash.cache, 'set').mockImplementation();

const english = { language: 'eng', id: 5 };
const russian = { language: 'rus', id: 4 };
Expand Down Expand Up @@ -1691,6 +1693,12 @@ describe('lib/viewers/media/DashViewer', () => {

expect(dash.selectedSubtitle).toBe(4);
});

test('should set media-subtitles-toggle to true by default', () => {
dash.initSubtitles();

expect(dash.cache.set).toBeCalledWith('media-subtitles-toggle', true, true);
});
});

describe('setSubtitle()', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/media/DashViewer.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('Dash Viewer', () => {
runQualityMenuTests();

runAudioTracksTests();

runSubtitlesTests();
});
});
});
25 changes: 24 additions & 1 deletion test/support/mediaSettingsTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function runSubtitlesTests() {
cy.getByTestId('bp-media-settings-subtitles').contains('Spanish');
});

it('Should be able to turn off subtitles via the button', () => {
it('Toggle CC button should turn off and on subtitles', () => {
cy.getByTitle('Subtitles/Closed Captions')
.as('subtitlesBtn')
.should('be.visible')
Expand All @@ -122,7 +122,18 @@ export function runSubtitlesTests() {
.click()
.should('have.attr', 'aria-pressed', 'false');

cy.getByTitle('Settings').click();

cy.getByTestId('bp-media-settings-subtitles').contains('Off');

// Toggling CC back on should restore the previously used text track
cy.get('@subtitlesBtn')
.click()
.should('have.attr', 'aria-pressed', 'true');

cy.getByTitle('Settings').click();

cy.getByTestId('bp-media-settings-subtitles').contains('English');
});

it('Should be able to turn off subtitles via the menu', () => {
Expand All @@ -142,6 +153,18 @@ export function runSubtitlesTests() {
cy.get('@subtitlesBtn').should('have.attr', 'aria-pressed', 'false');

cy.getByTestId('bp-media-settings-subtitles').contains('Off');

// Toggling CC back on should restore the previously used text track
cy.getByTitle('Subtitles/Closed Captions')
.as('subtitlesBtn')
.should('be.visible')
.should('have.attr', 'aria-pressed', 'false')
.click()
.should('have.attr', 'aria-pressed', 'true');

cy.getByTitle('Settings').click();

cy.getByTestId('bp-media-settings-subtitles').contains('English');
});
});
}