Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/files/e2e-tests/e2e-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/add-comments-e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other
Comment: Add an E2E test for the Jetpack Comments block editor.

2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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]*<li>First item<\/li>[\s\S]*<blockquote[\s\S]*A quote[\s\S]*<figure class="wp-block-image">https:\/\/example\.com\/e2e\.png<\/figure>/
);
} );
} );
} );
Loading