Skip to content

Commit

Permalink
Merge pull request #5754 from wordpress-mobile/add/videopress-rating-…
Browse files Browse the repository at this point in the history
…and-setting-tests

VideoPress block: Add tests to verify Privacy and Rating settings
  • Loading branch information
Siobhan Bamber authored May 17, 2023
2 parents 174802c + 82208a9 commit 26dfd76
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/test/videopress/__snapshots__/edit.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ exports[`Update VideoPress block's settings should update Privacy and Rating sec

exports[`Update VideoPress block's settings should update Privacy and Rating section's Show video sharing menu 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"displayEmbed":false,"rating":"G","isPrivate":true,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update Privacy and Rating section's privacy setting to Private 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","allowDownload":false,"rating":"G","isPrivate":true,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update Privacy and Rating section's privacy setting to Public 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":0,"allowDownload":false,"rating":"G","isPrivate":false,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update Privacy and Rating section's rating setting to PG-13 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"PG-13","isPrivate":true,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update Privacy and Rating section's rating setting to R 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"R-17","isPrivate":true,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update description 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"The video's new description!","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":true,"duration":2803} /-->"`;

exports[`Update VideoPress block's settings should update title 1`] = `"<!-- wp:videopress/video {"title":"Hello world!","description":"","useAverageColor":false,"id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":true,"duration":2803} /-->"`;
43 changes: 43 additions & 0 deletions src/test/videopress/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import {
VIDEOPRESS_BLOCK_HTML,
PLAYBACK_SETTINGS,
PLAYBACK_BAR_COLOR_SETTINGS,
RATING_OPTIONS,
PRIVACY_OPTIONS,
ADDITIONAL_PRIVACY_AND_RATING_SETTINGS,
} from './local-helpers/constants';
import {
selectAndOpenBlockSettings,
pressSettingInPanel,
pressSettingInPicker,
} from './local-helpers/utils';

setupCoreBlocks();
Expand Down Expand Up @@ -126,6 +129,46 @@ describe( "Update VideoPress block's settings", () => {
} );
} );

/*
* RATING SETTINGS
* Loop through each of the possible ratings and select each one
*/
RATING_OPTIONS.forEach( ( option, index ) => {
// Skip the default setting, as it is already selected
if ( index === 0 ) return;

it( `should update Privacy and Rating section's rating setting to ${ option }`, async () => {
await selectAndOpenBlockSettings( screen );
await pressSettingInPicker(
screen,
'Privacy and Rating',
'Rating',
RATING_OPTIONS,
option
);
} );
} );

/*
* PRIVACY SETTINGS
* Loop through each of the possible privacy options and select each one
*/
PRIVACY_OPTIONS.forEach( ( option, index ) => {
// Skip the default setting, as it is already selected
if ( index === 0 ) return;

it( `should update Privacy and Rating section's privacy setting to ${ option }`, async () => {
await selectAndOpenBlockSettings( screen );
await pressSettingInPicker(
screen,
'Privacy and Rating',
'Privacy',
PRIVACY_OPTIONS,
option
);
} );
} );

/*
* PRIVACY AND RATING SETTINGS
* Loop through the additional Privacy and Rating settings and toggle on/off
Expand Down
4 changes: 4 additions & 0 deletions src/test/videopress/local-helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const PLAYBACK_SETTINGS = [

export const PLAYBACK_BAR_COLOR_SETTINGS = [ 'Dynamic color' ];

export const RATING_OPTIONS = [ 'G', 'PG-13', 'R' ];

export const PRIVACY_OPTIONS = [ 'Site default (Public)', 'Public', 'Private' ];

export const ADDITIONAL_PRIVACY_AND_RATING_SETTINGS = [
'Allow download',
'Show video sharing menu',
Expand Down
37 changes: 36 additions & 1 deletion src/test/videopress/local-helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* External dependencies
*/
import { act, getBlock, fireEvent, openBlockSettings } from 'test/helpers';
import {
act,
getBlock,
fireEvent,
openBlockSettings,
setupPicker,
} from 'test/helpers';

export const selectAndOpenBlockSettings = async ( screen ) => {
const videoPressBlock = await getBlock( screen, 'VideoPress' );
Expand Down Expand Up @@ -31,3 +37,32 @@ export const pressSettingInPanel = async ( screen, panel, setting ) => {
// Toggle the specified setting
await act( () => fireEvent.press( getByText( setting ) ) );
};

/**
* Presses a setting in a specified panel, triggers a picker, and selects an option from the sheet.
*
* @param {Object} screen - The editor's screen.
* @param {string} panel - The panel containing the setting to be pressed.
* @param {string} setting - The setting to be pressed, which triggers the picker.
* @param {string[]} options - An array of all the options available in the picker.
* @param {string} option - The option to be selected from the picker.
*/
export const pressSettingInPicker = async (
screen,
panel,
setting,
options,
option
) => {
const { getByText } = screen;

// Navigate to the specified settings panel
fireEvent.press( getByText( panel ) );

// Setup the picker and open picker
const { selectOption } = setupPicker( screen, options );
fireEvent.press( getByText( setting ) );

// Select the specified option from the picker
await act( () => selectOption( option ) );
};

0 comments on commit 26dfd76

Please sign in to comment.