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

VideoPress block: Add tests to verify Privacy and Rating settings #5754

Merged
merged 12 commits into from
May 17, 2023
2 changes: 1 addition & 1 deletion gutenberg
SiobhyB marked this conversation as resolved.
Show resolved Hide resolved
Submodule gutenberg updated 51 files
+1 −0 bin/build-plugin-zip.sh
+1 −1 docs/reference-guides/core-blocks.md
+0 −46 lib/compat/wordpress-6.3/get-global-styles-and-settings.php
+34 −0 lib/compat/wordpress-6.3/link-template.php
+17 −3 lib/compat/wordpress-6.3/rest-api.php
+3 −0 lib/experimental/editor-settings.php
+12 −0 lib/experiments-page.php
+46 −0 lib/global-styles-and-settings.php
+1 −0 lib/load.php
+29 −29 package-lock.json
+1 −3 packages/block-editor/src/components/block-styles/preview-panel.js
+12 −9 packages/block-editor/src/components/iframe/index.js
+2 −1 packages/block-editor/src/components/list-view/style.scss
+9 −1 packages/block-editor/src/components/use-resize-canvas/index.js
+1 −1 packages/block-library/package.json
+0 −9 packages/block-library/src/buttons/test/edit.native.js
+2 −3 packages/block-library/src/image/deprecated.js
+3 −2 packages/block-library/src/image/edit.js
+2 −6 packages/block-library/src/image/image.js
+4 −3 packages/block-library/src/image/save.js
+11 −18 packages/block-library/src/image/utils.js
+1 −4 packages/block-library/src/latest-posts/edit.native.js
+4 −5 packages/block-library/src/media-text/deprecated.js
+1 −2 packages/block-library/src/media-text/save.js
+4 −1 packages/block-library/src/navigation/index.php
+4 −0 packages/block-library/src/pattern/block.json
+51 −16 packages/block-library/src/pattern/edit.js
+5 −4 packages/block-library/src/pattern/index.js
+11 −3 packages/block-library/src/pattern/index.php
+57 −0 packages/block-library/src/pattern/v1/edit.js
+4 −6 packages/block-library/src/template-part/edit/index.js
+1 −1 packages/block-library/src/template-part/edit/utils/hooks.js
+1 −1 packages/blocks/package.json
+1 −0 packages/components/CHANGELOG.md
+1 −1 packages/components/package.json
+5 −12 packages/components/src/button/style.scss
+1 −1 packages/core-data/package.json
+0 −177 packages/e2e-tests/specs/editor/blocks/cover.test.js
+1 −1 packages/edit-post/package.json
+1 −1 packages/edit-site/package.json
+12 −5 packages/edit-site/src/components/list/actions/index.js
+3 −4 packages/edit-site/src/store/actions.js
+15 −5 packages/edit-site/src/store/test/utils.js
+1 −1 packages/editor/package.json
+4 −1 packages/editor/src/components/entities-saved-states/index.js
+1 −1 packages/i18n/package.json
+4 −0 packages/icons/README.md
+1 −1 packages/plugins/package.json
+1 −1 packages/rich-text/package.json
+1 −1 packages/shortcode/package.json
+284 −0 test/e2e/specs/editor/blocks/cover.spec.js
2 changes: 1 addition & 1 deletion jetpack
SiobhyB marked this conversation as resolved.
Show resolved Hide resolved
Submodule jetpack updated 458 files
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;
SiobhyB marked this conversation as resolved.
Show resolved Hide resolved

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' ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first privacy option (Site default (Public)) can also be Site default (Private) if the site is private. I'm wondering if it would be worth adding a test case for this, WDYT? Note that it would require mocking the hook or the fetch request that returns the site privacy value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a great idea! I looked a bit into what was needed and see that it would involve mocking the useSyncMedia hook in order to get the privateEnabledForSite value, like here. I think that would be easier to get working when that hook has been mocked for testing the syncing, so will make a note to follow up with a different PR after that. :)


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 ) );
};