From d491305569da1749a1fda7ade821400e8c5b65e4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 13 Apr 2022 19:31:52 +0200 Subject: [PATCH 01/23] E2E Tests: Migrate Comments Query Loop test to Playwright --- .../src/request-utils/comments.js | 32 +++++++++++++++++ .../src/request-utils/index.ts | 2 ++ .../specs/site-editor/blocks/comments.spec.js | 35 ++++++++++++------- 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 packages/e2e-test-utils-playwright/src/request-utils/comments.js rename packages/e2e-tests/specs/editor/blocks/comments.test.js => test/e2e/specs/site-editor/blocks/comments.spec.js (80%) diff --git a/packages/e2e-test-utils-playwright/src/request-utils/comments.js b/packages/e2e-test-utils-playwright/src/request-utils/comments.js new file mode 100644 index 00000000000000..a942484df3a75c --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/request-utils/comments.js @@ -0,0 +1,32 @@ +/** + * Delete all comments using the REST API. + * + * @this {import('./index').RequestUtils} + */ +export async function deleteAllComments() { + // 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 ) => + this.rest( { + method: 'DELETE', + path: `/wp/v2/comments/${ comment.id }`, + params: { + force: true, + }, + } ) + ) + ); +} diff --git a/packages/e2e-test-utils-playwright/src/request-utils/index.ts b/packages/e2e-test-utils-playwright/src/request-utils/index.ts index 151013a8fe000c..63d99b29854c12 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/index.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/index.ts @@ -18,6 +18,7 @@ import { getPluginsMap, activatePlugin, deactivatePlugin } from './plugins'; import { deleteAllTemplates } from './templates'; import { activateTheme } from './themes'; import { deleteAllBlocks } from './blocks'; +import { deleteAllComments } from './comments'; import { deleteAllPosts } from './posts'; import { resetPreferences } from './preferences'; import { deleteAllWidgets, addWidgetBlock } from './widgets'; @@ -121,6 +122,7 @@ class RequestUtils { activateTheme = activateTheme.bind( this ); deleteAllBlocks = deleteAllBlocks; deleteAllPosts = deleteAllPosts.bind( this ); + deleteAllComments = deleteAllComments.bind( this ); deleteAllWidgets = deleteAllWidgets.bind( this ); addWidgetBlock = addWidgetBlock.bind( this ); deleteAllTemplates = deleteAllTemplates.bind( this ); diff --git a/packages/e2e-tests/specs/editor/blocks/comments.test.js b/test/e2e/specs/site-editor/blocks/comments.spec.js similarity index 80% rename from packages/e2e-tests/specs/editor/blocks/comments.test.js rename to test/e2e/specs/site-editor/blocks/comments.spec.js index e68d23f34fb7df..e9836881a0c87b 100644 --- a/packages/e2e-tests/specs/editor/blocks/comments.test.js +++ b/test/e2e/specs/site-editor/blocks/comments.spec.js @@ -1,22 +1,26 @@ /** * WordPress dependencies */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); import { - activateTheme, createNewPost, insertBlock, pressKeyTimes, publishPost, setOption, - trashAllComments, } from '@wordpress/e2e-test-utils'; -describe( 'Comments', () => { +/** + * @typedef {import('@playwright/test').Page} Page + * @typedef {import('@wordpress/e2e-test-utils-playwright').RequestUtils} RequestUtils + */ + +test.describe( 'Comments', () => { let previousPageComments, previousCommentsPerPage, previousDefaultCommentsPage; - beforeAll( async () => { - await activateTheme( 'emptytheme' ); + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'emptytheme' ); previousPageComments = await setOption( 'page_comments', '1' ); previousCommentsPerPage = await setOption( 'comments_per_page', '1' ); previousDefaultCommentsPage = await setOption( @@ -24,13 +28,18 @@ describe( 'Comments', () => { 'newest' ); } ); - it( 'We show no results message if there are no comments', async () => { - await trashAllComments(); + + test( 'We show no results message if there are no comments', async ( { + page, + requestUtils, + } ) => { + await requestUtils.deleteAllComments(); await createNewPost(); await insertBlock( 'Comments' ); await page.waitForXPath( '//p[contains(text(), "No results found.")]' ); } ); - it( 'Pagination links are working as expected', async () => { + + test( 'Pagination links are working as expected', async ( { page } ) => { await createNewPost(); await insertBlock( 'Comments' ); await publishPost(); @@ -89,7 +98,9 @@ describe( 'Comments', () => { await page.$( '.wp-block-comments-pagination-next' ) ).not.toBeNull(); } ); - it( 'Pagination links are not appearing if break comments is not enabled', async () => { + test( 'Pagination links are not appearing if break comments is not enabled', async ( { + page, + } ) => { await setOption( 'page_comments', '0' ); await createNewPost(); await insertBlock( 'Comments' ); @@ -121,9 +132,9 @@ describe( 'Comments', () => { await page.$( '.wp-block-comments-pagination-next' ) ).toBeNull(); } ); - afterAll( async () => { - await trashAllComments(); - await activateTheme( 'twentytwentyone' ); + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllComments(); + await requestUtils.activateTheme( 'twentytwentyone' ); await setOption( 'page_comments', previousPageComments ); await setOption( 'comments_per_page', previousCommentsPerPage ); await setOption( 'default_comments_page', previousDefaultCommentsPage ); From f50241ce78513a97e5d39e1c8cdb1d5347e69a21 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:03:00 +0200 Subject: [PATCH 02/23] Move to correct destination folder --- test/e2e/specs/{site-editor => editor}/blocks/comments.spec.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/e2e/specs/{site-editor => editor}/blocks/comments.spec.js (100%) diff --git a/test/e2e/specs/site-editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js similarity index 100% rename from test/e2e/specs/site-editor/blocks/comments.spec.js rename to test/e2e/specs/editor/blocks/comments.spec.js From 9086e5a248df4c880ec7316cdd62a09e833467f9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:09:43 +0200 Subject: [PATCH 03/23] Type comments e2e util --- .../request-utils/{comments.js => comments.ts} | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) rename packages/e2e-test-utils-playwright/src/request-utils/{comments.js => comments.ts} (72%) diff --git a/packages/e2e-test-utils-playwright/src/request-utils/comments.js b/packages/e2e-test-utils-playwright/src/request-utils/comments.ts similarity index 72% rename from packages/e2e-test-utils-playwright/src/request-utils/comments.js rename to packages/e2e-test-utils-playwright/src/request-utils/comments.ts index a942484df3a75c..b9da230b3b0edb 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/comments.js +++ b/packages/e2e-test-utils-playwright/src/request-utils/comments.ts @@ -1,9 +1,18 @@ +/** + * Internal dependencies + */ +import type { RequestUtils } from './index'; + +interface Comment { + id: number; +} + /** * Delete all comments using the REST API. * - * @this {import('./index').RequestUtils} + * @param {} this RequestUtils. */ -export async function deleteAllComments() { +export async function deleteAllComments( this: RequestUtils ) { // List all comments. // https://developer.wordpress.org/rest-api/reference/comments/#list-comments const comments = await this.rest( { @@ -19,7 +28,7 @@ export async function deleteAllComments() { // 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 ) => + comments.map( ( comment: Comment ) => this.rest( { method: 'DELETE', path: `/wp/v2/comments/${ comment.id }`, From 6bbb0fd9a8ae7e6253f549e4a6254e684fa0082c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:18:34 +0200 Subject: [PATCH 04/23] Migrate createNewPost and insertBlock --- test/e2e/specs/editor/blocks/comments.spec.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index e9836881a0c87b..066c6527931dd0 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -3,8 +3,6 @@ */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); import { - createNewPost, - insertBlock, pressKeyTimes, publishPost, setOption, @@ -30,18 +28,24 @@ test.describe( 'Comments', () => { } ); test( 'We show no results message if there are no comments', async ( { + admin, + editor, page, requestUtils, } ) => { await requestUtils.deleteAllComments(); - await createNewPost(); - await insertBlock( 'Comments' ); + await admin.createNewPost(); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await page.waitForXPath( '//p[contains(text(), "No results found.")]' ); } ); - test( 'Pagination links are working as expected', async ( { page } ) => { - await createNewPost(); - await insertBlock( 'Comments' ); + test( 'Pagination links are working as expected', async ( { + admin, + editor, + page, + } ) => { + await admin.createNewPost(); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await publishPost(); // Visit the post that was just published. await page.click( @@ -99,11 +103,13 @@ test.describe( 'Comments', () => { ).not.toBeNull(); } ); test( 'Pagination links are not appearing if break comments is not enabled', async ( { + admin, + editor, page, } ) => { await setOption( 'page_comments', '0' ); - await createNewPost(); - await insertBlock( 'Comments' ); + await admin.createNewPost(); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await publishPost(); // Visit the post that was just published. await page.click( From 84408c4a0b24e88e46aa5267b8259bd706128a23 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:21:29 +0200 Subject: [PATCH 05/23] Migrate publishPost --- test/e2e/specs/editor/blocks/comments.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 066c6527931dd0..6ca43d97c71d71 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -4,7 +4,6 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); import { pressKeyTimes, - publishPost, setOption, } from '@wordpress/e2e-test-utils'; @@ -46,7 +45,7 @@ test.describe( 'Comments', () => { } ) => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); - await publishPost(); + await editor.publishPost(); // Visit the post that was just published. await page.click( '.post-publish-panel__postpublish-buttons .is-primary' @@ -110,7 +109,7 @@ test.describe( 'Comments', () => { await setOption( 'page_comments', '0' ); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); - await publishPost(); + await editor.publishPost(); // Visit the post that was just published. await page.click( '.post-publish-panel__postpublish-buttons .is-primary' From c5acda46a5debe2f86fe110ef6e2c9400c0437c8 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:34:16 +0200 Subject: [PATCH 06/23] Migrate pressKeyTimes --- test/e2e/specs/editor/blocks/comments.spec.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 6ca43d97c71d71..3242469377ab9a 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -2,10 +2,7 @@ * WordPress dependencies */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -import { - pressKeyTimes, - setOption, -} from '@wordpress/e2e-test-utils'; +import { setOption } from '@wordpress/e2e-test-utils'; /** * @typedef {import('@playwright/test').Page} Page @@ -42,6 +39,7 @@ test.describe( 'Comments', () => { admin, editor, page, + pageUtils, } ) => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); @@ -60,7 +58,7 @@ test.describe( 'Comments', () => { `textarea#comment`, `This is an automated comment - ${ i }` ); - await pressKeyTimes( 'Tab', 1 ); + await pageUtils.pressKeyTimes( 'Tab', 1 ); await Promise.all( [ page.keyboard.press( 'Enter' ), page.waitForNavigation( { waitUntil: 'networkidle0' } ), @@ -105,6 +103,7 @@ test.describe( 'Comments', () => { admin, editor, page, + pageUtils, } ) => { await setOption( 'page_comments', '0' ); await admin.createNewPost(); @@ -123,7 +122,7 @@ test.describe( 'Comments', () => { `textarea#comment`, `This is an automated comment - ${ i }` ); - await pressKeyTimes( 'Tab', 1 ); + await pageUtils.pressKeyTimes( 'Tab', 1 ); await Promise.all( [ page.keyboard.press( 'Enter' ), page.waitForNavigation( { waitUntil: 'networkidle0' } ), From cc4a80c87a905a19f2effac053deacefcab10acb Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 17:46:34 +0200 Subject: [PATCH 07/23] Add and use new setOption Playwright util --- .../src/admin/index.ts | 2 ++ .../src/admin/set-option.ts | 20 +++++++++++++++ test/e2e/specs/editor/blocks/comments.spec.js | 25 +++++++++++-------- 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 packages/e2e-test-utils-playwright/src/admin/set-option.ts diff --git a/packages/e2e-test-utils-playwright/src/admin/index.ts b/packages/e2e-test-utils-playwright/src/admin/index.ts index ee7ebe406fc25f..d28f68872abc51 100644 --- a/packages/e2e-test-utils-playwright/src/admin/index.ts +++ b/packages/e2e-test-utils-playwright/src/admin/index.ts @@ -11,6 +11,7 @@ import type { Browser, Page, BrowserContext } from '@playwright/test'; */ import { createNewPost } from './create-new-post'; import { getPageError } from './get-page-error'; +import { setOption } from './set-option'; import { visitAdminPage } from './visit-admin-page'; import { visitSiteEditor } from './visit-site-editor'; import type { PageUtils } from '../page-utils'; @@ -35,6 +36,7 @@ export class Admin { createNewPost = createNewPost.bind( this ); getPageError = getPageError.bind( this ); + setOption = setOption.bind( this ); visitAdminPage = visitAdminPage.bind( this ); visitSiteEditor = visitSiteEditor.bind( this ); } diff --git a/packages/e2e-test-utils-playwright/src/admin/set-option.ts b/packages/e2e-test-utils-playwright/src/admin/set-option.ts new file mode 100644 index 00000000000000..e9941dc06c7554 --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/admin/set-option.ts @@ -0,0 +1,20 @@ +/** + * Internal dependencies + */ +import type { Admin } from './'; + +export async function setOption( this: Admin, setting: string, value: string ) { + await this.visitAdminPage( 'options.php', '' ); + await this.page.waitForSelector( `#${ setting }` ); + const previousValue = await this.page.inputValue( `#${ setting }` ); + + await this.page.focus( `#${ setting }` ); + await this.pageUtils.pressKeyWithModifier( 'primary', 'a' ); + await this.page.type( `#${ setting }`, value ); + + await Promise.all( [ + this.page.click( '#Update' ), + this.page.waitForNavigation( { waitUntil: 'networkidle' } ), + ] ); + return previousValue; +} diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 3242469377ab9a..5ac32c6b47b5f8 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -2,7 +2,6 @@ * WordPress dependencies */ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); -import { setOption } from '@wordpress/e2e-test-utils'; /** * @typedef {import('@playwright/test').Page} Page @@ -13,11 +12,14 @@ test.describe( 'Comments', () => { let previousPageComments, previousCommentsPerPage, previousDefaultCommentsPage; - test.beforeAll( async ( { requestUtils } ) => { + test.beforeAll( async ( { admin, requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); - previousPageComments = await setOption( 'page_comments', '1' ); - previousCommentsPerPage = await setOption( 'comments_per_page', '1' ); - previousDefaultCommentsPage = await setOption( + previousPageComments = await admin.setOption( 'page_comments', '1' ); + previousCommentsPerPage = await admin.setOption( + 'comments_per_page', + '1' + ); + previousDefaultCommentsPage = await admin.setOption( 'default_comments_page', 'newest' ); @@ -105,7 +107,7 @@ test.describe( 'Comments', () => { page, pageUtils, } ) => { - await setOption( 'page_comments', '0' ); + await admin.setOption( 'page_comments', '0' ); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); await editor.publishPost(); @@ -136,11 +138,14 @@ test.describe( 'Comments', () => { await page.$( '.wp-block-comments-pagination-next' ) ).toBeNull(); } ); - test.afterAll( async ( { requestUtils } ) => { + test.afterAll( async ( { admin, requestUtils } ) => { await requestUtils.deleteAllComments(); await requestUtils.activateTheme( 'twentytwentyone' ); - await setOption( 'page_comments', previousPageComments ); - await setOption( 'comments_per_page', previousCommentsPerPage ); - await setOption( 'default_comments_page', previousDefaultCommentsPage ); + await admin.setOption( 'page_comments', previousPageComments ); + await admin.setOption( 'comments_per_page', previousCommentsPerPage ); + await admin.setOption( + 'default_comments_page', + previousDefaultCommentsPage + ); } ); } ); From 5ae3a4ee7b25913b94f6c71a991d971f3c4c3edc Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 6 Jul 2022 19:33:46 +0200 Subject: [PATCH 08/23] Use page.locator instead of page.$ --- test/e2e/specs/editor/blocks/comments.spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 5ac32c6b47b5f8..c5a022584fe5ec 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -69,10 +69,10 @@ test.describe( 'Comments', () => { // We check that there is a previous comments page link. expect( - await page.$( '.wp-block-comments-pagination-previous' ) + await page.locator( '.wp-block-comments-pagination-previous' ) ).not.toBeNull(); expect( - await page.$( '.wp-block-comments-pagination-next' ) + await page.locator( '.wp-block-comments-pagination-next' ) ).toBeNull(); await Promise.all( [ @@ -82,10 +82,10 @@ test.describe( 'Comments', () => { // We check that there are a previous and a next link. expect( - await page.$( '.wp-block-comments-pagination-previous' ) + await page.locator( '.wp-block-comments-pagination-previous' ) ).not.toBeNull(); expect( - await page.$( '.wp-block-comments-pagination-next' ) + await page.locator( '.wp-block-comments-pagination-next' ) ).not.toBeNull(); await Promise.all( [ @@ -95,10 +95,10 @@ test.describe( 'Comments', () => { // We check that there is only have a next link expect( - await page.$( '.wp-block-comments-pagination-previous' ) + await page.locator( '.wp-block-comments-pagination-previous' ) ).toBeNull(); expect( - await page.$( '.wp-block-comments-pagination-next' ) + await page.locator( '.wp-block-comments-pagination-next' ) ).not.toBeNull(); } ); test( 'Pagination links are not appearing if break comments is not enabled', async ( { @@ -132,10 +132,10 @@ test.describe( 'Comments', () => { } // We check that there are no comments page link. expect( - await page.$( '.wp-block-comments-pagination-previous' ) + await page.locator( '.wp-block-comments-pagination-previous' ) ).toBeNull(); expect( - await page.$( '.wp-block-comments-pagination-next' ) + await page.locator( '.wp-block-comments-pagination-next' ) ).toBeNull(); } ); test.afterAll( async ( { admin, requestUtils } ) => { From 5622a82e78788b55f56c91aa1705d843ef17829c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 7 Jul 2022 13:58:42 +0200 Subject: [PATCH 09/23] Use beforeEach and afterEach --- test/e2e/specs/editor/blocks/comments.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index c5a022584fe5ec..191101bcbc71b9 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -12,7 +12,7 @@ test.describe( 'Comments', () => { let previousPageComments, previousCommentsPerPage, previousDefaultCommentsPage; - test.beforeAll( async ( { admin, requestUtils } ) => { + test.beforeEach( async ( { admin, requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); previousPageComments = await admin.setOption( 'page_comments', '1' ); previousCommentsPerPage = await admin.setOption( @@ -138,7 +138,7 @@ test.describe( 'Comments', () => { await page.locator( '.wp-block-comments-pagination-next' ) ).toBeNull(); } ); - test.afterAll( async ( { admin, requestUtils } ) => { + test.afterEach( async ( { admin, requestUtils } ) => { await requestUtils.deleteAllComments(); await requestUtils.activateTheme( 'twentytwentyone' ); await admin.setOption( 'page_comments', previousPageComments ); From 27f8d226466443c9f422cc24353310027d8f1e52 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 7 Jul 2022 14:04:47 +0200 Subject: [PATCH 10/23] Add comments and move theme activation into beforeAll/afterAll --- test/e2e/specs/editor/blocks/comments.spec.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 191101bcbc71b9..80643fc2f66841 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -12,8 +12,16 @@ test.describe( 'Comments', () => { let previousPageComments, previousCommentsPerPage, previousDefaultCommentsPage; - test.beforeEach( async ( { admin, requestUtils } ) => { + + test.beforeAll( async ( { requestUtils } ) => { await requestUtils.activateTheme( 'emptytheme' ); + } ); + + test.beforeEach( async ( { admin } ) => { + // Ideally, we'd set options in beforeAll. Unfortunately, these + // aren't exposed via the REST API, so we have to set them through the + // relevant wp-admin screen, which involves page utils; but those are + // prohibited from beforeAll. previousPageComments = await admin.setOption( 'page_comments', '1' ); previousCommentsPerPage = await admin.setOption( 'comments_per_page', @@ -138,9 +146,12 @@ test.describe( 'Comments', () => { await page.locator( '.wp-block-comments-pagination-next' ) ).toBeNull(); } ); - test.afterEach( async ( { admin, requestUtils } ) => { - await requestUtils.deleteAllComments(); - await requestUtils.activateTheme( 'twentytwentyone' ); + + test.afterEach( async ( { admin } ) => { + // Ideally, we'd set options in afterAll. Unfortunately, these + // aren't exposed via the REST API, so we have to set them through the + // relevant wp-admin screen, which involves page utils; but those are + // prohibited from beforeAll. await admin.setOption( 'page_comments', previousPageComments ); await admin.setOption( 'comments_per_page', previousCommentsPerPage ); await admin.setOption( @@ -148,4 +159,9 @@ test.describe( 'Comments', () => { previousDefaultCommentsPage ); } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deleteAllComments(); + await requestUtils.activateTheme( 'twentytwentyone' ); + } ); } ); From 321d4fb2dd447d4b2336491368a0bd986f740b24 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 7 Jul 2022 23:08:24 +0200 Subject: [PATCH 11/23] Use assertions that work --- test/e2e/specs/editor/blocks/comments.spec.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 80643fc2f66841..c4c6f29bafe222 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -76,12 +76,12 @@ test.describe( 'Comments', () => { } // We check that there is a previous comments page link. - expect( + await expect( await page.locator( '.wp-block-comments-pagination-previous' ) - ).not.toBeNull(); - expect( + ).toHaveCount( 1 ); + await expect( await page.locator( '.wp-block-comments-pagination-next' ) - ).toBeNull(); + ).toHaveCount( 0 ); await Promise.all( [ page.click( '.wp-block-comments-pagination-previous' ), @@ -89,12 +89,12 @@ test.describe( 'Comments', () => { ] ); // We check that there are a previous and a next link. - expect( + await expect( await page.locator( '.wp-block-comments-pagination-previous' ) - ).not.toBeNull(); - expect( + ).toHaveCount( 1 ); + await expect( await page.locator( '.wp-block-comments-pagination-next' ) - ).not.toBeNull(); + ).toHaveCount( 1 ); await Promise.all( [ page.click( '.wp-block-comments-pagination-previous' ), @@ -102,12 +102,12 @@ test.describe( 'Comments', () => { ] ); // We check that there is only have a next link - expect( + await expect( await page.locator( '.wp-block-comments-pagination-previous' ) - ).toBeNull(); - expect( + ).toHaveCount( 0 ); + await expect( await page.locator( '.wp-block-comments-pagination-next' ) - ).not.toBeNull(); + ).toHaveCount( 1 ); } ); test( 'Pagination links are not appearing if break comments is not enabled', async ( { admin, @@ -139,12 +139,12 @@ test.describe( 'Comments', () => { ] ); } // We check that there are no comments page link. - expect( + await expect( await page.locator( '.wp-block-comments-pagination-previous' ) - ).toBeNull(); - expect( + ).toHaveCount( 0 ); + await expect( await page.locator( '.wp-block-comments-pagination-next' ) - ).toBeNull(); + ).toHaveCount( 0 ); } ); test.afterEach( async ( { admin } ) => { From 7a6ab23b4371feced5716c2de85fb1e6dd15e3c6 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 7 Jul 2022 23:13:12 +0200 Subject: [PATCH 12/23] Use waitForSelector --- test/e2e/specs/editor/blocks/comments.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index c4c6f29bafe222..390fe9f12f7a48 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -42,7 +42,9 @@ test.describe( 'Comments', () => { await requestUtils.deleteAllComments(); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); - await page.waitForXPath( '//p[contains(text(), "No results found.")]' ); + await page.waitForSelector( + 'xpath=//p[contains(text(), "No results found.")]' + ); } ); test( 'Pagination links are working as expected', async ( { From 088c37217bd3a48e744b5a08644de1c27123dab4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 11:50:55 +0200 Subject: [PATCH 13/23] Wrong block ID :facepalm: --- test/e2e/specs/editor/blocks/comments.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 390fe9f12f7a48..5b363e58ae530a 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -41,7 +41,7 @@ test.describe( 'Comments', () => { } ) => { await requestUtils.deleteAllComments(); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); await page.waitForSelector( 'xpath=//p[contains(text(), "No results found.")]' ); @@ -54,7 +54,7 @@ test.describe( 'Comments', () => { pageUtils, } ) => { await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); await editor.publishPost(); // Visit the post that was just published. await page.click( @@ -119,7 +119,7 @@ test.describe( 'Comments', () => { } ) => { await admin.setOption( 'page_comments', '0' ); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); await editor.publishPost(); // Visit the post that was just published. await page.click( From e041a2c8dba5fa8d528eae69fb119cbca73e4389 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 12:04:24 +0200 Subject: [PATCH 14/23] Revert "Wrong block ID :facepalm:" This reverts commit 088c37217bd3a48e744b5a08644de1c27123dab4. --- test/e2e/specs/editor/blocks/comments.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 5b363e58ae530a..390fe9f12f7a48 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -41,7 +41,7 @@ test.describe( 'Comments', () => { } ) => { await requestUtils.deleteAllComments(); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments' } ); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await page.waitForSelector( 'xpath=//p[contains(text(), "No results found.")]' ); @@ -54,7 +54,7 @@ test.describe( 'Comments', () => { pageUtils, } ) => { await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments' } ); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await editor.publishPost(); // Visit the post that was just published. await page.click( @@ -119,7 +119,7 @@ test.describe( 'Comments', () => { } ) => { await admin.setOption( 'page_comments', '0' ); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments' } ); + await editor.insertBlock( { name: 'core/comments-query-loop' } ); await editor.publishPost(); // Visit the post that was just published. await page.click( From e6b43255ef2359b572949fd443bfb22123722303 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 12:29:36 +0200 Subject: [PATCH 15/23] Nicer selector for View Post --- test/e2e/specs/editor/blocks/comments.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 390fe9f12f7a48..ce4f3708c1e745 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -58,7 +58,7 @@ test.describe( 'Comments', () => { await editor.publishPost(); // Visit the post that was just published. await page.click( - '.post-publish-panel__postpublish-buttons .is-primary' + 'role=region[name="Editor publish"i] >> "View Post"' ); // TODO: We can extract this into a util once we find we need it elsewhere. @@ -123,7 +123,7 @@ test.describe( 'Comments', () => { await editor.publishPost(); // Visit the post that was just published. await page.click( - '.post-publish-panel__postpublish-buttons .is-primary' + 'role=region[name="Editor publish"i] >> "View Post"' ); // Create three comments for that post. From ca5cab10067242edf72c6cedba535b485f27cbae Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 13:51:50 +0200 Subject: [PATCH 16/23] Have publishPost return the ID of the newly created post --- .../e2e-test-utils-playwright/src/editor/publish-post.ts | 5 +++++ test/e2e/specs/editor/blocks/comments.spec.js | 1 + 2 files changed, 6 insertions(+) diff --git a/packages/e2e-test-utils-playwright/src/editor/publish-post.ts b/packages/e2e-test-utils-playwright/src/editor/publish-post.ts index a1f624981bdc97..acd0ba1c5c0341 100644 --- a/packages/e2e-test-utils-playwright/src/editor/publish-post.ts +++ b/packages/e2e-test-utils-playwright/src/editor/publish-post.ts @@ -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"' ); + const url = new URL( urlString ); + const postId = url.searchParams.get( 'p' ); + return postId; } diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index ce4f3708c1e745..f9c3c6f7177f25 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -121,6 +121,7 @@ test.describe( 'Comments', () => { await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); await editor.publishPost(); + // Visit the post that was just published. await page.click( 'role=region[name="Editor publish"i] >> "View Post"' From a120459376f8d52681c0996cea0a6ca837a19131 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 14:13:28 +0200 Subject: [PATCH 17/23] Add createComment util --- .../src/request-utils/comments.ts | 18 +++++++++++++++++- .../src/request-utils/index.ts | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/request-utils/comments.ts b/packages/e2e-test-utils-playwright/src/request-utils/comments.ts index b9da230b3b0edb..a49526f167180d 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/comments.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/comments.ts @@ -3,8 +3,24 @@ */ import type { RequestUtils } from './index'; -interface Comment { +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( { + method: 'POST', + path: '/wp/v2/comments', + data: comment, + } ); } /** diff --git a/packages/e2e-test-utils-playwright/src/request-utils/index.ts b/packages/e2e-test-utils-playwright/src/request-utils/index.ts index 63d99b29854c12..03c9002c65bcb1 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/index.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/index.ts @@ -18,7 +18,7 @@ import { getPluginsMap, activatePlugin, deactivatePlugin } from './plugins'; import { deleteAllTemplates } from './templates'; import { activateTheme } from './themes'; import { deleteAllBlocks } from './blocks'; -import { deleteAllComments } from './comments'; +import { createComment, deleteAllComments } from './comments'; import { deleteAllPosts } from './posts'; import { resetPreferences } from './preferences'; import { deleteAllWidgets, addWidgetBlock } from './widgets'; @@ -122,6 +122,7 @@ class RequestUtils { activateTheme = activateTheme.bind( this ); deleteAllBlocks = deleteAllBlocks; deleteAllPosts = deleteAllPosts.bind( this ); + createComment = createComment.bind( this ); deleteAllComments = deleteAllComments.bind( this ); deleteAllWidgets = deleteAllWidgets.bind( this ); addWidgetBlock = addWidgetBlock.bind( this ); From f54440e1d5cb38333c3169e3d1dad08e1a365b3d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 14:14:29 +0200 Subject: [PATCH 18/23] Add getCurrentUser util --- .../src/request-utils/index.ts | 2 ++ .../src/request-utils/user.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 packages/e2e-test-utils-playwright/src/request-utils/user.ts diff --git a/packages/e2e-test-utils-playwright/src/request-utils/index.ts b/packages/e2e-test-utils-playwright/src/request-utils/index.ts index 03c9002c65bcb1..1ea7b81acdfdb6 100644 --- a/packages/e2e-test-utils-playwright/src/request-utils/index.ts +++ b/packages/e2e-test-utils-playwright/src/request-utils/index.ts @@ -21,6 +21,7 @@ import { deleteAllBlocks } from './blocks'; import { createComment, deleteAllComments } from './comments'; import { deleteAllPosts } from './posts'; import { resetPreferences } from './preferences'; +import { getCurrentUser } from './user'; import { deleteAllWidgets, addWidgetBlock } from './widgets'; interface StorageState { @@ -132,6 +133,7 @@ class RequestUtils { uploadMedia = uploadMedia.bind( this ); deleteMedia = deleteMedia.bind( this ); deleteAllMedia = deleteAllMedia.bind( this ); + getCurrentUser = getCurrentUser.bind( this ); } export type { StorageState }; diff --git a/packages/e2e-test-utils-playwright/src/request-utils/user.ts b/packages/e2e-test-utils-playwright/src/request-utils/user.ts new file mode 100644 index 00000000000000..855136d80c051e --- /dev/null +++ b/packages/e2e-test-utils-playwright/src/request-utils/user.ts @@ -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; +} From 2a622f2af72c5b3e3638e1ab6659eb32003022eb Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 14:15:19 +0200 Subject: [PATCH 19/23] Create comments via requestUtils --- test/e2e/specs/editor/blocks/comments.spec.js | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index f9c3c6f7177f25..15d18c03701d6a 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -51,32 +51,27 @@ test.describe( 'Comments', () => { admin, editor, page, - pageUtils, + requestUtils, } ) => { + const author = requestUtils.getCurrentUser(); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); - await editor.publishPost(); - // Visit the post that was just published. - await page.click( - 'role=region[name="Editor publish"i] >> "View Post"' - ); + const postId = await editor.publishPost(); - // 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 pageUtils.pressKeyTimes( 'Tab', 1 ); - await Promise.all( [ - page.keyboard.press( 'Enter' ), - page.waitForNavigation( { waitUntil: 'networkidle0' } ), - ] ); + await requestUtils.createComment( { + author: author.id, + content: `This is an automated comment - ${ i }`, + post: postId, + } ); } + // Visit the post that was just published. + await page.click( + 'role=region[name="Editor publish"i] >> "View Post"' + ); + // We check that there is a previous comments page link. await expect( await page.locator( '.wp-block-comments-pagination-previous' ) @@ -115,32 +110,28 @@ test.describe( 'Comments', () => { admin, editor, page, - pageUtils, + requestUtils, } ) => { + const author = requestUtils.getCurrentUser(); await admin.setOption( 'page_comments', '0' ); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments-query-loop' } ); - await editor.publishPost(); + const postId = await editor.publishPost(); + + // Create three comments for that post. + for ( let i = 0; i < 3; i++ ) { + await requestUtils.createComment( { + author: author.id, + content: `This is an automated comment - ${ i }`, + post: postId, + } ); + } // Visit the post that was just published. await page.click( 'role=region[name="Editor publish"i] >> "View Post"' ); - // 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 pageUtils.pressKeyTimes( 'Tab', 1 ); - await Promise.all( [ - page.keyboard.press( 'Enter' ), - page.waitForNavigation( { waitUntil: 'networkidle0' } ), - ] ); - } // We check that there are no comments page link. await expect( await page.locator( '.wp-block-comments-pagination-previous' ) From bc7b5ab6d345e3500110ecc4752c60cc8290518d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 14:19:04 +0200 Subject: [PATCH 20/23] Fix ID --- test/e2e/specs/editor/blocks/comments.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 15d18c03701d6a..be90ecc7c2138e 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -41,7 +41,7 @@ test.describe( 'Comments', () => { } ) => { await requestUtils.deleteAllComments(); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); await page.waitForSelector( 'xpath=//p[contains(text(), "No results found.")]' ); @@ -55,7 +55,7 @@ test.describe( 'Comments', () => { } ) => { const author = requestUtils.getCurrentUser(); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); const postId = await editor.publishPost(); // Create three comments for that post. @@ -115,7 +115,7 @@ test.describe( 'Comments', () => { const author = requestUtils.getCurrentUser(); await admin.setOption( 'page_comments', '0' ); await admin.createNewPost(); - await editor.insertBlock( { name: 'core/comments-query-loop' } ); + await editor.insertBlock( { name: 'core/comments' } ); const postId = await editor.publishPost(); // Create three comments for that post. From ffbcc07854f3a4b6cd5b475e05f2fc9faa93383c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 15:43:42 +0200 Subject: [PATCH 21/23] Nicer selectors --- test/e2e/specs/editor/blocks/comments.spec.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index be90ecc7c2138e..3687be1efe491f 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -74,36 +74,36 @@ test.describe( 'Comments', () => { // We check that there is a previous comments page link. await expect( - await page.locator( '.wp-block-comments-pagination-previous' ) + await page.locator( 'text="Older Comments"' ) ).toHaveCount( 1 ); await expect( - await page.locator( '.wp-block-comments-pagination-next' ) + await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 0 ); await Promise.all( [ - page.click( '.wp-block-comments-pagination-previous' ), + page.click( 'text="Older Comments"' ), page.waitForNavigation( { waitUntil: 'networkidle0' } ), ] ); // We check that there are a previous and a next link. await expect( - await page.locator( '.wp-block-comments-pagination-previous' ) + await page.locator( 'text="Older Comments"' ) ).toHaveCount( 1 ); await expect( - await page.locator( '.wp-block-comments-pagination-next' ) + await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 1 ); await Promise.all( [ - page.click( '.wp-block-comments-pagination-previous' ), + page.click( 'text="Older Comments"' ), page.waitForNavigation( { waitUntil: 'networkidle0' } ), ] ); // We check that there is only have a next link await expect( - await page.locator( '.wp-block-comments-pagination-previous' ) + await page.locator( 'text="Older Comments"' ) ).toHaveCount( 0 ); await expect( - await page.locator( '.wp-block-comments-pagination-next' ) + await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 1 ); } ); test( 'Pagination links are not appearing if break comments is not enabled', async ( { @@ -134,10 +134,10 @@ test.describe( 'Comments', () => { // We check that there are no comments page link. await expect( - await page.locator( '.wp-block-comments-pagination-previous' ) + await page.locator( 'text="Older Comments"' ) ).toHaveCount( 0 ); await expect( - await page.locator( '.wp-block-comments-pagination-next' ) + await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 0 ); } ); From 0980b30aa10fe8826d49c2624e14f91273673077 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 16:00:52 +0200 Subject: [PATCH 22/23] Further simplify --- test/e2e/specs/editor/blocks/comments.spec.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/e2e/specs/editor/blocks/comments.spec.js b/test/e2e/specs/editor/blocks/comments.spec.js index 3687be1efe491f..e487ead36e62fa 100644 --- a/test/e2e/specs/editor/blocks/comments.spec.js +++ b/test/e2e/specs/editor/blocks/comments.spec.js @@ -42,9 +42,9 @@ test.describe( 'Comments', () => { await requestUtils.deleteAllComments(); await admin.createNewPost(); await editor.insertBlock( { name: 'core/comments' } ); - await page.waitForSelector( - 'xpath=//p[contains(text(), "No results found.")]' - ); + await expect( + await page.locator( 'text="No results found."' ) + ).toHaveCount( 1 ); } ); test( 'Pagination links are working as expected', async ( { @@ -80,10 +80,7 @@ test.describe( 'Comments', () => { await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 0 ); - await Promise.all( [ - page.click( 'text="Older Comments"' ), - page.waitForNavigation( { waitUntil: 'networkidle0' } ), - ] ); + await page.click( 'text="Older Comments"' ); // We check that there are a previous and a next link. await expect( @@ -93,10 +90,7 @@ test.describe( 'Comments', () => { await page.locator( 'text="Newer Comments"' ) ).toHaveCount( 1 ); - await Promise.all( [ - page.click( 'text="Older Comments"' ), - page.waitForNavigation( { waitUntil: 'networkidle0' } ), - ] ); + await page.click( 'text="Older Comments"' ); // We check that there is only have a next link await expect( From cef603a2c56afe3c2e378d130c3469bcdaeb1385 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 8 Jul 2022 16:07:24 +0200 Subject: [PATCH 23/23] Simplify setOption --- .../e2e-test-utils-playwright/src/admin/set-option.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/set-option.ts b/packages/e2e-test-utils-playwright/src/admin/set-option.ts index e9941dc06c7554..2e18563d0c587b 100644 --- a/packages/e2e-test-utils-playwright/src/admin/set-option.ts +++ b/packages/e2e-test-utils-playwright/src/admin/set-option.ts @@ -5,16 +5,10 @@ import type { Admin } from './'; export async function setOption( this: Admin, setting: string, value: string ) { await this.visitAdminPage( 'options.php', '' ); - await this.page.waitForSelector( `#${ setting }` ); const previousValue = await this.page.inputValue( `#${ setting }` ); - await this.page.focus( `#${ setting }` ); - await this.pageUtils.pressKeyWithModifier( 'primary', 'a' ); - await this.page.type( `#${ setting }`, value ); + await this.page.fill( `#${ setting }`, value ); - await Promise.all( [ - this.page.click( '#Update' ), - this.page.waitForNavigation( { waitUntil: 'networkidle' } ), - ] ); + await this.page.click( '#Update' ); return previousValue; }