diff --git a/packages/e2e-test-utils/README.md b/packages/e2e-test-utils/README.md
index 5a070a5bb6e52..b688265625368 100644
--- a/packages/e2e-test-utils/README.md
+++ b/packages/e2e-test-utils/README.md
@@ -391,6 +391,14 @@ Opens the global block inserter.
Opens the publish panel.
+# **openSidebarPanel**
+
+Opens a sidebar panel with the provided title.
+
+_Parameters_
+
+- _panelTitle_ `string`: The name of sidebar panel.
+
# **pressKeyTimes**
Presses the given keyboard key a number of times in sequence.
diff --git a/packages/e2e-test-utils/src/index.js b/packages/e2e-test-utils/src/index.js
index d1345d0e9163b..fae789fc950cd 100644
--- a/packages/e2e-test-utils/src/index.js
+++ b/packages/e2e-test-utils/src/index.js
@@ -44,6 +44,7 @@ export {
} from './observe-focus-loss';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
export { openPublishPanel } from './open-publish-panel';
+export { openSidebarPanel } from './open-sidebar-panel';
export { trashAllPosts } from './posts';
export { pressKeyTimes } from './press-key-times';
export { pressKeyWithModifier } from './press-key-with-modifier';
diff --git a/packages/e2e-test-utils/src/open-sidebar-panel.js b/packages/e2e-test-utils/src/open-sidebar-panel.js
new file mode 100644
index 0000000000000..541b108d504d1
--- /dev/null
+++ b/packages/e2e-test-utils/src/open-sidebar-panel.js
@@ -0,0 +1,21 @@
+/**
+ * Internal dependencies
+ */
+import { findSidebarPanelToggleButtonWithTitle } from './find-sidebar-panel-toggle-button-with-title';
+
+/**
+ * Opens a sidebar panel with the provided title.
+ *
+ * @param {string} panelTitle The name of sidebar panel.
+ */
+export async function openSidebarPanel( panelTitle ) {
+ const panelToggle = await findSidebarPanelToggleButtonWithTitle(
+ panelTitle
+ );
+ const panelIsCollapsed = await panelToggle.evaluate(
+ ( node ) => node.getAttribute( 'aria-expanded' ) === 'false'
+ );
+ if ( panelIsCollapsed ) {
+ await panelToggle.click();
+ }
+}
diff --git a/packages/e2e-tests/specs/editor/various/datepicker.test.js b/packages/e2e-tests/specs/editor/various/datepicker.test.js
index 6118f05368ae7..129eeb9891274 100644
--- a/packages/e2e-tests/specs/editor/various/datepicker.test.js
+++ b/packages/e2e-tests/specs/editor/various/datepicker.test.js
@@ -1,7 +1,10 @@
/**
* WordPress dependencies
*/
-import { createNewPost } from '@wordpress/e2e-test-utils';
+import {
+ createNewPost,
+ findSidebarPanelToggleButtonWithTitle,
+} from '@wordpress/e2e-test-utils';
describe( 'Datepicker', () => {
beforeEach( async () => {
@@ -9,80 +12,92 @@ describe( 'Datepicker', () => {
} );
it( 'should show the publishing date as "Immediately" if the date is not altered', async () => {
- const publishingDate = await page.$eval(
- '.edit-post-post-schedule__toggle',
- ( dateLabel ) => dateLabel.textContent
+ const panelToggle = await findSidebarPanelToggleButtonWithTitle(
+ 'Publish:'
+ );
+ const publishDate = await panelToggle.$eval(
+ '.editor-post-publish-panel__link',
+ ( publishDateSpan ) => publishDateSpan.textContent
);
- expect( publishingDate ).toEqual( 'Immediately' );
+ expect( publishDate ).toEqual( 'Immediately' );
} );
it( 'should show the publishing date if the date is in the past', async () => {
// Open the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ const panelToggle = await findSidebarPanelToggleButtonWithTitle(
+ 'Publish:'
+ );
+ await panelToggle.click();
// Change the publishing date to a year in the past.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowDown' );
// Close the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ await panelToggle.click();
- const publishingDate = await page.$eval(
- '.edit-post-post-schedule__toggle',
- ( dateLabel ) => dateLabel.textContent
+ const publishDate = await panelToggle.$eval(
+ '.editor-post-publish-panel__link',
+ ( publishDateSpan ) => publishDateSpan.textContent
);
- expect( publishingDate ).toMatch(
+ expect( publishDate ).toMatch(
/[A-Za-z]{3} \d{1,2}, \d{4} \d{1,2}:\d{2} [ap]m/
);
} );
it( 'should show the publishing date if the date is in the future', async () => {
// Open the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ const panelToggle = await findSidebarPanelToggleButtonWithTitle(
+ 'Publish:'
+ );
+ await panelToggle.click();
// Change the publishing date to a year in the future.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowUp' );
// Close the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ await panelToggle.click();
- const publishingDate = await page.$eval(
- '.edit-post-post-schedule__toggle',
- ( dateLabel ) => dateLabel.textContent
+ const publishDate = await panelToggle.$eval(
+ '.editor-post-publish-panel__link',
+ ( publishDateSpan ) => publishDateSpan.textContent
);
- expect( publishingDate ).not.toEqual( 'Immediately' );
+ expect( publishDate ).not.toEqual( 'Immediately' );
// The expected date format will be "Sep 26, 2018 11:52 pm".
- expect( publishingDate ).toMatch(
+ expect( publishDate ).toMatch(
/[A-Za-z]{3} \d{1,2}, \d{4} \d{1,2}:\d{2} [ap]m/
);
} );
it( 'should show the publishing date as "Immediately" if the date is cleared', async () => {
// Open the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ const panelToggle = await findSidebarPanelToggleButtonWithTitle(
+ 'Publish:'
+ );
+ await panelToggle.click();
// Change the publishing date to a year in the future.
await page.click( '.components-datetime__time-field-year' );
await page.keyboard.press( 'ArrowUp' );
// Close the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ await panelToggle.click();
// Open the datepicker.
- await page.click( '.edit-post-post-schedule__toggle' );
+ await panelToggle.click();
- // Clear the date
+ // Clear the date.
await page.click( '.components-datetime__date-reset-button' );
- const publishingDate = await page.$eval(
- '.edit-post-post-schedule__toggle',
- ( dateLabel ) => dateLabel.textContent
+ const publishDate = await panelToggle.$eval(
+ '.editor-post-publish-panel__link',
+ ( publishDateSpan ) => publishDateSpan.textContent
);
- expect( publishingDate ).toEqual( 'Immediately' );
+ expect( publishDate ).toEqual( 'Immediately' );
} );
} );
diff --git a/packages/e2e-tests/specs/editor/various/new-post.test.js b/packages/e2e-tests/specs/editor/various/new-post.test.js
index 41db6ce7148b2..5c11971f6b51d 100644
--- a/packages/e2e-tests/specs/editor/various/new-post.test.js
+++ b/packages/e2e-tests/specs/editor/various/new-post.test.js
@@ -5,6 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
+ openSidebarPanel,
} from '@wordpress/e2e-test-utils';
describe( 'new editor state', () => {
@@ -34,6 +35,8 @@ describe( 'new editor state', () => {
);
expect( postPreviewButton ).not.toBeNull();
// Should display the Post Formats UI.
+ await openSidebarPanel( 'Post Format' );
+ await page.waitForSelector( '.editor-post-format' );
const postFormatsUi = await page.$( '.editor-post-format' );
expect( postFormatsUi ).not.toBeNull();
} );
diff --git a/packages/e2e-tests/specs/editor/various/post-visibility.test.js b/packages/e2e-tests/specs/editor/various/post-visibility.test.js
index 6844b9bd97345..2675629ce1d83 100644
--- a/packages/e2e-tests/specs/editor/various/post-visibility.test.js
+++ b/packages/e2e-tests/specs/editor/various/post-visibility.test.js
@@ -5,6 +5,7 @@ import {
setBrowserViewport,
createNewPost,
openDocumentSettingsSidebar,
+ openSidebarPanel,
} from '@wordpress/e2e-test-utils';
describe( 'Post visibility', () => {
@@ -19,7 +20,7 @@ describe( 'Post visibility', () => {
await openDocumentSettingsSidebar();
- await page.click( '.edit-post-post-visibility__toggle' );
+ await openSidebarPanel( 'Visibility:' );
const [ privateLabel ] = await page.$x(
'//label[text()="Private"]'
@@ -45,7 +46,7 @@ describe( 'Post visibility', () => {
await openDocumentSettingsSidebar();
// Set a publish date for the next month.
- await page.click( '.edit-post-post-schedule__toggle' );
+ await openSidebarPanel( 'Publish' );
await page.click(
'div[aria-label="Move forward to switch to the next month."]'
);
@@ -55,7 +56,7 @@ describe( 'Post visibility', () => {
)
)[ 0 ].click();
- await page.click( '.edit-post-post-visibility__toggle' );
+ await openSidebarPanel( 'Visibility:' );
const [ privateLabel ] = await page.$x( '//label[text()="Private"]' );
await privateLabel.click();
diff --git a/packages/e2e-tests/specs/editor/various/scheduling.test.js b/packages/e2e-tests/specs/editor/various/scheduling.test.js
index 7732f8d8a0e7c..36165ced76779 100644
--- a/packages/e2e-tests/specs/editor/various/scheduling.test.js
+++ b/packages/e2e-tests/specs/editor/various/scheduling.test.js
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
-import { createNewPost } from '@wordpress/e2e-test-utils';
+import { createNewPost, openSidebarPanel } from '@wordpress/e2e-test-utils';
describe( 'Scheduling', () => {
beforeEach( createNewPost );
@@ -19,7 +19,7 @@ describe( 'Scheduling', () => {
};
it( 'Should keep date time UI focused when the previous and next month buttons are clicked', async () => {
- await page.click( '.edit-post-post-schedule__toggle' );
+ await openSidebarPanel( 'Publish:' );
await page.click(
'div[aria-label="Move backward to switch to the previous month."]'
);
diff --git a/packages/e2e-tests/specs/editor/various/sidebar.test.js b/packages/e2e-tests/specs/editor/various/sidebar.test.js
index bc37aa3ec43a9..f8038023714af 100644
--- a/packages/e2e-tests/specs/editor/various/sidebar.test.js
+++ b/packages/e2e-tests/specs/editor/various/sidebar.test.js
@@ -2,8 +2,10 @@
* WordPress dependencies
*/
import {
+ activatePlugin,
clearLocalStorage,
createNewPost,
+ deactivatePlugin,
findSidebarPanelWithTitle,
enableFocusLossObservation,
disableFocusLossObservation,
@@ -120,11 +122,21 @@ describe( 'Sidebar', () => {
} );
it( 'should be possible to programmatically remove Document Settings panels', async () => {
+ await activatePlugin( 'gutenberg-test-plugin-post-formats-support' );
+
await createNewPost();
await enableFocusLossObservation();
await openDocumentSettingsSidebar();
+ expect( await findSidebarPanelWithTitle( 'General' ) ).toBeDefined();
+ expect(
+ await findSidebarPanelWithTitle( 'Visibility:' )
+ ).toBeDefined();
+ expect( await findSidebarPanelWithTitle( 'Publish:' ) ).toBeDefined();
+ expect(
+ await findSidebarPanelWithTitle( 'Post Format' )
+ ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Categories' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Tags' ) ).toBeDefined();
expect(
@@ -132,21 +144,29 @@ describe( 'Sidebar', () => {
).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Excerpt' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Discussion' ) ).toBeDefined();
- expect(
- await findSidebarPanelWithTitle( 'Status & visibility' )
- ).toBeDefined();
await page.evaluate( () => {
const { removeEditorPanel } = wp.data.dispatch( 'core/edit-post' );
+ removeEditorPanel( 'post-status' );
+ removeEditorPanel( 'visibility' );
+ removeEditorPanel( 'schedule' );
+ removeEditorPanel( 'post-format' );
removeEditorPanel( 'taxonomy-panel-category' );
removeEditorPanel( 'taxonomy-panel-post_tag' );
removeEditorPanel( 'featured-image' );
removeEditorPanel( 'post-excerpt' );
removeEditorPanel( 'discussion-panel' );
- removeEditorPanel( 'post-status' );
} );
+ expect( await findSidebarPanelWithTitle( 'General' ) ).toBeUndefined();
+ expect(
+ await findSidebarPanelWithTitle( 'Visibility:' )
+ ).toBeUndefined();
+ expect( await findSidebarPanelWithTitle( 'Publish:' ) ).toBeUndefined();
+ expect(
+ await findSidebarPanelWithTitle( 'Post Format' )
+ ).toBeUndefined();
expect(
await findSidebarPanelWithTitle( 'Categories' )
).toBeUndefined();
@@ -158,8 +178,7 @@ describe( 'Sidebar', () => {
expect(
await findSidebarPanelWithTitle( 'Discussion' )
).toBeUndefined();
- expect(
- await findSidebarPanelWithTitle( 'Status & visibility' )
- ).toBeUndefined();
+
+ await deactivatePlugin( 'gutenberg-test-plugin-post-formats-support' );
} );
} );
diff --git a/packages/edit-post/src/components/sidebar/post-format/index.js b/packages/edit-post/src/components/sidebar/post-format/index.js
index 67f8f690f7403..36ad9db250779 100644
--- a/packages/edit-post/src/components/sidebar/post-format/index.js
+++ b/packages/edit-post/src/components/sidebar/post-format/index.js
@@ -1,20 +1,49 @@
/**
* WordPress dependencies
*/
-import { PanelRow } from '@wordpress/components';
+import { PanelBody } from '@wordpress/components';
+import { useDispatch, useSelect } from '@wordpress/data';
import {
PostFormat as PostFormatForm,
PostFormatCheck,
} from '@wordpress/editor';
+import { __ } from '@wordpress/i18n';
+
+const PANEL_NAME = 'post-format';
+
+export default function PostFormat() {
+ const { isOpened, isRemoved } = useSelect( ( select ) => {
+ // We use isEditorPanelRemoved to hide the panel if it was
+ // programatically removed. We don't use isEditorPanelEnabled since
+ // this panel should not be disabled through the UI.
+ const { isEditorPanelRemoved, isEditorPanelOpened } = select(
+ 'core/edit-post'
+ );
+
+ return {
+ isOpened: isEditorPanelOpened( PANEL_NAME ),
+ isRemoved: isEditorPanelRemoved( PANEL_NAME ),
+ };
+ }, [] );
+
+ const { toggleEditorPanelOpened } = useDispatch( 'core/edit-post' );
+
+ if ( isRemoved ) {
+ return null;
+ }
-export function PostFormat() {
return (
+ { __( + 'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.' + ) } +
+ ) } + { suggestedFormat && (