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 24, 2020
1 parent 43fb27f commit e680392
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 160 deletions.
59 changes: 33 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,95 @@
/**
* WordPress dependencies
*/
import { createNewPost } from '@wordpress/e2e-test-utils';
import {
createNewPost,
findSidebarPanelWithTitle,
} 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 findSidebarPanelWithTitle( 'Publish:' );
const publishDateSpan = await panelToggle.$(
'.editor-post-publish-panel__link'
);
const publishDate = 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 findSidebarPanelWithTitle( '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 publishDateSpan = await panelToggle.$(
'.editor-post-publish-panel__link'
);
const publishDate = 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 findSidebarPanelWithTitle( '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 publishDateSpan = await panelToggle.$(
'.editor-post-publish-panel__link'
);
const publishDate = 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 findSidebarPanelWithTitle( '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 publishDateSpan = await panelToggle.$(
'.editor-post-publish-panel__link'
);
const publishDate = publishDateSpan.textContent;

expect( publishingDate ).toEqual( 'Immediately' );
expect( publishDate ).toEqual( 'Immediately' );
} );
} );
10 changes: 10 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,8 +5,16 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
findSidebarPanelWithTitle,
} from '@wordpress/e2e-test-utils';

async function openSidebarPanel( label ) {
const panelToggle = await findSidebarPanelWithTitle( label );
if ( ( await panelToggle.getProperty( 'aria-expanded' ) ) === false ) {
await panelToggle.click();
}
}

describe( 'new editor state', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-plugin-post-formats-support' );
Expand Down Expand Up @@ -34,6 +42,8 @@ describe( 'new editor state', () => {
);
expect( postPreviewButton ).not.toBeNull();
// Should display the Post Formats UI.
openSidebarPanel( 'Post Format' );
await page.waitForSelector( '.editor-post-format' );
const postFormatsUi = await page.$( '.editor-post-format' );
expect( postFormatsUi ).not.toBeNull();
} );
Expand Down
14 changes: 11 additions & 3 deletions packages/e2e-tests/specs/editor/various/post-visibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
import {
setBrowserViewport,
createNewPost,
findSidebarPanelWithTitle,
openDocumentSettingsSidebar,
} from '@wordpress/e2e-test-utils';

async function openSidebarPanel( label ) {
const panelToggle = await findSidebarPanelWithTitle( label );
if ( ( await panelToggle.getProperty( 'aria-expanded' ) ) === false ) {
await panelToggle.click();
}
}

describe( 'Post visibility', () => {
afterEach( async () => {
await setBrowserViewport( 'large' );
Expand All @@ -19,7 +27,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 +53,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 +63,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
8 changes: 6 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,10 @@
/**
* WordPress dependencies
*/
import { createNewPost } from '@wordpress/e2e-test-utils';
import {
createNewPost,
findSidebarPanelWithTitle,
} from '@wordpress/e2e-test-utils';

describe( 'Scheduling', () => {
beforeEach( createNewPost );
Expand All @@ -19,7 +22,8 @@ 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' );
const panelToggle = await findSidebarPanelWithTitle( 'Publish:' );
await panelToggle.click();
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 e680392

Please sign in to comment.