-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate 'datepicker' e2e tests to Playwright #57545
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
148 changes: 0 additions & 148 deletions
148
packages/e2e-tests/specs/editor/various/datepicker.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
// Set browser to a timezone that's different to `timezone`. | ||
test.use( { | ||
timezoneId: 'America/New_York', | ||
} ); | ||
|
||
// The `timezone` setting exposed via REST API only accepts `UTC` | ||
// and timezone strings by location. | ||
const TIMEZONES = [ 'Pacific/Honolulu', 'UTC', 'Australia/Sydney' ]; | ||
|
||
TIMEZONES.forEach( ( timezone ) => { | ||
test.describe( `Datepicker: ${ timezone }`, () => { | ||
let orignalTimezone; | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
orignalTimezone = ( await requestUtils.getSiteSettings() ).timezone; | ||
await requestUtils.updateSiteSettings( { timezone } ); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin, editor } ) => { | ||
await admin.createNewPost(); | ||
await editor.openDocumentSettingsSidebar(); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.updateSiteSettings( { | ||
timezone: orignalTimezone, | ||
} ); | ||
} ); | ||
|
||
test( 'should show the publishing date as "Immediately" if the date is not altered', async ( { | ||
page, | ||
} ) => { | ||
await expect( | ||
page.getByRole( 'button', { name: 'Change date' } ) | ||
).toHaveText( 'Immediately' ); | ||
} ); | ||
|
||
test( 'should show the publishing date if the date is in the past', async ( { | ||
page, | ||
} ) => { | ||
const datepicker = page.getByRole( 'button', { | ||
name: 'Change date', | ||
} ); | ||
await datepicker.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( 'ArrowDown' ); | ||
await page.keyboard.press( 'Escape' ); | ||
|
||
// The expected date format will be "Sep 26, 2018 11:52 pm". | ||
await expect( | ||
page.getByRole( 'button', { name: 'Change date' } ) | ||
).toContainText( /^[A-Za-z]+\s\d{1,2},\s\d{1,4}/ ); | ||
} ); | ||
|
||
test( 'should show the publishing date if the date is in the future', async ( { | ||
page, | ||
} ) => { | ||
const datepicker = page.getByRole( 'button', { | ||
name: 'Change date', | ||
} ); | ||
await datepicker.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' ); | ||
await page.keyboard.press( 'Escape' ); | ||
|
||
// The expected date format will be "Sep 26, 2018 11:52 pm". | ||
await expect( | ||
page.getByRole( 'button', { name: 'Change date' } ) | ||
).toContainText( /^[A-Za-z]+\s\d{1,2},\s\d{1,4}/ ); | ||
} ); | ||
|
||
test( 'should show the publishing date as "Immediately" if the date is cleared', async ( { | ||
page, | ||
} ) => { | ||
const datepicker = page.getByRole( 'button', { | ||
name: 'Change date', | ||
} ); | ||
await datepicker.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' ); | ||
await page.keyboard.press( 'Escape' ); | ||
|
||
// Clear the date. | ||
await datepicker.click(); | ||
await page | ||
.getByLabel( 'Change publish date' ) | ||
.getByRole( 'button', { name: 'Now' } ) | ||
.click(); | ||
|
||
await expect( | ||
page.getByRole( 'button', { name: 'Change date' } ) | ||
).toHaveText( 'Immediately' ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevin940726, @WunderBart, what do you think about this assertion? Would it suffice? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be easier to just parse the date 😆. Something like...
We can keep the regex to test the format once if we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example; I'll try it out later.
P.S. My understanding of this test is that they just assert that the date label switches from
Immediately
to an actual date. In my opinion, it shouldn't really matter if the date string matches.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried the suggested path, but
Date
fails to parse the string returned by a locator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Judged from the test case, I think it's also asserting that the date in the datepicker is the same as the one shown on the button. Not sure if it matters though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe unit tests cover exact date assertions for the
date-time
components. Doing something similar usually ends up in ugly e2e test code 😅Should we land the current migration version or try to make date assertions happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's already covered by unit tests then absolutely! TBH, I think all of these cases can be tested in unit/integration tests 😆. I was just being conservative 😅.