Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a test for #9326 #9454

Merged
merged 1 commit into from
Sep 25, 2018
Merged
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
44 changes: 44 additions & 0 deletions test/e2e/specs/convert-block-type.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Internal dependencies
*/
import {
getEditedPostContent,
newPost,
insertBlock,
} from '../support/utils';

describe( 'Code block', () => {
beforeEach( async () => {
await newPost();
} );

it( 'should convert to a preformatted block', async () => {
const code = 'print "Hello Dolly!"';

await insertBlock( 'Code' );

await page.type( '.editor-block-list__block textarea', code );

// Verify the content starts as a Code block.
const originalPostContent = await getEditedPostContent();
const codeRegex = new RegExp( `<!-- wp:code -->\\s*<pre class="wp-block-code"><code>${ code }<\\/code><\\/pre>\\s*<!-- \\/wp:code -->` );
tofumatt marked this conversation as resolved.
Show resolved Hide resolved

expect( originalPostContent ).toMatch( codeRegex );

// Hover over this block to show its toolbar so we can click on the block
// conversion button.
const insertionPoint = await page.$( '.editor-block-list__block-edit' );
Copy link
Member Author

Choose a reason for hiding this comment

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

This could stand to be a helper too, just let me know. 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeas, please. We use it in a few places with a different implementation.

const rect = await insertionPoint.boundingBox();
await page.mouse.move( rect.x + ( rect.width / 2 ), rect.y + ( rect.height / 2 ), { steps: 10 } );

// Convert this block to a Preformatted block.
await page.click( '.editor-block-switcher__toggle' );
await page.click( '.editor-block-types-list__item[aria-label="Preformatted"]' );

// The content should now be a Preformatted block with no data loss.
const convertedPostContent = await getEditedPostContent();
const preformattedRegex = new RegExp( `<!-- wp:preformatted -->\\s*<pre class="wp-block-preformatted">${ code }<\\/pre>\\s*<!-- \\/wp:preformatted -->` );

expect( convertedPostContent ).toMatch( preformattedRegex );
} );
} );