Skip to content

Commit

Permalink
Migrate Heading block tests to Playwright (#47955)
Browse files Browse the repository at this point in the history
* Migrate Heading block tests to Playwright

* Open document settings before color tests

* Use the new recommended method

* Update remaining assertions
  • Loading branch information
Mamaduka authored Feb 10, 2023
1 parent 59a6178 commit 9b1f1af
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 164 deletions.

This file was deleted.

113 changes: 0 additions & 113 deletions packages/e2e-tests/specs/editor/blocks/heading.test.js

This file was deleted.

182 changes: 182 additions & 0 deletions test/e2e/specs/editor/blocks/heading.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Heading', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'can be created by prefixing number sign and a space', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '### 3' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: { content: '3', level: 3 },
},
] );
} );

test( 'can be created by prefixing existing content with number signs and a space', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '4' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.type( '#### ' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: { content: '4', level: 4 },
},
] );
} );

test( 'should not work with the list input rule', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '## 1. H' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: { content: '1. H', level: 2 },
},
] );
} );

test( 'should work with the format input rules', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '## `code`' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: { content: '<code>code</code>', level: 2 },
},
] );
} );

test( 'should create a paragraph block above when pressing enter at the start', async ( {
editor,
page,
} ) => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '## a' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'Enter' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: { content: '' },
},
{
name: 'core/heading',
attributes: { content: 'a', level: 2 },
},
] );
} );

test( 'should create a paragraph block below when pressing enter at the end', async ( {
editor,
page,
} ) => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '## a' );
await page.keyboard.press( 'Enter' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: { content: 'a', level: 2 },
},
{
name: 'core/paragraph',
attributes: { content: '' },
},
] );
} );

test( 'should correctly apply custom colors', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '### Heading' );
await editor.openDocumentSettingsSidebar();

const textColor = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'button', { name: 'Text' } );

await textColor.click();
await page
.getByRole( 'button', { name: /Custom color picker./i } )
.click();

await page
.getByRole( 'textbox', { name: 'Hex color' } )
.fill( '4b7f4d' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: {
content: 'Heading',
level: 3,
style: { color: { text: '#4b7f4d' } },
},
},
] );
} );

test( 'should correctly apply named colors', async ( { editor, page } ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '## Heading' );
await editor.openDocumentSettingsSidebar();

const textColor = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'button', { name: 'Text' } );

await textColor.click();

await page
.getByRole( 'button', {
name: 'Color: Luminous vivid orange',
} )
.click();

// Close the popover.
await textColor.click();

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/heading',
attributes: {
content: 'Heading',
level: 2,
textColor: 'luminous-vivid-orange',
},
},
] );
} );
} );

1 comment on commit 9b1f1af

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9b1f1af.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4144538258
📝 Reported issues:

Please sign in to comment.