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

test(e2e): Add tests for basic Media Settings #1398

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions src/lib/viewers/controls/media/MediaSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,33 @@ export default function MediaSettings({
return (
<Settings badge={badge} className={className} toggle={toggle}>
<Settings.Menu name={Menu.MAIN}>
<Settings.MenuItem label={__('media_autoplay')} target={Menu.AUTOPLAY} value={autoValue} />
<Settings.MenuItem label={__('media_speed')} target={Menu.RATE} value={rateValue} />
<Settings.MenuItem
data-testid="bp-media-settings-autoplay"
label={__('media_autoplay')}
target={Menu.AUTOPLAY}
value={autoValue}
/>
<Settings.MenuItem
data-testid="bp-media-settings-speed"
label={__('media_speed')}
target={Menu.RATE}
value={rateValue}
/>
{quality && (
<Settings.MenuItem
data-testid="bp-media-settings-quality"
label={__('media_quality')}
target={Menu.QUALITY}
value={getQualityLabel(quality)}
/>
)}
{showAudioTrackItems && (
<Settings.MenuItem label={__('media_audio')} target={Menu.AUDIO} value={audioTrackLabel} />
<Settings.MenuItem
data-testid="bp-media-settings-audiotracks"
label={__('media_audio')}
target={Menu.AUDIO}
value={audioTrackLabel}
/>
)}
</Settings.Menu>

Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/controls/settings/SettingsFlyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function SettingsFlyout({
'bp-is-open': isOpen,
'bp-is-transitioning': isTransitioning,
})}
data-testid="bp-settings-flyout"
style={{ height, width }}
>
{isOpen && children}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/viewers/controls/settings/SettingsMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SettingsContext, { Menu } from './SettingsContext';
import { decodeKeydown } from '../../../util';
import './SettingsMenuItem.scss';

export type Props = {
export type Props = React.RefAttributes<HTMLDivElement> & {
className?: string;
label: string;
target: Menu;
Expand All @@ -14,7 +14,7 @@ export type Props = {
export type Ref = HTMLDivElement;

function SettingsMenuItem(props: Props, ref: React.Ref<Ref>): JSX.Element {
const { className, label, target, value } = props;
const { className, label, target, value, ...rest } = props;
const { setActiveMenu } = React.useContext(SettingsContext);

const handleClick = (): void => {
Expand All @@ -40,6 +40,7 @@ function SettingsMenuItem(props: Props, ref: React.Ref<Ref>): JSX.Element {
onKeyDown={handleKeydown}
role="menuitem"
tabIndex={0}
{...rest}
>
<div aria-label={label} className="bp-SettingsMenuItem-label">
{label}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/media/DashControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function DashControls({
volume,
}: Props): JSX.Element {
return (
<div className="bp-DashControls">
<div className="bp-DashControls" data-testid="media-controls-wrapper">
<TimeControls
bufferedRange={bufferedRange}
currentTime={currentTime}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/media/MP3Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function MP3Controls({
volume,
}: Props): JSX.Element {
return (
<div className="bp-MP3Controls">
<div className="bp-MP3Controls" data-testid="media-controls-wrapper">
<TimeControls
bufferedRange={bufferedRange}
currentTime={currentTime}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/media/MP4Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function MP4Controls({
volume,
}: Props): JSX.Element {
return (
<div className="bp-MP4Controls">
<div className="bp-MP4Controls" data-testid="media-controls-wrapper">
<TimeControls
bufferedRange={bufferedRange}
currentTime={currentTime}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/viewers/media/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ const SETTINGS_MENU_PADDING = 18;
const SETTINGS_MENU_PADDING_SCROLL = 32;
const SETTINGS_MENU_MAX_HEIGHT = 210;

const SETTINGS_TEMPLATE = `<div class="bp-media-settings">
const SETTINGS_TEMPLATE = `<div class="bp-media-settings" data-testid="bp-settings-flyout">
<div class="bp-media-settings-menu-main bp-media-settings-menu" role="menu">
<div class="bp-media-settings-item bp-media-settings-item-autoplay" data-type="autoplay" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-item bp-media-settings-item-autoplay" data-testid="bp-media-settings-autoplay" data-type="autoplay" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-label" aria-label="${__('media_autoplay')}">${__('media_autoplay')}</div>
<div class="bp-media-settings-value">${__('media_autoplay_disabled')}</div>
<div class="bp-media-settings-arrow">${ICON_ARROW_RIGHT}</div>
</div>
<div class="bp-media-settings-item bp-media-settings-item-speed" data-type="speed" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-item bp-media-settings-item-speed" data-testid="bp-media-settings-speed" data-type="speed" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-label" aria-label="${__('media_speed')}">${__('media_speed')}</div>
<div class="bp-media-settings-value">${__('media_speed_normal')}</div>
<div class="bp-media-settings-arrow">${ICON_ARROW_RIGHT}</div>
</div>
<div class="bp-media-settings-item bp-media-settings-item-quality" data-type="quality" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-item bp-media-settings-item-quality" data-testid="bp-media-settings-quality" data-type="quality" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-label" aria-label="${__('media_quality')}">${__('media_quality')}</div>
<div class="bp-media-settings-value">${__('media_quality_auto')}</div>
<div class="bp-media-settings-arrow">${ICON_ARROW_RIGHT}</div>
</div>
<div class="bp-media-settings-item bp-media-settings-item-subtitles bp-media-settings-is-hidden" data-type="subtitles" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-item bp-media-settings-item-subtitles data-testid="bp-media-settings-subtitles" bp-media-settings-is-hidden" data-type="subtitles" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-label" aria-label="${__('subtitles')}/CC">${__('subtitles')}/CC</div>
<div class="bp-media-settings-value">${__('off')}</div>
<div class="bp-media-settings-arrow">${ICON_ARROW_RIGHT}</div>
</div>
<div class="bp-media-settings-item bp-media-settings-item-audiotracks bp-media-settings-is-hidden" data-type="audiotracks" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-item bp-media-settings-item-audiotracks bp-media-settings-is-hidden" data-testid="bp-media-settings-audiotracks" data-type="audiotracks" tabindex="0" role="menuitem" aria-haspopup="true">
<div class="bp-media-settings-label" aria-label="${__('media_audio')}">${__('media_audio')}</div>
<div class="bp-media-settings-value"></div>
<div class="bp-media-settings-arrow">${ICON_ARROW_RIGHT}</div>
Expand Down
150 changes: 150 additions & 0 deletions test/integration/media/MediaSettingsBase.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
function runBaseMediaSettingsTests() {
beforeEach(() => {
cy.showMediaControls();

// Open the menu
cy.getByTitle('Settings').click({ force: true });
});

describe('Media Settings', () => {
it('Should be able to toggle media settings menu', () => {
cy.getByTestId('bp-settings-flyout').should('be.visible');
cy.getByTestId('bp-media-settings-autoplay').contains('Disabled');
cy.getByTestId('bp-media-settings-speed').contains('Normal');

// Close the menu
cy.getByTitle('Settings').click({ force: true });
cy.getByTestId('bp-settings-flyout').should('not.be.visible');
});

it('Should be able to click away from media settings menu to close it', () => {
cy.getByTestId('bp-settings-flyout').should('be.visible');
cy.getByTestId('bp-media-settings-autoplay').contains('Disabled');
cy.getByTestId('bp-media-settings-speed').contains('Normal');

// Click away from menu
cy.getByTestId('bp').click();
cy.getByTestId('bp-settings-flyout').should('not.be.visible');
});

it('Should be able to change the Autoplay setting', () => {
cy.getByTestId('bp-media-settings-autoplay')
.contains('Disabled')
.click();

cy.get('[role="menuitem"]').contains('Autoplay');

cy.getByTestId('bp-settings-flyout')
.contains('Enabled')
.click();

cy.getByTestId('bp-media-settings-autoplay').contains('Enabled');
});

it('Should be able to change the Speed setting', () => {
cy.getByTestId('bp-media-settings-speed')
.contains('Normal')
.click();

cy.get('[role="menuitem"]').contains('Speed');

cy.getByTestId('bp-settings-flyout')
.contains('0.5')
.click();

cy.getByTestId('bp-media-settings-speed').contains('0.5');
});
});
}

describe('Media Settings Base', () => {
const token = Cypress.env('ACCESS_TOKEN');
const fileIdVideo = Cypress.env('FILE_ID_VIDEO');
const fileIdVideo360 = Cypress.env('FILE_ID_VIDEO_360');
const fileIdMP3 = Cypress.env('FILE_ID_MP3');

describe('MP4 Viewer', () => {
describe('Without react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdVideo, {
viewers: { Dash: { disabled: true }, MP4: { useReactControls: false } },
});
});

runBaseMediaSettingsTests();
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
});

describe('With react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdVideo, {
viewers: { Dash: { disabled: true }, MP4: { useReactControls: true } },
});
});

runBaseMediaSettingsTests();
});
});

describe('Dash Viewer', () => {
describe('Without react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdVideo, {
viewers: { Dash: { useReactControls: false } },
});
});

runBaseMediaSettingsTests();
});

describe('With react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdVideo, {
viewers: { Dash: { useReactControls: true } },
});
});

runBaseMediaSettingsTests();
});
});

describe('MP3 Viewer', () => {
describe('Without react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdMP3, {
viewers: { MP3: { useReactControls: false } },
});
});

runBaseMediaSettingsTests();
});

describe('With react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdMP3, {
viewers: { MP3: { useReactControls: true } },
});
});

runBaseMediaSettingsTests();
});
});

describe('Video360 Viewer', () => {
describe('Without react controls', () => {
beforeEach(() => {
cy.visit('/');
cy.showPreview(token, fileIdVideo360, {
viewers: { Video360: { useReactControls: false } },
});
});

runBaseMediaSettingsTests();
});
});
});
15 changes: 3 additions & 12 deletions test/integration/sanity/FileOptions.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ describe('Preview File Options', () => {
},
};

/* eslint-disable */
const showMediaControls = () => {
// Hover over the preview to trigger the controls
cy.getByTestId('bp').trigger('mouseover');
// Assert that the controls are shown
return cy.getByTestId('media-controls-wrapper').should('be.visible');
};
/* eslint-enable */

beforeEach(() => {
cy.visit('/');
});
Expand All @@ -51,18 +42,18 @@ describe('Preview File Options', () => {
it('Should open video(DASH) to the specified timestamp', () => {
cy.showPreview(token, fileIdVideo, { fileOptions });

showMediaControls().contains('0:15');
cy.showMediaControls().contains('0:15');
});

it('Should open video(MP4) to the specified timestamp', () => {
cy.showPreview(token, fileIdVideo, { fileOptions, viewers: { Dash: { disabled: true } } });

showMediaControls().contains('0:15');
cy.showMediaControls().contains('0:15');
});

it('Should open MP3 to the specified timestamp', () => {
cy.showPreview(token, fileIdMp3, { fileOptions });

showMediaControls().contains('0:03');
cy.showMediaControls().contains('0:03');
});
});
7 changes: 7 additions & 0 deletions test/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ Cypress.Commands.add('showControls', () => {
cy.getByTestId('bp').trigger('mouseover');
cy.getByTestId('bp-controls').should('be.visible');
});

Cypress.Commands.add('showMediaControls', () => {
// Hover over the preview to trigger the controls
cy.getByTestId('bp').trigger('mouseover');
// Assert that the controls are shown
return cy.getByTestId('media-controls-wrapper').should('be.visible');
});
1 change: 1 addition & 0 deletions test/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Cypress.env({
FILE_ID_VIDEO_SMALL: '415542846356',
FILE_ID_VIDEO_SUBTITLES_TRACKS: '415542245854',
FILE_ID_VIDEO: '416047501580',
FILE_ID_VIDEO_360: '818568699040',
});