From 2fae2bd0f727af7d7668e4f4f1a0856dbca3a2f5 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 4 Jan 2024 13:22:30 +0400 Subject: [PATCH 1/2] Migrate 'scheduling' e2e tests to Playwright --- .../specs/editor/various/scheduling.spec.js | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test/e2e/specs/editor/various/scheduling.spec.js diff --git a/test/e2e/specs/editor/various/scheduling.spec.js b/test/e2e/specs/editor/various/scheduling.spec.js new file mode 100644 index 00000000000000..1fa41a79ea7ccc --- /dev/null +++ b/test/e2e/specs/editor/various/scheduling.spec.js @@ -0,0 +1,90 @@ +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +// The `timezone` setting exposed via REST API only accepts `UTC` +// and timezone strings by location. +const TIMEZONES = [ 'Pacific/Honolulu', 'UTC', 'Australia/Sydney' ]; + +test.describe( 'Scheduling', () => { + TIMEZONES.forEach( ( timezone ) => { + test.describe( `Timezone ${ timezone }`, () => { + let orignalTimezone; + test.beforeAll( async ( { requestUtils } ) => { + orignalTimezone = ( await requestUtils.getSiteSettings() ) + .timezone; + + await requestUtils.updateSiteSettings( { timezone } ); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.updateSiteSettings( { + timezone: orignalTimezone, + } ); + } ); + + test( 'Should change publishing button text from "Publish" to "Schedule"', async ( { + admin, + editor, + page, + } ) => { + await admin.createNewPost(); + await editor.openDocumentSettingsSidebar(); + + const topBar = page.getByRole( 'region', { + name: 'Editor top bar', + } ); + + await expect( + topBar.getByRole( 'button', { name: 'Publish' } ) + ).toBeVisible(); + + // Open the datepicker. + await page + .getByRole( 'button', { name: 'Change date' } ) + .click(); + + // Change the publishing date to a year in the future. + await page + .getByRole( 'group', { name: 'Date' } ) + .getByRole( 'spinbutton', { name: 'Year' } ) + .click(); + await page.keyboard.press( 'ArrowUp' ); + + // Close the datepicker. + await page.keyboard.press( 'Escape' ); + + await expect( + topBar.getByRole( 'button', { name: 'Schedule…' } ) + ).toBeVisible(); + } ); + } ); + } ); + + test( 'should keep date time UI focused when the previous and next month buttons are clicked', async ( { + admin, + editor, + page, + } ) => { + await admin.createNewPost(); + await editor.openDocumentSettingsSidebar(); + await page.getByRole( 'button', { name: 'Change date' } ).click(); + + const calendar = page.getByRole( 'application', { name: 'Calendar' } ); + const prevMonth = calendar.getByRole( 'button', { + name: 'View previous month', + } ); + const nextMonth = calendar.getByRole( 'button', { + name: 'View next month', + } ); + + await prevMonth.click(); + await expect( prevMonth ).toBeFocused(); + await expect( calendar ).toBeVisible(); + + await nextMonth.click(); + await expect( nextMonth ).toBeFocused(); + await expect( calendar ).toBeVisible(); + } ); +} ); From 46a6e465104bf5e41c2610400c4c8cc7396042ab Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 4 Jan 2024 13:22:56 +0400 Subject: [PATCH 2/2] Remove old test file --- .../specs/editor/various/scheduling.test.js | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/various/scheduling.test.js diff --git a/packages/e2e-tests/specs/editor/various/scheduling.test.js b/packages/e2e-tests/specs/editor/various/scheduling.test.js deleted file mode 100644 index df75dcb92f2820..00000000000000 --- a/packages/e2e-tests/specs/editor/various/scheduling.test.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * WordPress dependencies - */ -import { createNewPost, changeSiteTimezone } from '@wordpress/e2e-test-utils'; - -async function getPublishButtonText() { - return page.$eval( - '.editor-post-publish-button__button', - ( element ) => element.textContent - ); -} - -describe( 'Scheduling', () => { - const isDateTimeComponentFocused = () => { - return page.evaluate( () => { - const dateTimeElement = document.querySelector( - '.components-datetime__date' - ); - if ( ! dateTimeElement || ! document.activeElement ) { - return false; - } - return dateTimeElement.contains( document.activeElement ); - } ); - }; - - describe.each( [ [ 'UTC-10' ], [ 'UTC' ], [ 'UTC+10' ] ] )( - `Timezone %s`, - ( timezone ) => { - let oldTimezone; - beforeEach( async () => { - oldTimezone = await changeSiteTimezone( timezone ); - await createNewPost(); - } ); - afterEach( async () => { - await changeSiteTimezone( oldTimezone ); - } ); - - it( `should change publishing button text from "Publish" to "Schedule"`, async () => { - expect( await getPublishButtonText() ).toBe( 'Publish' ); - - // Open the datepicker. - await page.click( '*[aria-label^="Change date"]' ); - - // 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( '.editor-post-schedule__dialog-toggle' ); - - expect( await getPublishButtonText() ).toBe( 'Schedule…' ); - } ); - } - ); - - it( 'Should keep date time UI focused when the previous and next month buttons are clicked', async () => { - await createNewPost(); - - await page.click( '*[aria-label^="Change date"]' ); - await page.click( '*[aria-label="View previous month"]' ); - expect( await isDateTimeComponentFocused() ).toBe( true ); - await page.click( '*[aria-label="View next month"]' ); - expect( await isDateTimeComponentFocused() ).toBe( true ); - } ); -} );