Skip to content

Commit

Permalink
Fix copy paste and delete error core paragraph with locking (#14712)
Browse files Browse the repository at this point in the history
* Fix: Copy / Paste error core/paragraph with locking

* Add test case.

* Update packages/block-library/src/paragraph/edit.js

Co-Authored-By: jorgefilipecosta <[email protected]>
  • Loading branch information
jorgefilipecosta authored Apr 30, 2019
1 parent 0b2eb1c commit 447dd27
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ class ParagraphBlock extends Component {
} }
unstableOnSplit={ this.splitBlock }
onMerge={ mergeBlocks }
onReplace={ this.onReplace }
onRemove={ () => onReplace( [] ) }
onReplace={ this.props.onReplace && this.onReplace }
onRemove={ onReplace && ( () => onReplace( [] ) ) }
aria-label={ content ? __( 'Paragraph block' ) : __( 'Empty block; start writing or type forward slash to choose a block' ) }
placeholder={ placeholder || __( 'Start writing or type / to choose a block' ) }
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cpt locking template_lock all should not error when deleting the cotents of a paragraph 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
`;
exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
Expand Down
9 changes: 9 additions & 0 deletions packages/e2e-tests/specs/plugins/cpt-locking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
deactivatePlugin,
getEditedPostContent,
insertBlock,
pressKeyTimes,
} from '@wordpress/e2e-test-utils';

describe( 'cpt locking', () => {
Expand Down Expand Up @@ -58,6 +59,14 @@ describe( 'cpt locking', () => {
await page.$( 'button[aria-label="Move up"]' )
).toBeNull();
} );

it( 'should not error when deleting the cotents of a paragraph', async () => {
await page.click( '.block-editor-block-list__block[data-type="core/paragraph"] p' );
const textToType = 'Paragraph';
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Backspace', textToType.length + 1 );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

describe( 'template_lock insert', () => {
Expand Down

0 comments on commit 447dd27

Please sign in to comment.