From 7ac72b73a33384912844303748d04cf3c1b3a52d Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 12 Mar 2019 14:49:38 +0000 Subject: [PATCH] Fix: Regression: Template lock option is not taken into consideration; Add: end to end tests; --- packages/e2e-tests/plugins/cpt-locking.php | 56 +++++++++++ .../__snapshots__/cpt-locking.test.js.snap | 57 +++++++++++ .../specs/plugins/cpt-locking.test.js | 99 +++++++++++++++++++ .../editor/src/components/provider/index.js | 15 +-- 4 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 packages/e2e-tests/plugins/cpt-locking.php create mode 100644 packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap create mode 100644 packages/e2e-tests/specs/plugins/cpt-locking.test.js diff --git a/packages/e2e-tests/plugins/cpt-locking.php b/packages/e2e-tests/plugins/cpt-locking.php new file mode 100644 index 0000000000000..ba8a8d611c428 --- /dev/null +++ b/packages/e2e-tests/plugins/cpt-locking.php @@ -0,0 +1,56 @@ + 'Add a description', + ), + ), + array( 'core/quote' ), + ); + register_post_type( + 'locked-all-post', + array( + 'public' => true, + 'label' => 'Locked All Post', + 'show_in_rest' => true, + 'template' => $template, + 'template_lock' => 'all', + ) + ); + register_post_type( + 'locked-insert-post', + array( + 'public' => true, + 'label' => 'Locked Insert Post', + 'show_in_rest' => true, + 'template' => $template, + 'template_lock' => 'insert', + ) + ); + register_post_type( + 'not-locked-post', + array( + 'public' => true, + 'label' => 'Not Locked Post', + 'show_in_rest' => true, + 'template' => $template, + 'template_lock' => false, + ) + ); +} + +add_action( 'init', 'gutenberg_test_cpt_locking' ); diff --git a/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap new file mode 100644 index 0000000000000..de467ce40d3e8 --- /dev/null +++ b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = ` +" +
\\"\\"/
+ + + +

+ + + +

+ + + + +" +`; + +exports[`cpt locking template_lock false should allow blocks to be moved 1`] = ` +" +

p1

+ + + +
\\"\\"/
+ + + +

+" +`; + +exports[`cpt locking template_lock false should allow blocks to be removed 1`] = ` +" +
\\"\\"/
+ + + +

+" +`; + +exports[`cpt locking template_lock insert should allow blocks to be moved 1`] = ` +" +

p1

+ + + +
\\"\\"/
+ + + +

+" +`; diff --git a/packages/e2e-tests/specs/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/plugins/cpt-locking.test.js new file mode 100644 index 0000000000000..2a858b8a5c849 --- /dev/null +++ b/packages/e2e-tests/specs/plugins/cpt-locking.test.js @@ -0,0 +1,99 @@ +/** + * WordPress dependencies + */ +import { + activatePlugin, + clickBlockToolbarButton, + createNewPost, + deactivatePlugin, + getEditedPostContent, + insertBlock, +} from '@wordpress/e2e-test-utils'; + +describe( 'cpt locking', () => { + beforeAll( async () => { + await activatePlugin( 'gutenberg-test-plugin-cpt-locking' ); + } ); + + afterAll( async () => { + await deactivatePlugin( 'gutenberg-test-plugin-cpt-locking' ); + } ); + + const shouldRemoveTheInserter = async () => { + expect( + await page.$( '.edit-post-header [aria-label="Add block"]' ) + ).toBeNull(); + }; + + const shouldNotAllowBlocksToBeRemoved = async () => { + await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' ); + await clickBlockToolbarButton( 'More options' ); + expect( + await page.$x( '//button[contains(text(), "Remove Block")]' ) + ).toHaveLength( 0 ); + }; + + const shouldAllowBlocksToBeMoved = async () => { + await page.click( '.editor-rich-text__editable.wp-block-paragraph' ); + expect( + await page.$( 'button[aria-label="Move up"]' ) + ).not.toBeNull(); + await page.click( 'button[aria-label="Move up"]' ); + await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' ); + expect( await getEditedPostContent() ).toMatchSnapshot(); + }; + + describe( 'template_lock all', () => { + beforeEach( async () => { + await createNewPost( { postType: 'locked-all-post' } ); + } ); + + it( 'should remove the inserter', shouldRemoveTheInserter ); + + it( 'should not allow blocks to be removed', shouldNotAllowBlocksToBeRemoved ); + + it( 'should not allow blocks to be moved', async () => { + await page.click( '.editor-rich-text__editable.wp-block-paragraph' ); + expect( + await page.$( 'button[aria-label="Move up"]' ) + ).toBeNull(); + } ); + } ); + + describe( 'template_lock insert', () => { + beforeEach( async () => { + await createNewPost( { postType: 'locked-insert-post' } ); + } ); + + it( 'should remove the inserter', shouldRemoveTheInserter ); + + it( 'should not allow blocks to be removed', shouldNotAllowBlocksToBeRemoved ); + + it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); + } ); + + describe( 'template_lock false', () => { + beforeEach( async () => { + await createNewPost( { postType: 'not-locked-post' } ); + } ); + + it( 'should allow blocks to be inserted', async () => { + expect( + await page.$( '.edit-post-header [aria-label="Add block"]' ) + ).not.toBeNull(); + await insertBlock( 'List' ); + await page.keyboard.type( 'List content' ); + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + + it( 'should allow blocks to be removed', async () => { + await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' ); + await clickBlockToolbarButton( 'More options' ); + const [ removeBlock ] = await page.$x( '//button[contains(text(), "Remove Block")]' ); + await removeBlock.click(); + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + + it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved ); + } ); +} ); diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 14ead7919501f..8ced0e95422c2 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -55,20 +55,21 @@ class EditorProvider extends Component { return { ...pick( settings, [ 'alignWide', + 'allowedBlockTypes', 'availableLegacyWidgets', + 'bodyPlaceholder', 'colors', 'disableCustomColors', - 'fontSizes', 'disableCustomFontSizes', - 'imageSizes', - 'maxWidth', - 'allowedBlockTypes', + 'focusMode', + 'fontSizes', 'hasFixedToolbar', 'hasPermissionsToManageWidgets', - 'focusMode', - 'styles', + 'imageSizes', 'isRTL', - 'bodyPlaceholder', + 'maxWidth', + 'styles', + 'templateLock', 'titlePlaceholder', ] ), __experimentalMetaSource: {