2
` ); - await editor.canvas.focus( - 'role=document[name="Block: Paragraph"i] >> text=2' - ); + await editor.canvas + .locator( 'role=document[name="Block: Paragraph"i] >> text=2' ) + .focus(); await editor.showBlockToolbar(); const dragHandle = page.locator( @@ -114,9 +114,9 @@ test.describe( 'Draggable block', () => {2
` ); - await editor.canvas.focus( - 'role=document[name="Block: Paragraph"i] >> text=1' - ); + await editor.canvas + .locator( 'role=document[name="Block: Paragraph"i] >> text=1' ) + .focus(); await editor.showBlockToolbar(); const dragHandle = page.locator( @@ -197,9 +197,9 @@ test.describe( 'Draggable block', () => { ], } ); - await editor.canvas.focus( - 'role=document[name="Block: Paragraph"i] >> text=2' - ); + await editor.canvas + .locator( 'role=document[name="Block: Paragraph"i] >> text=2' ) + .focus(); await editor.showBlockToolbar(); const dragHandle = page.locator( @@ -278,9 +278,9 @@ test.describe( 'Draggable block', () => { ], } ); - await editor.canvas.focus( - 'role=document[name="Block: Paragraph"i] >> text=1' - ); + await editor.canvas + .locator( 'role=document[name="Block: Paragraph"i] >> text=1' ) + .focus(); await editor.showBlockToolbar(); const dragHandle = page.locator( @@ -342,13 +342,6 @@ test.describe( 'Draggable block', () => { editor, pageUtils, } ) => { - // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); // Insert a row. await editor.insertBlock( { name: 'core/group', @@ -421,7 +414,7 @@ test.describe( 'Draggable block', () => { 'Dragging over the empty group block but outside the appender should still show the blue background' ).toHaveCSS( 'background-color', 'rgb(0, 124, 186)' ); - await drop(); + await drop( rowBlock ); await expect( rowAppender ).toBeHidden(); await expect.poll( editor.getBlocks ).toMatchObject( [ { @@ -453,7 +446,7 @@ test.describe( 'Draggable block', () => { 'rgb(0, 124, 186)' ); - await drop(); + await drop( columnAppender ); await expect( columnAppender ).toBeHidden(); await expect.poll( editor.getBlocks ).toMatchObject( [ { name: 'core/group' }, diff --git a/test/e2e/specs/editor/various/font-size-picker.spec.js b/test/e2e/specs/editor/various/font-size-picker.spec.js index ddc47e3ee6de6..5c6cb4b186e25 100644 --- a/test/e2e/specs/editor/various/font-size-picker.spec.js +++ b/test/e2e/specs/editor/various/font-size-picker.spec.js @@ -24,9 +24,9 @@ test.describe( 'Font Size Picker', () => { page, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph to be made "small"' ); await page.click( 'role=region[name="Editor settings"i] >> role=button[name="Set custom size"i]' @@ -47,9 +47,9 @@ test.describe( 'Font Size Picker', () => { pageUtils, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph reset - custom size' ); await page.click( 'role=region[name="Editor settings"i] >> role=button[name="Set custom size"i]' @@ -139,9 +139,9 @@ test.describe( 'Font Size Picker', () => { pageUtils, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph to be made "large"' ); await page.click( 'role=group[name="Font size"i] >> role=button[name="Font size"i]' @@ -161,9 +161,9 @@ test.describe( 'Font Size Picker', () => { pageUtils, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph with font size reset using tools panel menu' ); @@ -194,9 +194,9 @@ test.describe( 'Font Size Picker', () => { pageUtils, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph with font size reset using input field' ); @@ -231,9 +231,9 @@ test.describe( 'Font Size Picker', () => { page, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph to be made "large"' ); await page.click( 'role=radiogroup[name="Font size"i] >> role=radio[name="Large"i]' @@ -250,9 +250,9 @@ test.describe( 'Font Size Picker', () => { page, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph with font size reset using tools panel menu' ); @@ -281,9 +281,9 @@ test.describe( 'Font Size Picker', () => { pageUtils, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( - 'role=button[name="Add default block"i]' - ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Paragraph with font size reset using input field' ); diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index e3aa17c5a101c..14a2fc653e387 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -27,7 +27,9 @@ test.describe( 'Footnotes', () => { } ); test( 'can be inserted', async ( { editor, page } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'first paragraph' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'second paragraph' ); @@ -38,7 +40,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( 'first footnote' ); - const id1 = await editor.canvas.evaluate( () => { + const id1 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); @@ -58,7 +60,7 @@ test.describe( 'Footnotes', () => { }, ] ); - await editor.canvas.click( 'p:text("first paragraph")' ); + await editor.canvas.locator( 'p:text("first paragraph")' ).click(); await editor.showBlockToolbar(); await editor.clickBlockToolbarButton( 'More' ); @@ -66,7 +68,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( 'second footnote' ); - const id2 = await editor.canvas.evaluate( () => { + const id2 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); @@ -99,7 +101,7 @@ test.describe( 'Footnotes', () => { }, ] ); - await editor.canvas.click( 'p:text("first paragraph")' ); + await editor.canvas.locator( 'p:text("first paragraph")' ).click(); await editor.showBlockToolbar(); await editor.clickBlockToolbarButton( 'Move down' ); @@ -133,7 +135,7 @@ test.describe( 'Footnotes', () => { }, ] ); - await editor.canvas.click( `a[href="#${ id2 }-link"]` ); + await editor.canvas.locator( `a[href="#${ id2 }-link"]` ).click(); await page.keyboard.press( 'Backspace' ); expect( await editor.getBlocks() ).toMatchObject( [ @@ -161,7 +163,7 @@ test.describe( 'Footnotes', () => { }, ] ); - await editor.canvas.click( `a[href="#${ id1 }-link"]` ); + await editor.canvas.locator( `a[href="#${ id1 }-link"]` ).click(); await page.keyboard.press( 'Backspace' ); expect( await editor.getBlocks() ).toMatchObject( [ @@ -186,14 +188,16 @@ test.describe( 'Footnotes', () => { } ); test( 'can be inserted in a list', async ( { editor, page } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '* 1' ); await editor.clickBlockToolbarButton( 'More' ); await page.locator( 'button:text("Footnote")' ).click(); await page.keyboard.type( 'a' ); - const id1 = await editor.canvas.evaluate( () => { + const id1 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); @@ -224,7 +228,9 @@ test.describe( 'Footnotes', () => { test( 'can be inserted in a table', async ( { editor, page } ) => { await editor.insertBlock( { name: 'core/table' } ); - await editor.canvas.click( 'role=button[name="Create Table"i]' ); + await editor.canvas + .locator( 'role=button[name="Create Table"i]' ) + .click(); await page.keyboard.type( '1' ); await editor.showBlockToolbar(); await editor.clickBlockToolbarButton( 'More' ); @@ -232,7 +238,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( 'a' ); - const id1 = await editor.canvas.evaluate( () => { + const id1 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); @@ -282,7 +288,9 @@ test.describe( 'Footnotes', () => { } ); test( 'works with revisions', async ( { editor, page } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'first paragraph' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'second paragraph' ); @@ -294,11 +302,11 @@ test.describe( 'Footnotes', () => { // Check if content is correctly slashed on save and restore. await page.keyboard.type( 'first footnote"' ); - const id1 = await editor.canvas.evaluate( () => { + const id1 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); - await editor.canvas.click( 'p:text("first paragraph")' ); + await editor.canvas.locator( 'p:text("first paragraph")' ).click(); await editor.showBlockToolbar(); await editor.clickBlockToolbarButton( 'More' ); @@ -306,7 +314,7 @@ test.describe( 'Footnotes', () => { await page.keyboard.type( 'second footnote' ); - const id2 = await editor.canvas.evaluate( () => { + const id2 = await editor.canvas.locator( ':root' ).evaluate( () => { return document.activeElement.id; } ); @@ -322,7 +330,7 @@ test.describe( 'Footnotes', () => { }, ] ); - await editor.canvas.click( 'p:text("first paragraph")' ); + await editor.canvas.locator( 'p:text("first paragraph")' ).click(); await editor.showBlockToolbar(); await editor.clickBlockToolbarButton( 'Move down' ); @@ -348,7 +356,7 @@ test.describe( 'Footnotes', () => { await previewPage.close(); await editorPage.bringToFront(); - await editor.canvas.click( 'p:text("first paragraph")' ); + await editor.canvas.locator( 'p:text("first paragraph")' ).click(); // Open revisions. await editor.openDocumentSettingsSidebar(); @@ -383,7 +391,9 @@ test.describe( 'Footnotes', () => { } ); test( 'can be previewed when published', async ( { editor, page } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'a' ); await editor.showBlockToolbar(); @@ -396,7 +406,7 @@ test.describe( 'Footnotes', () => { const postId = await editor.publishPost(); // Test previewing changes to meta. - await editor.canvas.click( 'ol.wp-block-footnotes li span' ); + await editor.canvas.locator( 'ol.wp-block-footnotes li span' ).click(); await page.keyboard.press( 'End' ); await page.keyboard.type( '2' ); @@ -410,8 +420,9 @@ test.describe( 'Footnotes', () => { await previewPage.close(); await editorPage.bringToFront(); - // Test again, this time with an existing revision (different code path). - await editor.canvas.click( 'ol.wp-block-footnotes li span' ); + // Test again, this time with an existing revision (different code + // path). + await editor.canvas.locator( 'ol.wp-block-footnotes li span' ).click(); await page.keyboard.press( 'End' ); // Test slashing. await page.keyboard.type( '3"' ); diff --git a/test/e2e/specs/editor/various/inner-blocks-templates.spec.js b/test/e2e/specs/editor/various/inner-blocks-templates.spec.js index 47ef0dfe74791..0f9aed33d0773 100644 --- a/test/e2e/specs/editor/various/inner-blocks-templates.spec.js +++ b/test/e2e/specs/editor/various/inner-blocks-templates.spec.js @@ -28,11 +28,9 @@ test.describe( 'Inner blocks templates', () => { name: 'test/test-inner-blocks-async-template', } ); - const blockWithTemplateContent = page - .frameLocator( '[name=editor-canvas]' ) - .locator( - 'role=document[name="Block: Test Inner Blocks Async Template"i] >> text=OneTwo' - ); + const blockWithTemplateContent = editor.canvas.locator( + 'role=document[name="Block: Test Inner Blocks Async Template"i] >> text=OneTwo' + ); // The block template content appears asynchronously, so wait for it. await expect( blockWithTemplateContent ).toBeVisible(); diff --git a/test/e2e/specs/editor/various/inserting-blocks.spec.js b/test/e2e/specs/editor/various/inserting-blocks.spec.js index cfef686ef5c87..a48fe117c97a2 100644 --- a/test/e2e/specs/editor/various/inserting-blocks.spec.js +++ b/test/e2e/specs/editor/various/inserting-blocks.spec.js @@ -31,7 +31,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { ); await admin.createNewPost(); - await insertingBlocksUtils.runWithoutIframe(); + await editor.switchToLegacyCanvas(); // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 @@ -39,7 +39,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { name: 'core/paragraph', attributes: { content: 'Dummy text' }, } ); - const paragraphBlock = editor.canvas.locator( + const paragraphBlock = page.locator( '[data-type="core/paragraph"] >> text=Dummy text' ); @@ -109,7 +109,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { insertingBlocksUtils, } ) => { await admin.createNewPost(); - await insertingBlocksUtils.runWithoutIframe(); + await editor.switchToLegacyCanvas(); // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 @@ -120,7 +120,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { const beforeContent = await editor.getEditedPostContent(); - const paragraphBlock = editor.canvas.locator( + const paragraphBlock = page.locator( '[data-type="core/paragraph"] >> text=Dummy text' ); @@ -175,7 +175,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { ); await admin.createNewPost(); - await insertingBlocksUtils.runWithoutIframe(); + await editor.switchToLegacyCanvas(); // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 @@ -184,7 +184,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { attributes: { content: 'Dummy text' }, } ); - const paragraphBlock = editor.canvas.locator( + const paragraphBlock = page.locator( '[data-type="core/paragraph"] >> text=Dummy text' ); @@ -245,7 +245,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { insertingBlocksUtils, } ) => { await admin.createNewPost(); - await insertingBlocksUtils.runWithoutIframe(); + await editor.switchToLegacyCanvas(); // We need a dummy block in place to display the drop indicator due to a bug. // @see https://github.com/WordPress/gutenberg/issues/44064 @@ -256,7 +256,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { const beforeContent = await editor.getEditedPostContent(); - const paragraphBlock = editor.canvas.locator( + const paragraphBlock = page.locator( '[data-type="core/paragraph"] >> text=Dummy text' ); @@ -307,10 +307,8 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => { admin, page, editor, - insertingBlocksUtils, } ) => { await admin.createNewPost(); - await insertingBlocksUtils.runWithoutIframe(); const inserterButton = page.getByRole( 'button', { name: 'Toggle block inserter', @@ -390,16 +388,4 @@ class InsertingBlocksUtils { 'data-testid=block-draggable-chip >> visible=true' ); } - - async runWithoutIframe() { - /** - * @todo Some drag an drop tests are failing, so run them without iframe for now. - */ - return await this.page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); - } } diff --git a/test/e2e/specs/editor/various/keep-styles-on-block-transforms.spec.js b/test/e2e/specs/editor/various/keep-styles-on-block-transforms.spec.js index 8d1f37187fee1..57b958fdfc4b4 100644 --- a/test/e2e/specs/editor/various/keep-styles-on-block-transforms.spec.js +++ b/test/e2e/specs/editor/various/keep-styles-on-block-transforms.spec.js @@ -13,7 +13,9 @@ test.describe( 'Keep styles on block transforms', () => { editor, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '## Heading' ); await page.click( 'role=button[name="Color Text styles"i]' ); await page.click( 'role=option[name="Color: Luminous vivid orange"i]' ); @@ -37,15 +39,10 @@ test.describe( 'Keep styles on block transforms', () => { pageUtils, editor, } ) => { - // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Line 1 to be made large' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'Line 2 to be made large' ); @@ -78,7 +75,9 @@ test.describe( 'Keep styles on block transforms', () => { editor, } ) => { await editor.openDocumentSettingsSidebar(); - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Line 1 to be made large' ); await page.click( 'role=radio[name="Large"i]' ); await editor.showBlockToolbar(); diff --git a/test/e2e/specs/editor/various/list-view.spec.js b/test/e2e/specs/editor/various/list-view.spec.js index 7fd21085deae2..222d743acdf39 100644 --- a/test/e2e/specs/editor/various/list-view.spec.js +++ b/test/e2e/specs/editor/various/list-view.spec.js @@ -261,13 +261,6 @@ test.describe( 'List View', () => { page, pageUtils, } ) => { - // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); await editor.insertBlock( { name: 'core/image' } ); await editor.insertBlock( { name: 'core/paragraph', diff --git a/test/e2e/specs/editor/various/mentions.spec.js b/test/e2e/specs/editor/various/mentions.spec.js index 061b8d67a0801..fef3b1c3e3d2e 100644 --- a/test/e2e/specs/editor/various/mentions.spec.js +++ b/test/e2e/specs/editor/various/mentions.spec.js @@ -23,7 +23,9 @@ test.describe( 'autocomplete mentions', () => { } ); test( 'should insert mention', async ( { page, editor } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'I am @ad' ); await expect( page.locator( 'role=listbox >> role=option[name=/admin/i]' ) @@ -42,7 +44,9 @@ test.describe( 'autocomplete mentions', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Stuck in the middle with you' ); await pageUtils.pressKeys( 'ArrowLeft', { times: 'you'.length } ); await page.keyboard.type( '@j' ); @@ -62,7 +66,9 @@ test.describe( 'autocomplete mentions', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'I am @j' ); await expect( page.locator( 'role=listbox >> role=option[name=/testuser/i]' ) diff --git a/test/e2e/specs/editor/various/multi-block-selection.spec.js b/test/e2e/specs/editor/various/multi-block-selection.spec.js index 3374a13b98eb7..2473be99d218c 100644 --- a/test/e2e/specs/editor/various/multi-block-selection.spec.js +++ b/test/e2e/specs/editor/various/multi-block-selection.spec.js @@ -248,20 +248,14 @@ test.describe( 'Multi-block selection', () => { multiBlockSelectionUtils, } ) => { // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); - await editor.canvas - .getByRole( 'button', { name: 'Add default block' } ) - .click(); + await editor.switchToLegacyCanvas(); + + await page.getByRole( 'button', { name: 'Add default block' } ).click(); await page.keyboard.type( '1' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( '2' ); - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: '1' } ) .click( { modifiers: [ 'Shift' ] } ); @@ -278,11 +272,11 @@ test.describe( 'Multi-block selection', () => { .getByRole( 'toolbar', { name: 'Block tools' } ) .getByRole( 'button', { name: 'Group' } ) .click(); - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: '1' } ) .click(); - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: '2' } ) .click( { modifiers: [ 'Shift' ] } ); @@ -300,12 +294,8 @@ test.describe( 'Multi-block selection', () => { pageUtils, } ) => { // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); + await editor.switchToLegacyCanvas(); + await editor.insertBlock( { name: 'core/paragraph', attributes: { content: 'test' }, @@ -317,16 +307,12 @@ test.describe( 'Multi-block selection', () => { .getByRole( 'button', { name: 'Dismiss this notice' } ) .filter( { hasText: 'Draft saved' } ) ).toBeVisible(); + await page.reload(); // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); + await editor.switchToLegacyCanvas(); - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .click( { modifiers: [ 'Shift' ] } ); await pageUtils.pressKeys( 'primary+a' ); @@ -573,37 +559,42 @@ test.describe( 'Multi-block selection', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '12' ); await page.keyboard.press( 'ArrowLeft' ); - const [ coord1, coord2 ] = await editor.canvas.evaluate( () => { - const selection = window.getSelection(); - - if ( ! selection.rangeCount ) { - return; - } - - const range = selection.getRangeAt( 0 ); - const rect1 = range.getClientRects()[ 0 ]; - const element = document.querySelector( - '[data-type="core/paragraph"]' - ); - const rect2 = element.getBoundingClientRect(); - const iframeOffset = window.frameElement.getBoundingClientRect(); - - return [ - { - x: iframeOffset.x + rect1.x, - y: iframeOffset.y + rect1.y + rect1.height / 2, - }, - { - // Move a bit outside the paragraph. - x: iframeOffset.x + rect2.x - 5, - y: iframeOffset.y + rect2.y + rect2.height / 2, - }, - ]; - } ); + const [ coord1, coord2 ] = await editor.canvas + .locator( ':root' ) + .evaluate( () => { + const selection = window.getSelection(); + + if ( ! selection.rangeCount ) { + return; + } + + const range = selection.getRangeAt( 0 ); + const rect1 = range.getClientRects()[ 0 ]; + const element = document.querySelector( + '[data-type="core/paragraph"]' + ); + const rect2 = element.getBoundingClientRect(); + const iframeOffset = + window.frameElement.getBoundingClientRect(); + + return [ + { + x: iframeOffset.x + rect1.x, + y: iframeOffset.y + rect1.y + rect1.height / 2, + }, + { + // Move a bit outside the paragraph. + x: iframeOffset.x + rect2.x - 5, + y: iframeOffset.y + rect2.y + rect2.height / 2, + }, + ]; + } ); await page.mouse.click( coord1.x, coord1.y ); await page.mouse.down(); @@ -935,7 +926,9 @@ test.describe( 'Multi-block selection', () => { .toEqual( [] ); await expect .poll( () => - editor.canvas.evaluate( () => window.getSelection().toString() ) + editor.canvas + .locator( ':root' ) + .evaluate( () => window.getSelection().toString() ) ) .toBe( 'Post title' ); } ); @@ -1184,12 +1177,8 @@ test.describe( 'Multi-block selection', () => { editor, } ) => { // To do: run with iframe. - await page.evaluate( () => { - window.wp.blocks.registerBlockType( 'test/v2', { - apiVersion: '2', - title: 'test', - } ); - } ); + await editor.switchToLegacyCanvas(); + await editor.insertBlock( { name: 'core/paragraph', attributes: { content: '1[' }, @@ -1199,18 +1188,18 @@ test.describe( 'Multi-block selection', () => { attributes: { content: ']2' }, } ); // Focus and move the caret to the end. - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: ']2' } ) .click(); await page.keyboard.press( 'ArrowLeft' ); - const strongText = editor.canvas + const strongText = page .getByRole( 'region', { name: 'Editor content' } ) .getByText( '1', { exact: true } ); const strongBox = await strongText.boundingBox(); // Focus and move the caret to the end. - await editor.canvas + await page .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: '1[' } ) .click( { @@ -1354,9 +1343,9 @@ class MultiBlockSelectionUtils { * Tests if the native selection matches the block selection. */ assertNativeSelection = async () => { - const selection = await this.#editor.canvas.evaluateHandle( () => - window.getSelection() - ); + const selection = await this.#editor.canvas + .locator( ':root' ) + .evaluateHandle( () => window.getSelection() ); const { isMultiSelected, selectionStart, selectionEnd } = await this.#page.evaluate( () => { diff --git a/test/e2e/specs/editor/various/new-post.spec.js b/test/e2e/specs/editor/various/new-post.spec.js index 4b192693c07b0..9d6f4ef45d9db 100644 --- a/test/e2e/specs/editor/various/new-post.spec.js +++ b/test/e2e/specs/editor/various/new-post.spec.js @@ -74,10 +74,9 @@ test.describe( 'new editor state', () => { await admin.createNewPost(); // Enter a title for this post. - await editor.canvas.type( - 'role=textbox[name="Add title"i]', - 'Here is the title' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( 'Here is the title' ); // Save the post as a draft. await page.click( 'role=button[name="Save draft"i]' ); await page.waitForSelector( diff --git a/test/e2e/specs/editor/various/post-editor-template-mode.spec.js b/test/e2e/specs/editor/various/post-editor-template-mode.spec.js index 5d63ff789e4ec..629a437a41665 100644 --- a/test/e2e/specs/editor/various/post-editor-template-mode.spec.js +++ b/test/e2e/specs/editor/various/post-editor-template-mode.spec.js @@ -156,7 +156,6 @@ class PostEditorTemplateMode { async createPostAndSaveDraft() { await this.admin.createNewPost(); - await this.editor.canvas.waitForLoadState(); // Create a random post. await this.page.keyboard.type( 'Just an FSE Post' ); await this.page.keyboard.press( 'Enter' ); diff --git a/test/e2e/specs/editor/various/post-visibility.spec.js b/test/e2e/specs/editor/various/post-visibility.spec.js index 3f83221c27b81..365209ef2e4e5 100644 --- a/test/e2e/specs/editor/various/post-visibility.spec.js +++ b/test/e2e/specs/editor/various/post-visibility.spec.js @@ -78,7 +78,9 @@ test.describe( 'Post visibility', () => { await admin.createNewPost(); // Enter a title for this post. - await editor.canvas.type( 'role=textbox[name="Add title"i]', 'Title' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( 'Title' ); await editor.openDocumentSettingsSidebar(); diff --git a/test/e2e/specs/editor/various/preview.spec.js b/test/e2e/specs/editor/various/preview.spec.js index a3fa4544f39f8..cfec384adba9b 100644 --- a/test/e2e/specs/editor/various/preview.spec.js +++ b/test/e2e/specs/editor/various/preview.spec.js @@ -27,10 +27,9 @@ test.describe( 'Preview', () => { editorPage.locator( 'role=button[name="Preview"i]' ) ).toBeDisabled(); - await editor.canvas.type( - 'role=textbox[name="Add title"i]', - 'Hello World' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( 'Hello World' ); const previewPage = await editor.openPreviewPage( editorPage ); const previewTitle = previewPage.locator( 'role=heading[level=1]' ); @@ -48,7 +47,9 @@ test.describe( 'Preview', () => { // Return to editor to change title. await editorPage.bringToFront(); - await editor.canvas.type( 'role=textbox[name="Add title"i]', '!' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( '!' ); await previewUtils.waitForPreviewNavigation( previewPage ); // Title in preview should match updated input. @@ -70,10 +71,9 @@ test.describe( 'Preview', () => { // Return to editor to change title. await editorPage.bringToFront(); - await editor.canvas.fill( - 'role=textbox[name="Add title"i]', - 'Hello World! And more.' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .fill( 'Hello World! And more.' ); await previewUtils.waitForPreviewNavigation( previewPage ); // Title in preview should match updated input. @@ -109,7 +109,9 @@ test.describe( 'Preview', () => { const editorPage = page; // Type aaaaa in the title field. - await editor.canvas.type( 'role=textbox[name="Add title"]', 'aaaaa' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"]' ) + .type( 'aaaaa' ); await editorPage.keyboard.press( 'Tab' ); // Save the post as a draft. @@ -129,10 +131,9 @@ test.describe( 'Preview', () => { await editorPage.bringToFront(); // Append bbbbb to the title, and tab away from the title so blur event is triggered. - await editor.canvas.fill( - 'role=textbox[name="Add title"i]', - 'aaaaabbbbb' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .fill( 'aaaaabbbbb' ); await editorPage.keyboard.press( 'Tab' ); // Save draft and open the preview page right after. @@ -157,7 +158,9 @@ test.describe( 'Preview', () => { const editorPage = page; // Type Lorem in the title field. - await editor.canvas.type( 'role=textbox[name="Add title"i]', 'Lorem' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( 'Lorem' ); // Open the preview page. const previewPage = await editor.openPreviewPage( editorPage ); @@ -174,7 +177,9 @@ test.describe( 'Preview', () => { await page.click( 'role=button[name="Close panel"i]' ); // Change the title and preview again. - await editor.canvas.type( 'role=textbox[name="Add title"i]', ' Ipsum' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( ' Ipsum' ); await previewUtils.waitForPreviewNavigation( previewPage ); // Title in preview should match updated input. @@ -196,7 +201,9 @@ test.describe( 'Preview', () => { ).toBeVisible(); // Change the title. - await editor.canvas.type( 'role=textbox[name="Add title"i]', ' Draft' ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( ' Draft' ); // Open the preview page. await previewUtils.waitForPreviewNavigation( previewPage ); @@ -227,10 +234,9 @@ test.describe( 'Preview with Custom Fields enabled', () => { const editorPage = page; // Add an initial title and content. - await editor.canvas.type( - 'role=textbox[name="Add title"i]', - 'title 1' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .type( 'title 1' ); await editor.insertBlock( { name: 'core/paragraph', attributes: { content: 'content 1' }, @@ -254,14 +260,12 @@ test.describe( 'Preview with Custom Fields enabled', () => { // Return to editor and modify the title and content. await editorPage.bringToFront(); - await editor.canvas.fill( - 'role=textbox[name="Add title"i]', - 'title 2' - ); - await editor.canvas.fill( - 'role=document >> text="content 1"', - 'content 2' - ); + await editor.canvas + .locator( 'role=textbox[name="Add title"i]' ) + .fill( 'title 2' ); + await editor.canvas + .locator( 'role=document >> text="content 1"' ) + .fill( 'content 2' ); // Open the preview page. await previewUtils.waitForPreviewNavigation( previewPage ); diff --git a/test/e2e/specs/editor/various/rich-text.spec.js b/test/e2e/specs/editor/various/rich-text.spec.js index 4ebd2cd450e70..2969a33d25485 100644 --- a/test/e2e/specs/editor/various/rich-text.spec.js +++ b/test/e2e/specs/editor/various/rich-text.spec.js @@ -35,7 +35,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'test' ); await pageUtils.pressKeys( 'primary+a' ); await pageUtils.pressKeys( 'primary+b' ); @@ -53,7 +55,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Some ' ); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( 'bold' ); @@ -73,7 +77,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await pageUtils.pressKeys( 'primary+i' ); await page.keyboard.type( '1' ); @@ -102,11 +108,14 @@ test.describe( 'RichText', () => { await pageUtils.pressKeys( 'shift+ArrowLeft' ); await pageUtils.pressKeys( 'primary+b' ); - const count = await editor.canvas.evaluate( - () => - document.querySelectorAll( '*[data-rich-text-format-boundary]' ) - .length - ); + const count = await editor.canvas + .locator( ':root' ) + .evaluate( + () => + document.querySelectorAll( + '*[data-rich-text-format-boundary]' + ).length + ); expect( count ).toBe( 1 ); } ); @@ -114,7 +123,9 @@ test.describe( 'RichText', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'Some ' ); await editor.clickBlockToolbarButton( 'Bold' ); await page.keyboard.type( 'bold' ); @@ -134,7 +145,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'A `backtick`' ); expect( await editor.getBlocks() ).toMatchObject( [ @@ -155,7 +168,9 @@ test.describe( 'RichText', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '`a`' ); await page.keyboard.press( 'Backspace' ); @@ -171,7 +186,9 @@ test.describe( 'RichText', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '`a`' ); await page.keyboard.type( 'b' ); await page.keyboard.press( 'Backspace' ); @@ -184,7 +201,9 @@ test.describe( 'RichText', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '`a`' ); await page.evaluate( () => new Promise( window.requestIdleCallback ) ); // Move inside format boundary. @@ -200,7 +219,9 @@ test.describe( 'RichText', () => { page, editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'A `backtick` and more.' ); expect( await editor.getBlocks() ).toMatchObject( [ @@ -216,7 +237,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'A selection test.' ); await page.keyboard.press( 'Home' ); await page.keyboard.press( 'ArrowRight' ); @@ -246,14 +269,16 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '2' ); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '3' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { let called; const { body } = document; const config = { @@ -313,7 +338,7 @@ test.describe( 'RichText', () => { await page.keyboard.type( '4' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { // The selection change event should be called once. If there's only // one item in `window.unsubscribes`, it means that only one // function is present to disconnect the `mutationObserver`. @@ -339,7 +364,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '1' ); await pageUtils.pressKeys( 'primary+b' ); @@ -369,7 +396,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '12' ); await pageUtils.pressKeys( 'primary+b' ); @@ -391,7 +420,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await page.keyboard.press( 'Tab' ); await pageUtils.pressKeys( 'shift+Tab' ); @@ -412,11 +443,13 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); // Simulate moving focus to a different app, then moving focus back, // without selection being changed. - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { const activeElement = document.activeElement; activeElement.blur(); activeElement.focus(); @@ -443,7 +476,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( '2' ); @@ -479,7 +514,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '2' ); await pageUtils.pressKeys( 'primary+a' ); await pageUtils.pressKeys( 'primary+x' ); @@ -500,7 +537,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '2' ); @@ -525,7 +564,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'Backspace' ); @@ -545,7 +586,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '1' ); await page.keyboard.type( '2' ); @@ -571,7 +614,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); // Add text and select to color. await page.keyboard.type( '1' ); @@ -626,7 +671,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); // Create two lines of text in a paragraph. await page.keyboard.type( '1' ); await pageUtils.pressKeys( 'shift+Enter' ); @@ -668,7 +715,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); // Create an indented list of two lines. await page.keyboard.type( '* 1' ); @@ -717,7 +766,9 @@ test.describe( 'RichText', () => { } ); test( 'should navigate arround emoji', async ( { page, editor } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '🍓' ); // Only one press on arrow left should be required to move in front of // the emoji. @@ -735,12 +786,14 @@ test.describe( 'RichText', () => { test( 'should run input rules after composition end', async ( { editor, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); // Playwright doesn't support composition, so emulate it by inserting // text in the DOM directly, setting selection in the right place, and // firing `compositionend`. // See https://github.com/puppeteer/puppeteer/issues/4981. - await editor.canvas.evaluate( async () => { + await editor.canvas.locator( ':root' ).evaluate( async () => { document.activeElement.textContent = '`a`'; const selection = window.getSelection(); // The `selectionchange` and `compositionend` events should run in separate event @@ -767,7 +820,9 @@ test.describe( 'RichText', () => { editor, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( '1' ); await pageUtils.pressKeys( 'primary+b' ); diff --git a/test/e2e/specs/editor/various/rtl.spec.js b/test/e2e/specs/editor/various/rtl.spec.js index 8475605e339fc..aaf1186cc5aba 100644 --- a/test/e2e/specs/editor/various/rtl.spec.js +++ b/test/e2e/specs/editor/various/rtl.spec.js @@ -150,7 +150,9 @@ test.describe( 'RTL', () => { page, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await pageUtils.pressKeys( 'primary+b' ); await page.keyboard.type( ARABIC_ONE ); await pageUtils.pressKeys( 'primary+b' ); diff --git a/test/e2e/specs/editor/various/splitting-merging.spec.js b/test/e2e/specs/editor/various/splitting-merging.spec.js index 1c5e12be8abb1..29e7e5d64522c 100644 --- a/test/e2e/specs/editor/various/splitting-merging.spec.js +++ b/test/e2e/specs/editor/various/splitting-merging.spec.js @@ -4,8 +4,11 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); test.describe( 'splitting and merging blocks (@firefox, @webkit)', () => { - test.beforeEach( async ( { admin } ) => { + test.beforeEach( async ( { admin, editor } ) => { await admin.createNewPost(); + await expect( + editor.canvas.getByRole( 'textbox', { name: 'Add title' } ) + ).toBeFocused(); } ); test.afterEach( async ( { requestUtils } ) => { diff --git a/test/e2e/specs/editor/various/toolbar-roving-tabindex.spec.js b/test/e2e/specs/editor/various/toolbar-roving-tabindex.spec.js index 23186dfff2de9..e706dfc3607dc 100644 --- a/test/e2e/specs/editor/various/toolbar-roving-tabindex.spec.js +++ b/test/e2e/specs/editor/various/toolbar-roving-tabindex.spec.js @@ -79,7 +79,9 @@ test.describe( 'Toolbar roving tabindex', () => { // Move focus to the first toolbar item. await page.keyboard.press( 'Home' ); await ToolbarRovingTabindexUtils.expectLabelToHaveFocus( 'Table' ); - await editor.canvas.click( `role=button[name="Create Table"i]` ); + await editor.canvas + .locator( `role=button[name="Create Table"i]` ) + .click(); await pageUtils.pressKeys( 'Tab' ); await ToolbarRovingTabindexUtils.testBlockToolbarKeyboardNavigation( 'Body cell text', diff --git a/test/e2e/specs/editor/various/undo.spec.js b/test/e2e/specs/editor/various/undo.spec.js index dfdbef60ffaa9..51683997aaf6f 100644 --- a/test/e2e/specs/editor/various/undo.spec.js +++ b/test/e2e/specs/editor/various/undo.spec.js @@ -20,7 +20,9 @@ test.describe( 'undo', () => { pageUtils, undoUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'before pause' ); await editor.page.waitForTimeout( 1000 ); await page.keyboard.type( ' after pause' ); @@ -88,7 +90,9 @@ test.describe( 'undo', () => { pageUtils, undoUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'before keyboard ' ); await pageUtils.pressKeys( 'primary+b' ); @@ -160,7 +164,9 @@ test.describe( 'undo', () => { } ); test( 'should undo bold', async ( { page, pageUtils, editor } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'test' ); await page.click( 'role=button[name="Save draft"i]' ); await expect( @@ -169,8 +175,7 @@ test.describe( 'undo', () => { ) ).toBeVisible(); await page.reload(); - await page.waitForSelector( 'iframe[name="editor-canvas"]' ); - await editor.canvas.click( '[data-type="core/paragraph"]' ); + await editor.canvas.locator( '[data-type="core/paragraph"]' ).click(); await pageUtils.pressKeys( 'primary+a' ); await pageUtils.pressKeys( 'primary+b' ); await pageUtils.pressKeys( 'primary+z' ); @@ -190,7 +195,9 @@ test.describe( 'undo', () => { pageUtils, undoUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); const firstBlock = await editor.getEditedPostContent(); @@ -333,7 +340,9 @@ test.describe( 'undo', () => { // See: https://github.com/WordPress/gutenberg/issues/14950 // Issue is demonstrated from an edited post: create, save, and reload. - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( 'original' ); await page.click( 'role=button[name="Save draft"i]' ); await expect( @@ -342,11 +351,12 @@ test.describe( 'undo', () => { ) ).toBeVisible(); await page.reload(); - await page.waitForSelector( 'iframe[name="editor-canvas"]' ); // Issue is demonstrated by forcing state merges (multiple inputs) on // an existing text after a fresh reload. - await editor.canvas.click( '[data-type="core/paragraph"] >> nth=0' ); + await editor.canvas + .locator( '[data-type="core/paragraph"] >> nth=0' ) + .click(); await page.keyboard.type( 'modified' ); // The issue is demonstrated after the one second delay to trigger the @@ -370,7 +380,9 @@ test.describe( 'undo', () => { page, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await page.click( 'role=button[name="Save draft"i]' ); await expect( @@ -388,7 +400,9 @@ test.describe( 'undo', () => { page, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await editor.publishPost(); await pageUtils.pressKeys( 'primary+z' ); @@ -401,7 +415,9 @@ test.describe( 'undo', () => { page, pageUtils, } ) => { - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( '1' ); await page.click( 'role=button[name="Save draft"i]' ); @@ -416,7 +432,7 @@ test.describe( 'undo', () => { await expect( page.locator( 'role=button[name="Undo"]' ) ).toBeDisabled(); - await editor.canvas.click( '[data-type="core/paragraph"]' ); + await editor.canvas.locator( '[data-type="core/paragraph"]' ).click(); await page.keyboard.type( '2' ); @@ -446,7 +462,9 @@ test.describe( 'undo', () => { // block attribute as in the previous action and results in transient edits // and skipping `undo` history steps. const text = 'tonis'; - await editor.canvas.click( 'role=button[name="Add default block"i]' ); + await editor.canvas + .locator( 'role=button[name="Add default block"i]' ) + .click(); await page.keyboard.type( text ); await editor.publishPost(); await pageUtils.pressKeys( 'primary+z' ); diff --git a/test/e2e/specs/editor/various/writing-flow.spec.js b/test/e2e/specs/editor/various/writing-flow.spec.js index 81bbcbbc758b9..98bb00a596f03 100644 --- a/test/e2e/specs/editor/various/writing-flow.spec.js +++ b/test/e2e/specs/editor/various/writing-flow.spec.js @@ -10,8 +10,11 @@ test.use( { } ); test.describe( 'Writing Flow (@firefox, @webkit)', () => { - test.beforeEach( async ( { admin } ) => { + test.beforeEach( async ( { admin, editor } ) => { await admin.createNewPost(); + await expect( + editor.canvas.getByRole( 'textbox', { name: 'Add title' } ) + ).toBeFocused(); } ); test.afterAll( async ( { requestUtils } ) => { @@ -46,9 +49,11 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { .poll( writingFlowUtils.getActiveBlockName ) .toBe( 'core/column' ); await page.keyboard.press( 'ArrowUp' ); - const activeElementBlockType = await editor.canvas.evaluate( () => - document.activeElement.getAttribute( 'data-type' ) - ); + const activeElementBlockType = await editor.canvas + .locator( ':root' ) + .evaluate( () => + document.activeElement.getAttribute( 'data-type' ) + ); expect( activeElementBlockType ).toBe( 'core/columns' ); await expect .poll( writingFlowUtils.getActiveBlockName ) @@ -515,12 +520,12 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { } ) => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'Enter' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { document.activeElement.style.paddingTop = '100px'; } ); await page.keyboard.press( 'ArrowUp' ); await page.keyboard.type( '1' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { document.activeElement.style.paddingBottom = '100px'; } ); await page.keyboard.press( 'ArrowDown' ); @@ -544,7 +549,7 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { } ) => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'Enter' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { document.activeElement.style.lineHeight = 'normal'; } ); await page.keyboard.press( 'ArrowUp' ); @@ -745,7 +750,7 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { } ) => { await page.keyboard.press( 'Enter' ); await page.keyboard.press( 'Enter' ); - await editor.canvas.evaluate( () => { + await editor.canvas.locator( ':root' ).evaluate( () => { document.activeElement.style.paddingLeft = '100px'; } ); await page.keyboard.press( 'Enter' ); @@ -1015,9 +1020,9 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { await page.keyboard.type( 'a' ); async function getHeight() { - return await editor.canvas.evaluate( - () => document.activeElement.offsetHeight - ); + return await editor.canvas + .locator( ':root' ) + .evaluate( () => document.activeElement.offsetHeight ); } const height = await getHeight(); @@ -1049,9 +1054,9 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { await page.keyboard.type( 'a' ); async function getHeight() { - return await editor.canvas.evaluate( - () => document.activeElement.offsetHeight - ); + return await editor.canvas + .locator( ':root' ) + .evaluate( () => document.activeElement.offsetHeight ); } const height = await getHeight(); @@ -1084,9 +1089,9 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => { await page.keyboard.type( 'a' ); async function getHeight() { - return await editor.canvas.evaluate( - () => document.activeElement.offsetHeight - ); + return await editor.canvas + .locator( ':root' ) + .evaluate( () => document.activeElement.offsetHeight ); } const height = await getHeight(); @@ -1135,19 +1140,23 @@ class WritingFlowUtils { await this.page.keyboard.press( 'Enter' ); await this.page.keyboard.type( '/columns' ); await this.page.keyboard.press( 'Enter' ); - await this.editor.canvas.click( - 'role=button[name="Two columns; equal split"i]' - ); - await this.editor.canvas.click( 'role=button[name="Add block"i]' ); + await this.editor.canvas + .locator( 'role=button[name="Two columns; equal split"i]' ) + .click(); + await this.editor.canvas + .locator( 'role=button[name="Add block"i]' ) + .click(); await this.page.click( 'role=listbox[name="Blocks"i] >> role=option[name="Paragraph"i]' ); await this.page.keyboard.type( '1st col' ); // If this text is too long, it may wrap to a new line and cause test failure. That's why we're using "1st" instead of "First" here. - await this.editor.canvas.focus( - 'role=document[name="Block: Column (2 of 2)"i]' - ); - await this.editor.canvas.click( 'role=button[name="Add block"i]' ); + await this.editor.canvas + .locator( 'role=document[name="Block: Column (2 of 2)"i]' ) + .focus(); + await this.editor.canvas + .locator( 'role=button[name="Add block"i]' ) + .click(); await this.page.click( 'role=listbox[name="Blocks"i] >> role=option[name="Paragraph"i]' ); diff --git a/test/e2e/specs/interactivity/directive-init.spec.ts b/test/e2e/specs/interactivity/directive-init.spec.ts index aa81ab1ea61db..e18341a48fa3f 100644 --- a/test/e2e/specs/interactivity/directive-init.spec.ts +++ b/test/e2e/specs/interactivity/directive-init.spec.ts @@ -53,7 +53,7 @@ test.describe( 'data-wp-init', () => { await toggle.click(); - await expect( show ).not.toBeVisible(); + await expect( show ).toBeHidden(); await expect( isMounted ).toHaveText( 'false' ); } ); @@ -65,7 +65,7 @@ test.describe( 'data-wp-init', () => { await toggle.click(); - await expect( show ).not.toBeVisible(); + await expect( show ).toBeHidden(); await expect( isMounted ).toHaveText( 'false' ); await toggle.click(); diff --git a/test/e2e/specs/interactivity/directive-slots.spec.ts b/test/e2e/specs/interactivity/directive-slots.spec.ts index d93e50f767215..195af52fdb1bd 100644 --- a/test/e2e/specs/interactivity/directive-slots.spec.ts +++ b/test/e2e/specs/interactivity/directive-slots.spec.ts @@ -108,7 +108,7 @@ test.describe( 'data-wp-slot', () => { await page.getByTestId( 'slot-5-button' ).click(); await expect( fillContainer ).toBeEmpty(); - await expect( slot5 ).not.toBeVisible(); + await expect( slot5 ).toBeHidden(); await expect( slots.getByTestId( 'fill' ) ).toBeVisible(); await expect( slots.locator( 'css= > *' ) ).toHaveText( [ '[1]', diff --git a/test/e2e/specs/site-editor/block-removal.spec.js b/test/e2e/specs/site-editor/block-removal.spec.js index c1d6cdfea0022..5c46ac769efd3 100644 --- a/test/e2e/specs/site-editor/block-removal.spec.js +++ b/test/e2e/specs/site-editor/block-removal.spec.js @@ -17,7 +17,7 @@ test.describe( 'Site editor block removal prompt', () => { postId: 'emptytheme//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should appear when attempting to remove Query Block', async ( { diff --git a/test/e2e/specs/site-editor/command-center.spec.js b/test/e2e/specs/site-editor/command-center.spec.js index 9d22248bc2362..60c5ec30b1247 100644 --- a/test/e2e/specs/site-editor/command-center.spec.js +++ b/test/e2e/specs/site-editor/command-center.spec.js @@ -19,6 +19,7 @@ test.describe( 'Site editor command palette', () => { test( 'Open the command palette and navigate to the page create page', async ( { page, + editor, } ) => { await page .getByRole( 'button', { name: 'Open command palette' } ) @@ -26,13 +27,11 @@ test.describe( 'Site editor command palette', () => { await page.keyboard.press( 'Meta+k' ); await page.keyboard.type( 'new page' ); await page.getByRole( 'option', { name: 'Add new page' } ).click(); - await page.waitForSelector( 'iframe[name="editor-canvas"]' ); - const frame = page.frame( 'editor-canvas' ); await expect( page ).toHaveURL( '/wp-admin/post-new.php?post_type=page' ); await expect( - frame.getByRole( 'textbox', { name: 'Add title' } ) + editor.canvas.getByRole( 'textbox', { name: 'Add title' } ) ).toBeVisible(); } ); diff --git a/test/e2e/specs/site-editor/font-library.spec.js b/test/e2e/specs/site-editor/font-library.spec.js index e6521cb7c540b..6aca027a30e78 100644 --- a/test/e2e/specs/site-editor/font-library.spec.js +++ b/test/e2e/specs/site-editor/font-library.spec.js @@ -14,7 +14,7 @@ test.describe( 'Font Library', () => { postId: 'emptytheme//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should display the "Manage Fonts" icon', async ( { page } ) => { @@ -39,7 +39,7 @@ test.describe( 'Font Library', () => { postId: 'twentytwentythree//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should display the "Manage Fonts" icon', async ( { page } ) => { diff --git a/test/e2e/specs/site-editor/global-styles-sidebar.spec.js b/test/e2e/specs/site-editor/global-styles-sidebar.spec.js index 02717f1b19432..f255640cb2f12 100644 --- a/test/e2e/specs/site-editor/global-styles-sidebar.spec.js +++ b/test/e2e/specs/site-editor/global-styles-sidebar.spec.js @@ -17,7 +17,7 @@ test.describe( 'Global styles sidebar', () => { postId: 'emptytheme//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should filter blocks list results', async ( { page } ) => { diff --git a/test/e2e/specs/site-editor/hybrid-theme.spec.js b/test/e2e/specs/site-editor/hybrid-theme.spec.js index 060daf508491a..7c9f3fc3a5e23 100644 --- a/test/e2e/specs/site-editor/hybrid-theme.spec.js +++ b/test/e2e/specs/site-editor/hybrid-theme.spec.js @@ -40,7 +40,7 @@ test.describe( 'Hybrid theme', () => { page.getByRole( 'region', { name: 'Editor content' } ) ).toBeVisible(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await expect( editor.canvas.getByRole( 'document', { diff --git a/test/e2e/specs/site-editor/iframe-rendering.spec.js b/test/e2e/specs/site-editor/iframe-rendering.spec.js index 02389cc936f06..4391f134a9f80 100644 --- a/test/e2e/specs/site-editor/iframe-rendering.spec.js +++ b/test/e2e/specs/site-editor/iframe-rendering.spec.js @@ -14,16 +14,15 @@ test.describe( 'Site editor iframe rendering mode', () => { test( 'Should render editor in standards mode.', async ( { admin, - page, + editor, } ) => { await admin.visitSiteEditor( { postId: 'emptytheme//index', postType: 'wp_template', } ); - - const compatMode = await page - .locator( 'iframe[name="editor-canvas"]' ) - .evaluate( ( iframe ) => iframe.contentDocument.compatMode ); + const compatMode = await editor.canvas + .locator( ':root' ) + .evaluate( () => document.compatMode ); // CSS1Compat = expected standards mode. // BackCompat = quirks mode. diff --git a/test/e2e/specs/site-editor/list-view.spec.js b/test/e2e/specs/site-editor/list-view.spec.js index 3057feaf7772b..ed64574168bd0 100644 --- a/test/e2e/specs/site-editor/list-view.spec.js +++ b/test/e2e/specs/site-editor/list-view.spec.js @@ -18,7 +18,7 @@ test.describe( 'Site Editor List View', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should open by default when preference is enabled', async ( { @@ -105,7 +105,7 @@ test.describe( 'Site Editor List View', () => { // Since focus is now inside the list view, the shortcut should close // the sidebar. await pageUtils.pressKeys( 'access+o' ); - await expect( listView ).not.toBeVisible(); + await expect( listView ).toBeHidden(); // Focus should now be on the list view toggle button. await expect( @@ -129,7 +129,7 @@ test.describe( 'Site Editor List View', () => { } ) ).toBeFocused(); await pageUtils.pressKeys( 'access+o' ); - await expect( listView ).not.toBeVisible(); + await expect( listView ).toBeHidden(); await expect( page.getByRole( 'button', { name: 'List View' } ) ).toBeFocused(); diff --git a/test/e2e/specs/site-editor/multi-entity-saving.spec.js b/test/e2e/specs/site-editor/multi-entity-saving.spec.js index b4d2f1dbda0d0..bb062aafa3e7f 100644 --- a/test/e2e/specs/site-editor/multi-entity-saving.spec.js +++ b/test/e2e/specs/site-editor/multi-entity-saving.spec.js @@ -23,7 +23,7 @@ test.describe( 'Site Editor - Multi-entity save flow', () => { postId: 'emptytheme//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'save flow should work as expected', async ( { editor, page } ) => { diff --git a/test/e2e/specs/site-editor/push-to-global-styles.spec.js b/test/e2e/specs/site-editor/push-to-global-styles.spec.js index 937b2aea0fb45..9507245c192d2 100644 --- a/test/e2e/specs/site-editor/push-to-global-styles.spec.js +++ b/test/e2e/specs/site-editor/push-to-global-styles.spec.js @@ -17,7 +17,7 @@ test.describe( 'Push to Global Styles button', () => { postId: 'emptytheme//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should apply Heading block styles to all Heading blocks', async ( { diff --git a/test/e2e/specs/site-editor/site-editor-inserter.spec.js b/test/e2e/specs/site-editor/site-editor-inserter.spec.js index f8ab0a534d858..98cb8e4e74149 100644 --- a/test/e2e/specs/site-editor/site-editor-inserter.spec.js +++ b/test/e2e/specs/site-editor/site-editor-inserter.spec.js @@ -18,7 +18,7 @@ test.describe( 'Site Editor Inserter', () => { test.beforeEach( async ( { admin, editor } ) => { await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'inserter toggle button should toggle global inserter', async ( { diff --git a/test/e2e/specs/site-editor/style-book.spec.js b/test/e2e/specs/site-editor/style-book.spec.js index eeaa1270f3ff9..08f5e6463ebc7 100644 --- a/test/e2e/specs/site-editor/style-book.spec.js +++ b/test/e2e/specs/site-editor/style-book.spec.js @@ -20,7 +20,7 @@ test.describe( 'Style Book', () => { test.beforeEach( async ( { admin, editor, styleBook, page } ) => { await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await styleBook.open(); await expect( page.locator( 'role=region[name="Style Book"i]' ) @@ -30,16 +30,16 @@ test.describe( 'Style Book', () => { test( 'should disable toolbar buttons when open', async ( { page } ) => { await expect( page.locator( 'role=button[name="Toggle block inserter"i]' ) - ).not.toBeVisible(); + ).toBeHidden(); await expect( page.locator( 'role=button[name="Tools"i]' ) - ).not.toBeVisible(); + ).toBeHidden(); await expect( page.locator( 'role=button[name="Undo"i]' ) - ).not.toBeVisible(); + ).toBeHidden(); await expect( page.locator( 'role=button[name="Redo"i]' ) - ).not.toBeVisible(); + ).toBeHidden(); await expect( page.locator( 'role=button[name="View"i]' ) ).toBeDisabled(); @@ -139,7 +139,7 @@ test.describe( 'Style Book', () => { await expect( styleBookRegion, 'should close when close button is clicked' - ).not.toBeVisible(); + ).toBeHidden(); // Open Style Book again. await page.getByRole( 'button', { name: 'Style Book' } ).click(); @@ -153,7 +153,7 @@ test.describe( 'Style Book', () => { await expect( styleBookRegion, 'should close when Escape key is pressed' - ).not.toBeVisible(); + ).toBeHidden(); } ); } ); diff --git a/test/e2e/specs/site-editor/style-variations.spec.js b/test/e2e/specs/site-editor/style-variations.spec.js index ee71e856269b0..8868c73300668 100644 --- a/test/e2e/specs/site-editor/style-variations.spec.js +++ b/test/e2e/specs/site-editor/style-variations.spec.js @@ -39,7 +39,7 @@ test.describe( 'Global styles variations', () => { postId: 'gutenberg-test-themes/style-variations//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await siteEditorStyleVariations.browseStyles(); @@ -76,7 +76,7 @@ test.describe( 'Global styles variations', () => { postId: 'gutenberg-test-themes/style-variations//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await siteEditorStyleVariations.browseStyles(); await page.click( 'role=button[name="pink"i]' ); await page.click( @@ -117,7 +117,7 @@ test.describe( 'Global styles variations', () => { postId: 'gutenberg-test-themes/style-variations//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await siteEditorStyleVariations.browseStyles(); await page.click( 'role=button[name="yellow"i]' ); await page.click( @@ -164,7 +164,7 @@ test.describe( 'Global styles variations', () => { postId: 'gutenberg-test-themes/style-variations//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await siteEditorStyleVariations.browseStyles(); await page.click( 'role=button[name="pink"i]' ); await page.click( @@ -196,15 +196,16 @@ test.describe( 'Global styles variations', () => { postId: 'gutenberg-test-themes/style-variations//index', postType: 'wp_template', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await siteEditorStyleVariations.browseStyles(); await page.click( 'role=button[name="yellow"i]' ); - const frame = page.frame( 'editor-canvas' ); - const paragraph = frame.locator( 'text="My awesome paragraph"' ); + const paragraph = editor.canvas.locator( + 'text="My awesome paragraph"' + ); await expect( paragraph ).toHaveCSS( 'color', 'rgb(25, 25, 17)' ); - const body = frame.locator( 'css=body' ); + const body = editor.canvas.locator( 'css=body' ); await expect( body ).toHaveCSS( 'background-color', 'rgb(255, 239, 11)' diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index cd81a616b1fee..d1c215ec2a494 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -28,11 +28,13 @@ test.describe( 'Template Part', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Insert a new template block and 'start blank'. await editor.insertBlock( { name: 'core/template-part' } ); - await editor.canvas.click( 'role=button[name="Start blank"i]' ); + await editor.canvas + .locator( 'role=button[name="Start blank"i]' ) + .click(); // Fill in a name in the dialog that pops up. await page.type( 'role=dialog >> role=textbox[name="Name"i]', 'New' ); @@ -56,7 +58,7 @@ test.describe( 'Template Part', () => { } ) => { // Visit the index. await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); const headerTemplateParts = editor.canvas.locator( '[data-type="core/template-part"]' ); @@ -66,7 +68,7 @@ test.describe( 'Template Part', () => { // Insert a new template block and choose an existing header pattern. await editor.insertBlock( { name: 'core/template-part' } ); - await editor.canvas.click( 'role=button[name="Choose"i]' ); + await editor.canvas.locator( 'role=button[name="Choose"i]' ).click(); await page.click( 'role=listbox[name="Block Patterns"i] >> role=option[name="header"i]' ); @@ -83,7 +85,7 @@ test.describe( 'Template Part', () => { const paragraphText = 'Test 2'; await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Add a block and select it. await editor.insertBlock( { name: 'core/paragraph', @@ -108,7 +110,7 @@ test.describe( 'Template Part', () => { // Check that the header contains the paragraph added earlier. const templatePartWithParagraph = editor.canvas.locator( '[data-type="core/template-part"]', - { has: paragraphBlock } + { hasText: paragraphText } ); await expect( templatePartWithParagraph ).toBeVisible(); @@ -123,7 +125,7 @@ test.describe( 'Template Part', () => { const paragraphText2 = 'Test 4'; await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Add a block and select it. await editor.insertBlock( { name: 'core/paragraph', @@ -158,11 +160,11 @@ test.describe( 'Template Part', () => { // Check that the header contains the paragraph added earlier. const templatePartWithParagraph1 = editor.canvas.locator( '[data-type="core/template-part"]', - { has: paragraphBlock1 } + { hasText: paragraphText1 } ); const templatePartWithParagraph2 = editor.canvas.locator( '[data-type="core/template-part"]', - { has: paragraphBlock2 } + { hasText: paragraphText2 } ); // TODO: I couldn't find an easy way to assert that the same template @@ -185,7 +187,7 @@ test.describe( 'Template Part', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await editor.insertBlock( { name: 'core/paragraph', attributes: { @@ -196,14 +198,14 @@ test.describe( 'Template Part', () => { // Visit the index. await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Check that the header contains the paragraph added earlier. const paragraph = editor.canvas.locator( `p >> text="${ paragraphText }"` ); const templatePartWithParagraph = editor.canvas.locator( '[data-type="core/template-part"]', - { has: paragraph } + { hasText: paragraphText } ); await expect( templatePartWithParagraph ).toBeVisible(); @@ -215,7 +217,7 @@ test.describe( 'Template Part', () => { // There should be a paragraph but no header template part. await expect( paragraph ).toBeVisible(); - await expect( templatePartWithParagraph ).not.toBeVisible(); + await expect( templatePartWithParagraph ).toBeHidden(); } ); test( 'shows changes in a template when a template part it contains is modified', async ( { @@ -228,7 +230,7 @@ test.describe( 'Template Part', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Edit the header. await editor.insertBlock( { name: 'core/paragraph', @@ -241,7 +243,7 @@ test.describe( 'Template Part', () => { // Visit the index. await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); const paragraph = editor.canvas.locator( `p >> text="${ paragraphText }"` ); @@ -261,7 +263,7 @@ test.describe( 'Template Part', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await editor.insertBlock( { name: 'core/paragraph', attributes: { @@ -300,7 +302,7 @@ test.describe( 'Template Part', () => { page, } ) => { await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Add a block and select it. await editor.insertBlock( { @@ -341,7 +343,7 @@ test.describe( 'Template Part', () => { page, } ) => { await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Select existing header template part. await editor.selectBlocks( @@ -355,7 +357,7 @@ test.describe( 'Template Part', () => { // Verify that the widget area import button is not there. await expect( page.getByRole( 'combobox', { name: 'Import widget area' } ) - ).not.toBeVisible(); + ).toBeHidden(); } ); test( 'Keeps focus in place on undo in template parts', async ( { @@ -368,7 +370,7 @@ test.describe( 'Template Part', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Select the site title block. const siteTitle = editor.canvas.getByRole( 'document', { diff --git a/test/e2e/specs/site-editor/template-revert.spec.js b/test/e2e/specs/site-editor/template-revert.spec.js index c8edc034901a2..c281b71d16a18 100644 --- a/test/e2e/specs/site-editor/template-revert.spec.js +++ b/test/e2e/specs/site-editor/template-revert.spec.js @@ -23,7 +23,7 @@ test.describe( 'Template Revert', () => { test.beforeEach( async ( { admin, requestUtils, editor } ) => { await requestUtils.deleteAllTemplates( 'wp_template' ); await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); } ); test( 'should delete the template after saving the reverted template', async ( { @@ -55,7 +55,7 @@ test.describe( 'Template Revert', () => { page.locator( 'role=region[name="Editor settings"i] >> role=button[name="Actions"i]' ) - ).not.toBeVisible(); + ).toBeHidden(); } ); test( 'should show the original content after revert', async ( { @@ -277,7 +277,7 @@ test.describe( 'Template Revert', () => { await editor.saveSiteEditorEntities(); await admin.visitSiteEditor(); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); const contentAfter = await templateRevertUtils.getCurrentSiteEditorContent(); expect( contentAfter ).toEqual( contentBefore ); diff --git a/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js b/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js index a7ecebfd9ed44..61fbf7c795a60 100644 --- a/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js +++ b/test/e2e/specs/site-editor/user-global-styles-revisions.spec.js @@ -31,7 +31,7 @@ test.describe( 'Global styles revisions', () => { editor, userGlobalStylesRevisions, } ) => { - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); const currentRevisions = await userGlobalStylesRevisions.getGlobalStylesRevisions(); await userGlobalStylesRevisions.openStylesPanel(); @@ -66,7 +66,7 @@ test.describe( 'Global styles revisions', () => { editor, userGlobalStylesRevisions, } ) => { - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await userGlobalStylesRevisions.openStylesPanel(); await page.getByRole( 'button', { name: 'Colors styles' } ).click(); await page @@ -110,7 +110,7 @@ test.describe( 'Global styles revisions', () => { editor, userGlobalStylesRevisions, } ) => { - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); await userGlobalStylesRevisions.openStylesPanel(); await userGlobalStylesRevisions.openRevisions(); const lastRevisionButton = page diff --git a/test/e2e/specs/site-editor/writing-flow.spec.js b/test/e2e/specs/site-editor/writing-flow.spec.js index f9681a5ea2d46..8ee6ce0e56557 100644 --- a/test/e2e/specs/site-editor/writing-flow.spec.js +++ b/test/e2e/specs/site-editor/writing-flow.spec.js @@ -24,7 +24,7 @@ test.describe( 'Site editor writing flow', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Select the first site title block. const siteTitleBlock = editor.canvas.locator( 'role=document[name="Block: Site Title"i]' @@ -52,7 +52,7 @@ test.describe( 'Site editor writing flow', () => { postId: 'emptytheme//header', postType: 'wp_template_part', } ); - await editor.canvas.click( 'body' ); + await editor.canvas.locator( 'body' ).click(); // Make sure the sidebar is open. await editor.openDocumentSettingsSidebar(); diff --git a/test/e2e/specs/widgets/customizing-widgets.spec.js b/test/e2e/specs/widgets/customizing-widgets.spec.js index e771c92fc24ee..6a6a51cae2686 100644 --- a/test/e2e/specs/widgets/customizing-widgets.spec.js +++ b/test/e2e/specs/widgets/customizing-widgets.spec.js @@ -36,11 +36,7 @@ test.describe( 'Widgets Customizer', () => { await requestUtils.activateTheme( 'twentytwentyone' ); } ); - test( 'should add blocks', async ( { - page, - widgetsCustomizerPage, - editor, - } ) => { + test( 'should add blocks', async ( { page, widgetsCustomizerPage } ) => { const previewFrame = widgetsCustomizerPage.previewFrame; await widgetsCustomizerPage.visitCustomizerPage(); @@ -86,9 +82,11 @@ test.describe( 'Widgets Customizer', () => { await page.click( 'role=option[name="Search"i]' ); - await editor.canvas.focus( - 'role=document[name="Block: Search"i] >> role=textbox[name="Label text"i]' - ); + await page + .locator( + 'role=document[name="Block: Search"i] >> role=textbox[name="Label text"i]' + ) + .focus(); await page.keyboard.type( 'My ' ); @@ -233,7 +231,6 @@ test.describe( 'Widgets Customizer', () => { page, requestUtils, widgetsCustomizerPage, - editor, } ) => { await requestUtils.addWidgetBlock( `\nFirst Paragraph
\n`, @@ -282,7 +279,7 @@ test.describe( 'Widgets Customizer', () => { await headingWidget.click(); // noop click on the widget text to unfocus the editor and hide toolbar await editHeadingWidget.click(); - const headingBlock = editor.canvas.locator( + const headingBlock = page.locator( 'role=document[name="Block: Heading"i] >> text="First Heading"' ); await expect( headingBlock ).toBeFocused(); @@ -586,13 +583,12 @@ test.describe( 'Widgets Customizer', () => { test( 'preserves content in the Custom HTML block', async ( { page, widgetsCustomizerPage, - editor, } ) => { await widgetsCustomizerPage.visitCustomizerPage(); await widgetsCustomizerPage.expandWidgetArea( 'Footer #1' ); await widgetsCustomizerPage.addBlock( 'Custom HTML' ); - const HTMLBlockTextarea = editor.canvas.locator( + const HTMLBlockTextarea = page.locator( 'role=document[name="Block: Custom HTML"i] >> role=textbox[name="HTML"i]' ); await HTMLBlockTextarea.type( 'hello' ); From 5735a49a1cf5647125872b658464d949e50b4290 Mon Sep 17 00:00:00 2001 From: Dave SmithHello+ + + + + " + ` ); + } ); } ); diff --git a/packages/block-library/src/verse/test/edit.native.js b/packages/block-library/src/verse/test/edit.native.js index c91c261c89c35..8794419775d32 100644 --- a/packages/block-library/src/verse/test/edit.native.js +++ b/packages/block-library/src/verse/test/edit.native.js @@ -78,4 +78,41 @@ describe( 'Verse block', () => { " ` ); } ); + + it( 'should split on triple Enter', async () => { + // Arrange + const screen = await initializeEditor(); + await addBlock( screen, 'Verse' ); + + // Act + const verseTextInput = + await screen.findByPlaceholderText( 'Write verse…' ); + typeInRichText( verseTextInput, 'Hello' ); + fireEvent( verseTextInput, 'onKeyDown', { + nativeEvent: {}, + preventDefault() {}, + keyCode: ENTER, + } ); + fireEvent( verseTextInput, 'onKeyDown', { + nativeEvent: {}, + preventDefault() {}, + keyCode: ENTER, + } ); + fireEvent( verseTextInput, 'onKeyDown', { + nativeEvent: {}, + preventDefault() {}, + keyCode: ENTER, + } ); + + // Assert + expect( getEditorHtml() ).toMatchInlineSnapshot( ` + " +
Hello+ + + + + " + ` ); + } ); } ); diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index 9316c4693cfaa..600f855ba0ec1 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -10,6 +10,7 @@ For each user feature we should also add a importance categorization label to i --> ## Unreleased +- [*] Exit Preformatted and Verse blocks by triple pressing the Return key [#53354] ## 1.105.0 - [*] Limit inner blocks nesting depth to avoid call stack size exceeded crash [#54382] From b8b89cecd6b6e274d70867d9d0dd7acd005be3e5 Mon Sep 17 00:00:00 2001 From: Bart Kalisz
@ringbearer +thebetterhobbit
-` ); + + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/paragraph', + attributes: { content: '@ringbearer +thebetterhobbit' }, + }, + ] ); } ); test( 'should hide UI when selection changes (by keyboard)', async ( { From ae5761b0b44ee86974e1ae87f65e46551ff50e84 Mon Sep 17 00:00:00 2001 From: Riad BenguellaNested modal content
+Hello WordPress!
', + 'expected_markup' => '/^Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'link element styles with serialization skipped' => array(
+ 'color_settings' => array(
+ 'link' => true,
+ '__experimentalSkipSerialization' => true,
+ ),
+ 'elements_styles' => array(
+ 'link' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'heading element styles with serialization skipped' => array(
+ 'color_settings' => array(
+ 'heading' => true,
+ '__experimentalSkipSerialization' => true,
+ ),
+ 'elements_styles' => array(
+ 'heading' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'button element styles apply class to wrapper' => array(
+ 'color_settings' => array( 'button' => true ),
+ 'elements_styles' => array(
+ 'button' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'link element styles apply class to wrapper' => array(
+ 'color_settings' => array( 'link' => true ),
+ 'elements_styles' => array(
+ 'link' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'heading element styles apply class to wrapper' => array(
+ 'color_settings' => array( 'heading' => true ),
+ 'elements_styles' => array(
+ 'heading' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'element styles apply class to wrapper when it has other classes' => array(
+ 'color_settings' => array( 'link' => true ),
+ 'elements_styles' => array(
+ 'link' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress! Hello WordPress<\/a>!<\/p>$/',
+ ),
+ 'element styles apply class to wrapper when it has other attributes' => array(
+ 'color_settings' => array( 'link' => true ),
+ 'elements_styles' => array(
+ 'link' => array( 'color' => $color_styles ),
+ ),
+ 'block_markup' => ' Hello WordPress!