diff --git a/.github/workflows/end2end-test.yml b/.github/workflows/end2end-test.yml
index 694a48f0266367..5fa1a82d5ad25b 100644
--- a/.github/workflows/end2end-test.yml
+++ b/.github/workflows/end2end-test.yml
@@ -36,10 +36,6 @@ jobs:
run: |
npm run wp-env start
- - name: Running the tests
- run: |
- npx wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache"
-
- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
if: always()
diff --git a/docs/manifest.json b/docs/manifest.json
index 84c7da42aa8b20..638c5d2b16c83d 100644
--- a/docs/manifest.json
+++ b/docs/manifest.json
@@ -1679,6 +1679,12 @@
"markdown_source": "../packages/interactivity/README.md",
"parent": "packages"
},
+ {
+ "title": "API Reference",
+ "slug": "packages-interactivity-api-reference",
+ "markdown_source": "../packages/interactivity/docs/api-reference.md",
+ "parent": "packages-interactivity"
+ },
{
"title": "@wordpress/interface",
"slug": "packages-interface",
diff --git a/docs/reference-guides/block-api/block-registration.md b/docs/reference-guides/block-api/block-registration.md
index 7af276d242509a..57123b7b47093d 100644
--- a/docs/reference-guides/block-api/block-registration.md
+++ b/docs/reference-guides/block-api/block-registration.md
@@ -304,7 +304,7 @@ The key is the name of the block (`string`) to hook into, and the value is the p
```js
{
blockHooks: {
- 'core/verse': 'before'
+ 'core/verse': 'before',
'core/spacer': 'after',
'core/column': 'firstChild',
'core/group': 'lastChild',
diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php
index b97cb649bb0bc8..f5d40ae8a2110c 100644
--- a/lib/experimental/editor-settings.php
+++ b/lib/experimental/editor-settings.php
@@ -22,6 +22,9 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' );
}
+ if ( $gutenberg_experiments && array_key_exists( 'gutenberg-grid-interactivity', $gutenberg_experiments ) ) {
+ wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGridInteractivity = true', 'before' );
+ }
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
diff --git a/lib/experiments-page.php b/lib/experiments-page.php
index 6608fbb138c58f..f66e0932192637 100644
--- a/lib/experiments-page.php
+++ b/lib/experiments-page.php
@@ -90,6 +90,7 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-color-randomizer',
)
);
+
add_settings_field(
'gutenberg-form-blocks',
__( 'Form and input blocks ', 'gutenberg' ),
@@ -101,6 +102,19 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-form-blocks',
)
);
+
+ add_settings_field(
+ 'gutenberg-grid-interactivity',
+ __( 'Grid interactivty ', 'gutenberg' ),
+ 'gutenberg_display_experiment_field',
+ 'gutenberg-experiments',
+ 'gutenberg_experiments_section',
+ array(
+ 'label' => __( 'Test enhancements to the Grid block that let you move and resize items in the editor canvas.', 'gutenberg' ),
+ 'id' => 'gutenberg-grid-interactivity',
+ )
+ );
+
add_settings_field(
'gutenberg-no-tinymce',
__( 'Disable TinyMCE and Classic block', 'gutenberg' ),
diff --git a/packages/base-styles/_z-index.scss b/packages/base-styles/_z-index.scss
index ff21d1d8df8f35..762508f921a00f 100644
--- a/packages/base-styles/_z-index.scss
+++ b/packages/base-styles/_z-index.scss
@@ -108,6 +108,9 @@ $z-layers: (
// Above the block list and the header.
".block-editor-block-popover": 31,
+ // Below the block toolbar.
+ ".block-editor-grid-visualizer": 30,
+
// Show snackbars above everything (similar to popovers)
".components-snackbar-list": 100000,
diff --git a/packages/block-editor/src/components/global-styles/shadow-panel-components.js b/packages/block-editor/src/components/global-styles/shadow-panel-components.js
index 8c9ba795bc17ba..0dc2367e7eda2f 100644
--- a/packages/block-editor/src/components/global-styles/shadow-panel-components.js
+++ b/packages/block-editor/src/components/global-styles/shadow-panel-components.js
@@ -5,19 +5,25 @@ import { __ } from '@wordpress/i18n';
import {
__experimentalVStack as VStack,
__experimentalHeading as Heading,
- __experimentalGrid as Grid,
__experimentalHStack as HStack,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Button,
FlexItem,
Dropdown,
+ privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { shadow as shadowIcon, Icon, check } from '@wordpress/icons';
+
/**
* External dependencies
*/
import classNames from 'classnames';
+/**
+ * Internal dependencies
+ */
+import { unlock } from '../../lock-unlock';
+
export function ShadowPopoverContainer( { shadow, onShadowChange, settings } ) {
const defaultShadows = settings?.shadow?.presets?.default || [];
const themeShadows = settings?.shadow?.presets?.theme || [];
@@ -43,8 +49,16 @@ export function ShadowPopoverContainer( { shadow, onShadowChange, settings } ) {
}
export function ShadowPresets( { presets, activeShadow, onSelect } ) {
+ const { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =
+ unlock( componentsPrivateApis );
+ const compositeStore = useCompositeStore();
return ! presets ? null : (
-
${ text }
-`; -} - -describe( 'autosave', () => { - beforeEach( async () => { - await clearSessionStorage(); - await createNewPost(); - await setLocalAutosaveInterval( AUTOSAVE_INTERVAL_SECONDS ); - } ); - - it( 'should save to sessionStorage', async () => { - // Wait for the original timeout to kick in, it will schedule - // another run using the updated interval length of AUTOSAVE_INTERVAL_SECONDS. - await sleep( 15 ); - - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await sleep( 1 ); - await page.keyboard.type( ' after save' ); - - // Wait long enough for local autosave to kick in. - await sleep( AUTOSAVE_INTERVAL_SECONDS + 1 ); - - const id = await getCurrentPostId(); - const autosave = await readSessionStorageAutosave( id ); - const { content } = JSON.parse( autosave ); - expect( content ).toBe( wrapParagraph( 'before save after save' ) ); - } ); - - it( 'should recover from sessionStorage', async () => { - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await page.keyboard.type( ' after save' ); - - // Trigger local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - // Reload without saving on the server. - await page.reload(); - await page.waitForSelector( '.edit-post-layout' ); - - const notice = await page.$eval( - '.components-notice__content', - ( element ) => element.innerText - ); - expect( notice ).toContain( AUTOSAVE_NOTICE_LOCAL ); - - expect( await getEditedPostContent() ).toEqual( - wrapParagraph( 'before save' ) - ); - await page.click( '.components-notice__action' ); - expect( await getEditedPostContent() ).toEqual( - wrapParagraph( 'before save after save' ) - ); - } ); - - it( "shouldn't contaminate other posts", async () => { - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraft(); - - // Fake local autosave. - await page.evaluate( - ( postId ) => - window.sessionStorage.setItem( - `wp-autosave-block-editor-post-${ postId }`, - JSON.stringify( { - post_title: 'A', - content: 'B', - excerpt: 'C', - } ) - ), - await getCurrentPostId() - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 1 ); - - await page.reload(); - await page.waitForSelector( '.edit-post-layout' ); - const notice = await page.$eval( - '.components-notice__content', - ( element ) => element.innerText - ); - expect( notice ).toContain( - 'The backup of this post in your browser is different from the version below.' - ); - - await createNewPost(); - expect( await page.$( '.components-notice__content' ) ).toBe( null ); - } ); - - it( 'should clear local autosave after successful remote autosave', async () => { - // Edit, save draft, edit again. - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await page.keyboard.type( ' after save' ); - - // Trigger local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBeGreaterThanOrEqual( 1 ); - - // Trigger remote autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave() - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 0 ); - } ); - - it( "shouldn't clear local autosave if remote autosave fails", async () => { - // Edit, save draft, edit again. - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await page.keyboard.type( ' after save' ); - - // Trigger local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 1 ); - - // Bring network down and attempt to autosave remotely. - toggleOfflineMode( true ); - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave() - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 1 ); - } ); - - it( 'should clear local autosave after successful save', async () => { - // Edit, save draft, edit again. - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await page.keyboard.type( ' after save' ); - - // Trigger local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 1 ); - - await saveDraftWithKeyboard(); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 0 ); - } ); - - it( "shouldn't clear local autosave if save fails", async () => { - // Edit, save draft, edit again. - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraftWithKeyboard(); - await page.keyboard.type( ' after save' ); - - // Trigger local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBeGreaterThanOrEqual( 1 ); - - // Bring network down and attempt to save. - toggleOfflineMode( true ); - saveDraftWithKeyboard(); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBeGreaterThanOrEqual( 1 ); - } ); - - it( "shouldn't conflict with server-side autosave", async () => { - await clickBlockAppender(); - await page.keyboard.type( 'before publish' ); - await publishPost(); - - await canvas().click( '[data-type="core/paragraph"]' ); - await page.keyboard.type( ' after publish' ); - - // Trigger remote autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave() - ); - - // Force conflicting local autosave. - await page.evaluate( () => - window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBeGreaterThanOrEqual( 1 ); - - await page.reload(); - await page.waitForSelector( '.edit-post-layout' ); - - // FIXME: Occasionally, upon reload, there is no server-provided - // autosave value available, despite our having previously explicitly - // autosaved. The reasons for this are still unknown. Since this is - // unrelated to *local* autosave, until we can understand them, we'll - // drop this test's expectations if we don't have an autosave object - // available. - const stillHasRemoteAutosave = await page.evaluate( - () => - window.wp.data.select( 'core/editor' ).getEditorSettings() - .autosave - ); - if ( ! stillHasRemoteAutosave ) { - return; - } - - // Only one autosave notice should be displayed. - const notices = await page.$$( '.components-notice' ); - expect( notices.length ).toBe( 1 ); - const notice = await page.$eval( - '.components-notice__content', - ( element ) => element.innerText - ); - expect( notice ).toContain( AUTOSAVE_NOTICE_REMOTE ); - } ); - - it( 'should clear sessionStorage upon user logout', async () => { - await clickBlockAppender(); - await page.keyboard.type( 'before save' ); - await saveDraft(); - - // Fake local autosave. - await page.evaluate( - ( postId ) => - window.sessionStorage.setItem( - `wp-autosave-block-editor-post-${ postId }`, - JSON.stringify( { - post_title: 'A', - content: 'B', - excerpt: 'C', - } ) - ), - await getCurrentPostId() - ); - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 1 ); - - await Promise.all( [ - page.waitForSelector( '#wp-admin-bar-logout', { visible: true } ), - page.hover( '#wp-admin-bar-my-account' ), - ] ); - await Promise.all( [ - page.waitForNavigation(), - page.click( '#wp-admin-bar-logout' ), - ] ); - - expect( - await page.evaluate( () => window.sessionStorage.length ) - ).toBe( 0 ); - } ); - - afterEach( async () => { - toggleOfflineMode( false ); - await clearSessionStorage(); - } ); -} ); diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js index 6236ea8fe3f246..74daf15640ffaf 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js @@ -19,10 +19,11 @@ import { FlexItem, Flex, Button, + DropdownMenu, } from '@wordpress/components'; import { debounce } from '@wordpress/compose'; import { sprintf, __, _x } from '@wordpress/i18n'; -import { search, closeSmall } from '@wordpress/icons'; +import { search, closeSmall, moreVertical } from '@wordpress/icons'; /** * Internal dependencies @@ -41,15 +42,15 @@ const DEFAULT_CATEGORY = { slug: 'all', name: _x( 'All', 'font categories' ), }; + +const LOCAL_STORAGE_ITEM = 'wp-font-library-google-fonts-permission'; +const MIN_WINDOW_HEIGHT = 500; + function FontCollection( { slug } ) { const requiresPermission = slug === 'google-fonts'; const getGoogleFontsPermissionFromStorage = () => { - return ( - window.localStorage.getItem( - 'wp-font-library-google-fonts-permission' - ) === 'true' - ); + return window.localStorage.getItem( LOCAL_STORAGE_ITEM ) === 'true'; }; const [ selectedFont, setSelectedFont ] = useState( null ); @@ -76,6 +77,11 @@ function FontCollection( { slug } ) { return () => window.removeEventListener( 'storage', handleStorage ); }, [ slug, requiresPermission ] ); + const revokeAccess = () => { + window.localStorage.setItem( LOCAL_STORAGE_ITEM, 'false' ); + window.dispatchEvent( new Event( 'storage' ) ); + }; + useEffect( () => { const fetchFontCollection = async () => { try { @@ -118,7 +124,8 @@ function FontCollection( { slug } ) { // NOTE: The height of the font library modal unavailable to use for rendering font family items is roughly 417px // The height of each font family item is 61px. - const pageSize = Math.floor( ( window.innerHeight - 417 ) / 61 ); + const windowHeight = Math.max( window.innerHeight, MIN_WINDOW_HEIGHT ); + const pageSize = Math.floor( ( windowHeight - 417 ) / 61 ); const totalPages = Math.ceil( fonts.length / pageSize ); const itemsStart = ( page - 1 ) * pageSize; const itemsLimit = page * pageSize; @@ -223,11 +230,33 @@ function FontCollection( { slug } ) { ); } + const ActionsComponent = () => { + if ( slug !== 'google-fonts' || renderConfirmDialog || selectedFont ) { + return null; + } + return ( +before save after save
+` ); + } ); + + test( 'should recover from sessionStorage', async ( { + editor, + page, + pageUtils, + } ) => { + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ) + .waitFor(); + await page.keyboard.type( ' after save' ); + + // Trigger local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + // Reload without saving on the server. + await page.reload(); + + await expect( + page.locator( '.components-notice__content' ) + ).toContainText( + 'The backup of this post in your browser is different from the version below.' + ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: 'before save' }, + }, + ] ); + + await page + .getByRole( 'button', { name: 'Restore the backup' } ) + .click(); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: 'before save after save' }, + }, + ] ); + } ); + + test( "shouldn't contaminate other posts", async ( { + admin, + editor, + page, + pageUtils, + } ) => { + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ) + .waitFor(); + await page.keyboard.type( ' after save' ); + + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 1 ); + + await page.reload(); + await expect( + page.locator( '.components-notice__content' ) + ).toContainText( + 'The backup of this post in your browser is different from the version below.' + ); + + await admin.createNewPost(); + await expect( + page.locator( '.components-notice__content' ) + ).toBeHidden(); + } ); + + test( 'should clear local autosave after successful remote autosave', async ( { + editor, + page, + pageUtils, + } ) => { + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ) + .waitFor(); + await page.keyboard.type( ' after save' ); + + // Trigger local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBeGreaterThanOrEqual( 1 ); + + // Trigger remote autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave() + ); + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 0 ); + } ); + + test( "shouldn't clear local autosave if remote autosave fails", async ( { + editor, + context, + page, + pageUtils, + } ) => { + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ) + .waitFor(); + await page.keyboard.type( ' after save' ); + + // Trigger local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBeGreaterThanOrEqual( 1 ); + + // Intercept autosave request and abort it. + await context.setOffline( true ); + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave() + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 1 ); + } ); + + test( 'should clear local autosave after successful save', async ( { + page, + pageUtils, + } ) => { + const notice = page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ); + + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await notice.waitFor(); + await page.keyboard.type( ' after save' ); + await notice.click(); + + // Trigger local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBeGreaterThanOrEqual( 1 ); + + await pageUtils.pressKeys( 'primary+s' ); + await notice.waitFor(); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 0 ); + } ); + + test( "shouldn't clear local autosave if save fails", async ( { + editor, + context, + page, + pageUtils, + } ) => { + const notice = page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ); + + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await notice.waitFor(); + await page.keyboard.type( ' after save' ); + await notice.click(); + + // Trigger local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBeGreaterThanOrEqual( 1 ); + + await context.setOffline( true ); + await pageUtils.pressKeys( 'primary+s' ); + + await expect( + page.locator( '.components-notice__content' ) + ).toContainText( 'Updating failed. You are probably offline.' ); + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 1 ); + } ); + + // See https://github.com/WordPress/gutenberg/pull/17501. + test( "shouldn't conflict with server-side autosave", async ( { + editor, + page, + } ) => { + await editor.canvas + .getByRole( 'button', { name: 'Add default block' } ) + .click(); + await page.keyboard.type( 'before save' ); + await editor.publishPost(); + + const paragraph = editor.canvas.getByRole( 'document', { + name: 'Block: Paragraph', + } ); + await paragraph.click(); + await page.keyboard.type( ' after save' ); + + // Trigger remote autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave() + ); + + await expect + .poll( async () => { + return await page.evaluate( () => { + const postId = window.wp.data + .select( 'core/editor' ) + .getCurrentPostId(); + const autosaves = window.wp.data + .select( 'core' ) + .getAutosaves( 'post', postId ); + + return autosaves?.length ?? 0; + } ); + } ) + .toBeGreaterThanOrEqual( 1 ); + + // Force conflicting local autosave. + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBeGreaterThanOrEqual( 1 ); + + await page.reload(); + await page.waitForFunction( () => window?.wp?.data ); + + // FIXME: Occasionally, upon reload, there is no server-provided + // autosave value available, despite our having previously explicitly + // autosaved. The reasons for this are still unknown. Since this is + // unrelated to *local* autosave, until we can understand them, we'll + // drop this test's expectations if we don't have an autosave object + // available. + const stillHasRemoteAutosave = await page.evaluate( + () => + window.wp.data.select( 'core/editor' ).getEditorSettings() + .autosave + ); + if ( ! stillHasRemoteAutosave ) { + return; + } + + // Only remote autosave notice should be applied. + await expect( + page.locator( '.components-notice__content' ) + ).toContainText( + 'There is an autosave of this post that is more recent than the version below.' + ); + } ); + + test.skip( 'should clear sessionStorage upon user logout', async ( { + page, + pageUtils, + } ) => { + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( 'before save' ); + await pageUtils.pressKeys( 'primary+s' ); + await page + .getByRole( 'button', { name: 'Dismiss this notice' } ) + .filter( { hasText: 'Draft saved' } ) + .waitFor(); + await page.keyboard.type( ' after save' ); + + await page.evaluate( () => + window.wp.data.dispatch( 'core/editor' ).autosave( { local: true } ) + ); + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 1 ); + + await page.locator( '#wp-admin-bar-my-account' ).hover(); + await page.locator( '#wp-admin-bar-logout' ).click(); + + expect( + await page.evaluate( () => window.sessionStorage.length ) + ).toBe( 0 ); + } ); +} ); diff --git a/test/e2e/specs/interactivity/directive-context.spec.ts b/test/e2e/specs/interactivity/directive-context.spec.ts index 3a566e7c2d9619..85341774c2af4e 100644 --- a/test/e2e/specs/interactivity/directive-context.spec.ts +++ b/test/e2e/specs/interactivity/directive-context.spec.ts @@ -313,4 +313,27 @@ test.describe( 'data-wp-context', () => { await select2.click(); await expect( selected ).toHaveText( 'Text 2' ); } ); + + test( 'should not subscribe to parent context props if those also exist in child', async ( { + page, + } ) => { + const counterParent = page.getByTestId( 'counter parent' ); + const counterChild = page.getByTestId( 'counter child' ); + const changes = page.getByTestId( 'counter changes' ); + + await expect( counterParent ).toHaveText( '0' ); + await expect( counterChild ).toHaveText( '0' ); + // The first render counts, so the changes counter starts at 1. + await expect( changes ).toHaveText( '1' ); + + await counterParent.click(); + await expect( counterParent ).toHaveText( '1' ); + await expect( counterChild ).toHaveText( '0' ); + await expect( changes ).toHaveText( '1' ); + + await counterChild.click(); + await expect( counterParent ).toHaveText( '1' ); + await expect( counterChild ).toHaveText( '1' ); + await expect( changes ).toHaveText( '2' ); + } ); } ); diff --git a/test/e2e/specs/site-editor/new-templates-list.spec.js b/test/e2e/specs/site-editor/new-templates-list.spec.js index a0dd0ccb903c2f..f0a4a579fc1861 100644 --- a/test/e2e/specs/site-editor/new-templates-list.spec.js +++ b/test/e2e/specs/site-editor/new-templates-list.spec.js @@ -7,15 +7,14 @@ test.describe( 'Templates', () => { test.beforeAll( async ( { requestUtils } ) => { await Promise.all( [ requestUtils.activateTheme( 'emptytheme' ), - requestUtils.setGutenbergExperiments( [ 'gutenberg-dataviews' ] ), + requestUtils.deleteAllTemplates( 'wp_template' ), ] ); } ); test.afterAll( async ( { requestUtils } ) => { - await Promise.all( [ - requestUtils.activateTheme( 'twentytwentyone' ), - requestUtils.deleteAllTemplates( 'wp_template' ), - requestUtils.setGutenbergExperiments( [] ), - ] ); + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllTemplates( 'wp_template' ); } ); test( 'Sorting', async ( { admin, page } ) => { await admin.visitSiteEditor( { path: '/wp_template/all' } ); diff --git a/test/e2e/specs/site-editor/patterns.spec.js b/test/e2e/specs/site-editor/patterns.spec.js index 6b2561d1f5bd95..97d8c0e8fcd252 100644 --- a/test/e2e/specs/site-editor/patterns.spec.js +++ b/test/e2e/specs/site-editor/patterns.spec.js @@ -13,9 +13,7 @@ const test = base.extend( { }, } ); -// Skip these tests for now as we plan to adapt them to -// the new patterns UI. -test.describe.skip( 'Patterns', () => { +test.describe( 'Patterns', () => { test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); await requestUtils.deleteAllBlocks(); @@ -35,19 +33,14 @@ test.describe.skip( 'Patterns', () => { admin, patterns, } ) => { - await admin.visitSiteEditor(); - - await patterns.navigation - .getByRole( 'button', { name: 'Patterns' } ) - .click(); - + await admin.visitSiteEditor( { path: '/patterns' } ); await expect( patterns.navigation.getByRole( 'heading', { name: 'Patterns', level: 1, } ) ).toBeVisible(); - await expect( patterns.content ).toContainText( 'No patterns found.' ); + await expect( patterns.content ).toContainText( 'No results' ); await patterns.navigation .getByRole( 'button', { name: 'Create pattern' } ) @@ -101,7 +94,6 @@ test.describe.skip( 'Patterns', () => { await patterns.navigation .getByRole( 'button', { name: 'Back' } ) .click(); - // TODO: await expect( page ).toHaveTitle( /^Patterns/ ); await expect( patterns.navigation.getByRole( 'button', { @@ -125,11 +117,11 @@ test.describe.skip( 'Patterns', () => { level: 2, } ) ).toBeVisible(); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 1 ); + await expect( patterns.item ).toHaveCount( 1 ); await expect( - patterns.list - .getByRole( 'heading', { name: 'My pattern' } ) - .getByRole( 'button', { name: 'My pattern', exact: true } ) + patterns.itemsList.getByText( 'My pattern', { + exact: true, + } ) ).toBeVisible(); } ); @@ -137,6 +129,7 @@ test.describe.skip( 'Patterns', () => { admin, requestUtils, patterns, + page, } ) => { await Promise.all( [ requestUtils.createBlock( { @@ -163,76 +156,46 @@ test.describe.skip( 'Patterns', () => { await admin.visitSiteEditor( { path: '/patterns' } ); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 3 ); - - await patterns.content - .getByRole( 'searchbox', { name: 'Search patterns' } ) - .fill( 'footer' ); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 2 ); + await expect( patterns.item ).toHaveCount( 3 ); + const searchBox = patterns.content.getByRole( 'searchbox', { + name: 'Search', + } ); + await searchBox.fill( 'footer' ); + await expect( patterns.item ).toHaveCount( 2 ); expect( - await patterns.list - .getByRole( 'listitem' ) - .getByRole( 'heading' ) - .allInnerTexts() + await patterns.item.getByRole( 'button' ).allInnerTexts() ).toEqual( expect.arrayContaining( [ 'Unsynced footer', 'Synced footer' ] ) ); - const searchBox = patterns.content.getByRole( 'searchbox', { - name: 'Search patterns', - } ); - await searchBox.fill( 'no match' ); - await expect( patterns.content ).toContainText( 'No patterns found.' ); + await expect( patterns.content ).toContainText( 'No results' ); await patterns.content - .getByRole( 'button', { name: 'Reset search' } ) + .getByRole( 'button', { name: 'Reset filters' } ) .click(); await expect( searchBox ).toHaveValue( '' ); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 3 ); - - const syncFilter = patterns.content.getByRole( 'radiogroup', { - name: 'Filter by sync status', - } ); - await expect( - syncFilter.getByRole( 'radio', { name: 'All' } ) - ).toBeChecked(); + await expect( patterns.item ).toHaveCount( 3 ); - await syncFilter - .getByRole( 'radio', { name: 'Synced', exact: true } ) + await patterns.content + .getByRole( 'button', { name: 'Sync Status' } ) .click(); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 1 ); - await expect( patterns.list.getByRole( 'listitem' ) ).toContainText( - 'Synced footer' - ); + await page.getByRole( 'option', { name: /^Synced/ } ).click(); + + await expect( patterns.item ).toHaveCount( 1 ); + await expect( patterns.item ).toContainText( 'Synced footer' ); - await syncFilter.getByRole( 'radio', { name: 'Not synced' } ).click(); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 2 ); + await page.getByRole( 'option', { name: /^Not synced/ } ).click(); + await expect( patterns.item ).toHaveCount( 2 ); expect( - await patterns.list - .getByRole( 'listitem' ) - .getByRole( 'heading' ) - .allInnerTexts() + await patterns.item.getByRole( 'button' ).allInnerTexts() ).toEqual( expect.arrayContaining( [ 'Unsynced header', 'Unsynced footer' ] ) ); await searchBox.fill( 'footer' ); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 1 ); - await expect( patterns.list.getByRole( 'listitem' ) ).toContainText( - 'Unsynced footer' - ); - - await syncFilter.getByRole( 'radio', { name: 'All' } ).click(); - await expect( patterns.list.getByRole( 'listitem' ) ).toHaveCount( 2 ); - expect( - await patterns.list - .getByRole( 'listitem' ) - .getByRole( 'heading' ) - .allInnerTexts() - ).toEqual( - expect.arrayContaining( [ 'Unsynced footer', 'Synced footer' ] ) - ); + await expect( patterns.item ).toHaveCount( 1 ); + await expect( patterns.item ).toContainText( 'Unsynced footer' ); } ); } ); @@ -249,6 +212,7 @@ class Patterns { this.navigation = this.#page.getByRole( 'region', { name: 'Navigation', } ); - this.list = this.content.getByRole( 'list' ); + this.itemsList = this.content.locator( '.dataviews-view-grid' ); + this.item = this.itemsList.locator( '.dataviews-view-grid__card' ); } } diff --git a/test/e2e/specs/site-editor/style-book.spec.js b/test/e2e/specs/site-editor/style-book.spec.js index 08f5e6463ebc7f..a832e06f6a6391 100644 --- a/test/e2e/specs/site-editor/style-book.spec.js +++ b/test/e2e/specs/site-editor/style-book.spec.js @@ -155,6 +155,35 @@ test.describe( 'Style Book', () => { 'should close when Escape key is pressed' ).toBeHidden(); } ); + + test( 'should persist when navigating the global styles sidebar', async ( { + page, + } ) => { + await page + .getByRole( 'region', { name: 'Editor settings' } ) + .getByRole( 'button', { name: 'Browse styles' } ) + .click(); + + const styleBookRegion = page.getByRole( 'region', { + name: 'Style Book', + } ); + await expect( + styleBookRegion, + 'style book should be visible' + ).toBeVisible(); + + await page.click( 'role=button[name="Navigate to the previous view"]' ); + + await page + .getByRole( 'region', { name: 'Editor settings' } ) + .getByRole( 'button', { name: 'Typography' } ) + .click(); + + await expect( + styleBookRegion, + 'style book should be visible' + ).toBeVisible(); + } ); } ); class StyleBook { diff --git a/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js b/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js index 9f5c9c8e36b221..b4848fe9401c4b 100644 --- a/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js +++ b/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js @@ -192,6 +192,38 @@ test.describe( 'Style Revisions', () => { ).toBeHidden(); } ); + test( 'should close revisions panel and leave style book open if activated', async ( { + page, + editor, + userGlobalStylesRevisions, + } ) => { + await editor.canvas.locator( 'body' ).click(); + await userGlobalStylesRevisions.openStylesPanel(); + const revisionsButton = page.getByRole( 'button', { + name: 'Revisions', + } ); + const styleBookButton = page.getByRole( 'button', { + name: 'Style Book', + } ); + await revisionsButton.click(); + await styleBookButton.click(); + + await expect( + page.getByLabel( 'Global styles revisions list' ) + ).toBeVisible(); + + await page.click( 'role=button[name="Navigate to the previous view"]' ); + + await expect( + page.getByLabel( 'Global styles revisions list' ) + ).toBeHidden(); + + // The site editor canvas has been restored. + await expect( + page.locator( 'iframe[name="style-book-canvas"]' ) + ).toBeVisible(); + } ); + test( 'should paginate', async ( { page, editor,