-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comments Query Loop - Add e2e tests for the block (#39502)
* Initial commit * Updated tests with recommendations * Move test to experiment block folder and add insertions tests * Update setOption e2e to handle checkboxes * Update and restore page comments pagination settings * Add unit test for comments block pagination links issue * Prepare for e2e, refactor unit test * Initial e2e test, needs refactor * Added e2e tests and trash all comments function * Update documentation * Move create post to beforeEach * Add default_comments_page option * Simplify setOption * Stray 3rd argument * Typo in Changelog entry * Return previous value from setOption * Don't cast bools * Changelog entry about returning previous value * Add waiting for the selectors Co-authored-by: Bernie Reiter <ockham@raz.or.at>
- Loading branch information
1 parent
8c871f3
commit 7b28f7e
Showing
7 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
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,35 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { switchUserToAdmin } from './switch-user-to-admin'; | ||
import { switchUserToTest } from './switch-user-to-test'; | ||
import { visitAdminPage } from './visit-admin-page'; | ||
|
||
/** | ||
* Navigates to the comments listing screen and bulk-trashes any comments which exist. | ||
* | ||
* @return {Promise} Promise resolving once comments have been trashed. | ||
*/ | ||
export async function trashAllComments() { | ||
await switchUserToAdmin(); | ||
// Visit `/wp-admin/edit-comments.php` so we can see a list of comments and delete them. | ||
await visitAdminPage( 'edit-comments.php' ); | ||
|
||
// If this selector doesn't exist there are no comments for us to delete. | ||
const bulkSelector = await page.$( '#bulk-action-selector-top' ); | ||
if ( ! bulkSelector ) { | ||
return; | ||
} | ||
|
||
// Select all comments. | ||
await page.waitForSelector( '[id^=cb-select-all-]' ); | ||
await page.click( '[id^=cb-select-all-]' ); | ||
// Select the "bulk actions" > "trash" option. | ||
await page.select( '#bulk-action-selector-top', 'trash' ); | ||
// Submit the form to send all mine/pendings/approved/spam comments to the trash. | ||
await page.click( '#doaction' ); | ||
await page.waitForXPath( | ||
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]' | ||
); | ||
await switchUserToTest(); | ||
} |
93 changes: 93 additions & 0 deletions
93
packages/e2e-tests/specs/experiments/blocks/comments-query.test.js
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,93 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activateTheme, | ||
createNewPost, | ||
insertBlock, | ||
pressKeyTimes, | ||
publishPost, | ||
setOption, | ||
trashAllComments, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Comment Query Loop', () => { | ||
let previousPageComments, | ||
previousCommentsPerPage, | ||
previousDefaultCommentsPage; | ||
beforeAll( async () => { | ||
await activateTheme( 'emptytheme' ); | ||
previousPageComments = await setOption( 'page_comments', '1' ); | ||
previousCommentsPerPage = await setOption( 'comments_per_page', '1' ); | ||
previousDefaultCommentsPage = await setOption( | ||
'default_comments_page', | ||
'newest' | ||
); | ||
} ); | ||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
it( 'Pagination links are working as expected', async () => { | ||
// Insert the Query Comment Loop block. | ||
await insertBlock( 'Comments Query Loop' ); | ||
// Insert the Comment Loop form. | ||
await insertBlock( 'Post Comments Form' ); | ||
await publishPost(); | ||
// Visit the post that was just published. | ||
await page.click( | ||
'.post-publish-panel__postpublish-buttons .is-primary' | ||
); | ||
|
||
// TODO: We can extract this into a util once we find we need it elsewhere. | ||
// Create three comments for that post. | ||
for ( let i = 0; i < 3; i++ ) { | ||
await page.waitForSelector( 'textarea#comment' ); | ||
await page.click( 'textarea#comment' ); | ||
await page.type( | ||
`textarea#comment`, | ||
`This is an automated comment - ${ i }` | ||
); | ||
await pressKeyTimes( 'Tab', 1 ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.waitForNavigation(); | ||
} | ||
|
||
// We check that there is a previous comments page link. | ||
await page.waitForSelector( '.wp-block-comments-pagination-previous' ); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-previous' ) | ||
).not.toBeNull(); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-next' ) | ||
).toBeNull(); | ||
|
||
await page.click( '.wp-block-comments-pagination-previous' ); | ||
|
||
// We check that there are a previous and a next link. | ||
await page.waitForSelector( '.wp-block-comments-pagination-previous' ); | ||
await page.waitForSelector( '.wp-block-comments-pagination-next' ); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-previous' ) | ||
).not.toBeNull(); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-next' ) | ||
).not.toBeNull(); | ||
await page.click( '.wp-block-comments-pagination-previous' ); | ||
|
||
// We check that there is only have a next link | ||
await page.waitForSelector( '.wp-block-comments-pagination-next' ); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-previous' ) | ||
).toBeNull(); | ||
expect( | ||
await page.$( '.wp-block-comments-pagination-next' ) | ||
).not.toBeNull(); | ||
} ); | ||
afterAll( async () => { | ||
await trashAllComments(); | ||
await activateTheme( 'twentytwentyone' ); | ||
await setOption( 'page_comments', previousPageComments ); | ||
await setOption( 'comments_per_page', previousCommentsPerPage ); | ||
await setOption( 'default_comments_page', previousDefaultCommentsPage ); | ||
} ); | ||
} ); |
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