Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix datepicker e2e tests
  • Loading branch information
noisysocks committed Jun 16, 2022
commit 3ec6ac34f5b5e512f9a5ec2df61adc54380963d3
20 changes: 9 additions & 11 deletions packages/e2e-tests/specs/editor/various/datepicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ function trimLeadingZero( str ) {
return str[ 0 ] === '0' ? str.slice( 1 ) : str;
}

function formatDatePickerValues( {
year,
monthLabel,
day,
hours,
minutes,
amOrPm,
} ) {
function formatDatePickerValues(
{ year, monthLabel, day, hours, minutes, amOrPm },
timezone
) {
const dayTrimmed = trimLeadingZero( day );
const hoursTrimmed = trimLeadingZero( hours );
return `${ monthLabel } ${ dayTrimmed }, ${ year } ${ hoursTrimmed }:${ minutes } ${ amOrPm }`;
return `${ monthLabel } ${ dayTrimmed }, ${ year } ${ hoursTrimmed }:${ minutes } ${ amOrPm } ${ timezone }`;
}

async function getPublishingDate() {
Expand All @@ -70,11 +66,13 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(
( timezone ) => {
let oldTimezone;
beforeEach( async () => {
await page.emulateTimezone( 'America/New_York' ); // Set browser to a timezone that's different to `timezone`.
oldTimezone = await changeSiteTimezone( timezone );
await createNewPost();
} );
afterEach( async () => {
await changeSiteTimezone( oldTimezone );
await page.emulateTimezone( null );
} );

it( 'should show the publishing date as "Immediately" if the date is not altered', async () => {
Expand All @@ -98,7 +96,7 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(
const publishingDate = await getPublishingDate();

expect( publishingDate ).toBe(
formatDatePickerValues( datePickerValues )
formatDatePickerValues( datePickerValues, timezone )
);
} );

Expand All @@ -119,7 +117,7 @@ describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )(
expect( publishingDate ).not.toEqual( 'Immediately' );
// The expected date format will be "Sep 26, 2018 11:52 pm".
expect( publishingDate ).toBe(
formatDatePickerValues( datePickerValues )
formatDatePickerValues( datePickerValues, timezone )
);
} );

Expand Down