Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/editor/src/components/post-schedule/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { dateI18n, getSettings } from '@wordpress/date';
import { dateI18n, getSettings, moment } from '@wordpress/date';
import { withSelect } from '@wordpress/data';

function PostScheduleLabel( { date } ) {
const settings = getSettings();
return date ?
dateI18n( settings.formats.datetime, date ) :

// If the publishing datetime is after the current datetime, show the date
// the post is scheduled to go public.
// Otherwise we just display "Immediately".
return date && moment().isBefore( date ) ?
dateI18n( settings.formats.datetimeAbbreviated, date ) :
__( 'Immediately' );
}

Expand Down
59 changes: 59 additions & 0 deletions test/e2e/specs/datepicker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Internal dependencies
*/
import { newPost } from '../support/utils';

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

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

expect( publishingDate ).toEqual( 'Immediately' );
} );

it( 'should show the publishing date as "Immediately" if the date is in the past', async () => {
// Open the datepicker.
await page.click( '#edit-post-post-schedule__toggle' );

// Change the publishing date to a year in the past.
await page.click( '.components-datetime__time__form__container--year' );
await page.keyboard.press( 'ArrowDown' );

// Close the datepicker.
await page.click( '#edit-post-post-schedule__toggle' );

const publishingDate = await page.$eval(
'#edit-post-post-schedule__toggle',
( dateLabel ) => dateLabel.textContent
);

expect( publishingDate ).toEqual( 'Immediately' );
} );

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

// Change the publishing date to a year in the future.
await page.click( '.components-datetime__time__form__container--year' );
await page.keyboard.press( 'ArrowUp' );

// Close the datepicker.
await page.click( '#edit-post-post-schedule__toggle' );

const publishingDate = await page.$eval(
'#edit-post-post-schedule__toggle',
( dateLabel ) => dateLabel.textContent
);

expect( publishingDate ).not.toEqual( 'Immediately' );
// The expected date format will be "Sep 26, 2018 11:52 pm".
expect( publishingDate ).toMatch( /[A-Za-z]{3} \d{1,2}, \d{4} \d{1,2}:\d{2} [ap]m/ );
} );
} );