diff --git a/.github/files/e2e-tests/e2e-matrix.js b/.github/files/e2e-tests/e2e-matrix.js index 88527f173d84..9b2bb4afc5cb 100644 --- a/.github/files/e2e-tests/e2e-matrix.js +++ b/.github/files/e2e-tests/e2e-matrix.js @@ -30,6 +30,13 @@ const projects = [ targets: [ 'plugins/jetpack', 'packages/forms' ], buildGroup: 'jetpack-core', }, + { + project: 'Jetpack comments', + path: 'projects/plugins/jetpack/tests/e2e', + testArgs: [ 'specs/comments' ], + targets: [ 'plugins/jetpack', 'packages/comments' ], + buildGroup: 'jetpack-core', + }, { project: 'Jetpack sync', path: 'projects/plugins/jetpack/tests/e2e', diff --git a/projects/plugins/jetpack/changelog/add-comments-e2e b/projects/plugins/jetpack/changelog/add-comments-e2e new file mode 100644 index 000000000000..595b91c7cf8b --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-comments-e2e @@ -0,0 +1,4 @@ +Significance: patch +Type: other +Comment: Add an E2E test for the Jetpack Comments block editor. + diff --git a/projects/plugins/jetpack/tests/e2e/package.json b/projects/plugins/jetpack/tests/e2e/package.json index 36481ebd4469..16a3e42028ca 100644 --- a/projects/plugins/jetpack/tests/e2e/package.json +++ b/projects/plugins/jetpack/tests/e2e/package.json @@ -3,7 +3,7 @@ "type": "module", "scripts": { "allure-report": "allure generate --clean --output ./output/allure-report ./output/allure-results && allure open ./output/allure-report", - "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/wp-build-polyfills packages/forms packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", + "build": "pnpm jetpack build packages/my-jetpack js-packages/social-logos js-packages/boost-score-api js-packages/components js-packages/number-formatters js-packages/charts js-packages/social-previews packages/wp-build-polyfills packages/forms packages/comments packages/assets packages/connection packages/publicize packages/blaze js-packages/ai-client plugins/jetpack -v --no-pnpm-install --production", "clean": "rm -rf output", "config:decrypt": "pnpm test-decrypt-default-config && pnpm test-decrypt-config", "distclean": "rm -rf node_modules", diff --git a/projects/plugins/jetpack/tests/e2e/specs/comments/block-editor.test.ts b/projects/plugins/jetpack/tests/e2e/specs/comments/block-editor.test.ts new file mode 100644 index 000000000000..4a2895c10cb4 --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/specs/comments/block-editor.test.ts @@ -0,0 +1,86 @@ +import { expect, test } from '@automattic/_jetpack-e2e-commons/fixtures/base-test'; + +let postId: number | undefined; + +const IMAGE = 'https://example.com/e2e.png'; +// A 1x1 PNG, so the image loads without the network. +const PNG = Buffer.from( + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', + 'base64' +); + +test.beforeAll( async ( { testUtils } ) => { + await testUtils.activateModule( 'comments' ); +} ); + +test.afterAll( async ( { requestUtils, testUtils } ) => { + if ( postId !== undefined ) { + await requestUtils.rest( { + method: 'DELETE', + path: `/wp/v2/posts/${ postId }`, + params: { force: true }, + } ); + } + await testUtils.deactivateModule( 'comments' ); +} ); + +test.describe( 'Comments: Block editor', () => { + test( 'Posts a comment with a paragraph, a list, a quote, and an image', async ( { + page, + requestUtils, + } ) => { + const post: { id: number; link: string } = await requestUtils.rest( { + method: 'POST', + path: '/wp/v2/posts', + data: { title: 'E2E Comments', status: 'publish' }, + } ); + postId = post.id; + + await page.route( IMAGE, route => route.fulfill( { contentType: 'image/png', body: PNG } ) ); + + await test.step( 'Write the comment in the block editor', async () => { + await page.goto( post.link ); + await page.getByRole( 'textbox', { name: 'Comment' } ).click(); + + const editor = page.locator( '.jetpack-comments__editor' ); + await expect( editor.locator( '[contenteditable="true"]' ).first() ).toBeFocused(); + + await page.keyboard.type( 'Hello from E2E' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '- First item' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '> A quote' ); + + // A block that crashes on select takes the whole editor down to the plain textarea. + await expect( editor.locator( '[data-type="core/list"]' ) ).toBeVisible(); + await expect( editor.locator( '[data-type="core/quote"]' ) ).toBeVisible(); + + await page.getByRole( 'button', { name: 'Add block' } ).click(); + await page.getByRole( 'menuitem', { name: 'Image' } ).click(); + await editor.getByRole( 'textbox', { name: 'URL' } ).fill( IMAGE ); + await editor.getByRole( 'button', { name: 'Apply' } ).click(); + // A failed load clears the URL, so the image must actually draw. + await expect( editor.locator( '[data-type="core/image"] img' ) ).toHaveJSProperty( + 'naturalWidth', + 1 + ); + } ); + + await test.step( 'Post it', async () => { + await page.getByRole( 'button', { name: 'Comment', exact: true } ).click(); + + await expect + .poll( async () => { + const comments = await requestUtils.rest( { + path: '/wp/v2/comments', + params: { post: post.id, context: 'edit' }, + } ); + return comments[ 0 ]?.content.raw ?? ''; + } ) + .toMatch( + /Hello from E2E[\s\S]*
https:\/\/example\.com\/e2e\.png<\/figure>/ + ); + } ); + } ); +} );