-
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
E2E Tests: Migrate Comments block test to Playwright #39826
Changes from all commits
d491305
f50241c
9086e5a
6bbb0fd
84408c4
c5acda4
cc4a80c
5ae3a4e
5622a82
27f8d22
321d4fb
7a6ab23
088c372
e041a2c
e6b4325
ca5cab1
a120459
f54440e
2a622f2
bc7b5ab
ffbcc07
0980b30
cef603a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Admin } from './'; | ||
|
||
export async function setOption( this: Admin, setting: string, value: string ) { | ||
await this.visitAdminPage( 'options.php', '' ); | ||
const previousValue = await this.page.inputValue( `#${ setting }` ); | ||
|
||
await this.page.fill( `#${ setting }`, value ); | ||
|
||
await this.page.click( '#Update' ); | ||
return previousValue; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,9 @@ export async function publishPost( this: Editor ) { | |
await this.page.click( | ||
'role=region[name="Editor publish"i] >> role=button[name="Publish"i]' | ||
); | ||
|
||
const urlString = await this.page.inputValue( 'text="Post address"' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally, we would prefer role selectors over text selectors if they're available. |
||
const url = new URL( urlString ); | ||
const postId = url.searchParams.get( 'p' ); | ||
return postId; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { RequestUtils } from './index'; | ||
|
||
export interface Comment { | ||
id: number; | ||
author: number; | ||
content: string; | ||
} | ||
|
||
/** | ||
* Create new comment using the REST API. | ||
* | ||
* @param {} this RequestUtils. | ||
* @param {} comment Comment. | ||
*/ | ||
export async function createComment( this: RequestUtils, comment: Comment ) { | ||
this.rest( { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing We should probably return the response of the API too to capture the created comment id. |
||
method: 'POST', | ||
path: '/wp/v2/comments', | ||
data: comment, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why couldn't we call |
||
} ); | ||
} | ||
|
||
/** | ||
* Delete all comments using the REST API. | ||
* | ||
* @param {} this RequestUtils. | ||
*/ | ||
export async function deleteAllComments( this: RequestUtils ) { | ||
// List all comments. | ||
// https://developer.wordpress.org/rest-api/reference/comments/#list-comments | ||
const comments = await this.rest( { | ||
path: '/wp/v2/comments', | ||
params: { | ||
per_page: 100, | ||
// All possible statuses. | ||
status: 'unapproved,approved,spam,trash', | ||
}, | ||
} ); | ||
|
||
// Delete all comments one by one. | ||
// https://developer.wordpress.org/rest-api/reference/comments/#delete-a-comment | ||
// "/wp/v2/comments" doesn't support batch requests yet. | ||
await Promise.all( | ||
comments.map( ( comment: Comment ) => | ||
this.rest( { | ||
method: 'DELETE', | ||
path: `/wp/v2/comments/${ comment.id }`, | ||
params: { | ||
force: true, | ||
}, | ||
} ) | ||
) | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { RequestUtils } from './index'; | ||
|
||
/** | ||
* Get current user | ||
* | ||
* @param {this} this Request utils. | ||
*/ | ||
export async function getCurrentUser( this: RequestUtils ) { | ||
const response = await this.rest( { | ||
path: '/wp/v2/users/me', | ||
method: 'GET', | ||
} ); | ||
|
||
return response; | ||
} |
This file was deleted.
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.
Personally, I wouldn't put this inside
e2e-test-utils-playwright
since it's just a temporary solution for one test suite. Breaking changes will be made once the REST options API is implemented.Instead, I would put this inside the
comments
test file to make it clear that it's an internal API.