Skip to content

Commit

Permalink
Migrate 'block-locking' to Playwright (#41050)
Browse files Browse the repository at this point in the history
* Migrate 'block-locking' to Playwright
* Use correct utility method
  • Loading branch information
Mamaduka authored May 18, 2022
1 parent a754e08 commit b499487
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 120 deletions.
120 changes: 0 additions & 120 deletions packages/e2e-tests/specs/editor/various/block-locking.test.js

This file was deleted.

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

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

test.describe( 'General', () => {
test( 'can prevent removal', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'Some paragraph' );

await editor.clickBlockOptionsMenuItem( 'Lock' );

await page.click( 'role=checkbox[name="Prevent removal"]' );
await page.click( 'role=button[name="Apply"]' );

await expect(
page.locator( 'role=menuitem[name="Remove Paragraph"]' )
).not.toBeVisible();
} );

test( 'can disable movement', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'First paragraph' );

await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'Second paragraph' );

await editor.clickBlockOptionsMenuItem( 'Lock' );

await page.click( 'role=checkbox[name="Disable movement"]' );
await page.click( 'role=button[name="Apply"]' );

// Hide options.
await editor.clickBlockToolbarButton( 'Options' );

// Drag handle is hidden.
await expect(
page.locator( 'role=button[name="Drag"]' )
).not.toBeVisible();

// Movers are hidden. No need to check for both.
await expect(
page.locator( 'role=button[name="Move up"]' )
).not.toBeVisible();
} );

test( 'can lock everything', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'Some paragraph' );

await editor.clickBlockOptionsMenuItem( 'Lock' );

await page.click( 'role=checkbox[name="Lock all"]' );
await page.click( 'role=button[name="Apply"]' );

expect( await editor.getEditedPostContent() )
.toBe( `<!-- wp:paragraph {"lock":{"move":true,"remove":true}} -->
<p>Some paragraph</p>
<!-- /wp:paragraph -->` );
} );

test( 'can unlock from toolbar', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'Some paragraph' );

await editor.clickBlockOptionsMenuItem( 'Lock' );

await page.click( 'role=checkbox[name="Lock all"]' );
await page.click( 'role=button[name="Apply"]' );

await editor.clickBlockToolbarButton( 'Unlock Paragraph' );
await page.click( 'role=checkbox[name="Lock all"]' );
await page.click( 'role=button[name="Apply"]' );

expect( await editor.getEditedPostContent() )
.toBe( `<!-- wp:paragraph {"lock":{"move":false,"remove":false}} -->
<p>Some paragraph</p>
<!-- /wp:paragraph -->` );
} );
} );
} );

0 comments on commit b499487

Please sign in to comment.