Skip to content

Commit

Permalink
Split "Status & visibility" into multiple panels.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Jul 29, 2020
1 parent 02a24e9 commit 78a47fa
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 160 deletions.
8 changes: 8 additions & 0 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ Opens the global block inserter.

Opens the publish panel.

<a name="openSidebarPanel" href="#openSidebarPanel">#</a> **openSidebarPanel**

Opens a sidebar panel with the provided title.

_Parameters_

- _panelTitle_ `string`: The name of sidebar panel.

<a name="pressKeyTimes" href="#pressKeyTimes">#</a> **pressKeyTimes**

Presses the given keyboard key a number of times in sequence.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
21 changes: 21 additions & 0 deletions packages/e2e-test-utils/src/open-sidebar-panel.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
67 changes: 41 additions & 26 deletions packages/e2e-tests/specs/editor/various/datepicker.test.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,103 @@
/**
* WordPress dependencies
*/
import { createNewPost } from '@wordpress/e2e-test-utils';
import {
createNewPost,
findSidebarPanelToggleButtonWithTitle,
} from '@wordpress/e2e-test-utils';

describe( 'Datepicker', () => {
beforeEach( async () => {
await createNewPost();
} );

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' );
} );
} );
3 changes: 3 additions & 0 deletions packages/e2e-tests/specs/editor/various/new-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
openSidebarPanel,
} from '@wordpress/e2e-test-utils';

describe( 'new editor state', () => {
Expand Down Expand Up @@ -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();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
setBrowserViewport,
createNewPost,
openDocumentSettingsSidebar,
openSidebarPanel,
} from '@wordpress/e2e-test-utils';

describe( 'Post visibility', () => {
Expand All @@ -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"]'
Expand All @@ -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."]'
);
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/specs/editor/various/scheduling.test.js
Original file line number Diff line number Diff line change
@@ -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 );
Expand All @@ -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."]'
);
Expand Down
33 changes: 26 additions & 7 deletions packages/e2e-tests/specs/editor/various/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
* WordPress dependencies
*/
import {
activatePlugin,
clearLocalStorage,
createNewPost,
deactivatePlugin,
findSidebarPanelWithTitle,
enableFocusLossObservation,
disableFocusLossObservation,
Expand Down Expand Up @@ -120,33 +122,51 @@ 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(
await findSidebarPanelWithTitle( 'Featured image' )
).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();
Expand All @@ -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' );
} );
} );
41 changes: 35 additions & 6 deletions packages/edit-post/src/components/sidebar/post-format/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<PostFormatCheck>
<PanelRow>
<PanelBody
initialOpen={ false }
opened={ isOpened }
onToggle={ () => {
toggleEditorPanelOpened( PANEL_NAME );
} }
title={ __( 'Post Format' ) }
>
<PostFormatForm />
</PanelRow>
</PanelBody>
</PostFormatCheck>
);
}

export default PostFormat;
Loading

0 comments on commit 78a47fa

Please sign in to comment.