Skip to content

Commit

Permalink
Add: End to end test to make sure when all blocks get removed the def…
Browse files Browse the repository at this point in the history
…ault block appender gets inserter and selected
  • Loading branch information
jorgefilipecosta committed Mar 1, 2019
1 parent 535e075 commit ca8f61f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { hasBlockSwitcher } from './has-block-switcher';
export { insertBlock } from './insert-block';
export { installPlugin } from './install-plugin';
export { isCurrentURL } from './is-current-url';
export { isInDefaultBlock } from './is-in-default-block';
export { loginUser } from './login-user';
export { observeFocusLoss } from './observe-focus-loss';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
Expand Down
15 changes: 15 additions & 0 deletions packages/e2e-test-utils/src/is-in-default-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Checks if the block that is focused is the default block.
*
* @return {Promise} Promise resolving with a boolean indicating if the focused block is the default block.
*/
export function isInDefaultBlock() {
return page.evaluate( () => {
const activeBlockName = document.activeElement
.closest( '[data-type]' )
.getAttribute( 'data-type' );
const defaultBlockName = window.wp.blocks.getDefaultBlockName();

return activeBlockName === defaultBlockName;
} );
}
22 changes: 22 additions & 0 deletions packages/e2e-tests/specs/block-deletion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
clickBlockAppender,
getEditedPostContent,
createNewPost,
isInDefaultBlock,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';

Expand Down Expand Up @@ -109,3 +110,24 @@ describe( 'block deletion -', () => {
} );
} );
} );

describe( 'deleting all blocks', () => {
it( 'results in the default block getting selected', async () => {
await createNewPost();
await clickBlockAppender();
await page.keyboard.type( 'Paragraph' );

await page.keyboard.press( 'Escape' );

await clickOnBlockSettingsMenuItem( 'Remove Block' );

// There is a default block:
expect( await page.$$( '.editor-block-list__block' ) ).toHaveLength( 1 );

// But the effective saved content is still empty:
expect( await getEditedPostContent() ).toBe( '' );

// And focus is retained:
expect( await isInDefaultBlock() ).toBe( true );
} );
} );
12 changes: 2 additions & 10 deletions packages/e2e-tests/specs/splitting-merging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
createNewPost,
insertBlock,
isInDefaultBlock,
getEditedPostContent,
pressKeyTimes,
pressKeyWithModifier,
Expand Down Expand Up @@ -199,15 +200,6 @@ describe( 'splitting and merging blocks', () => {
expect( await getEditedPostContent() ).toBe( '' );

// And focus is retained:
const isInDefaultBlock = await page.evaluate( () => {
const activeBlockName = document.activeElement
.closest( '[data-type]' )
.getAttribute( 'data-type' );
const defaultBlockName = window.wp.blocks.getDefaultBlockName();

return activeBlockName === defaultBlockName;
} );

expect( isInDefaultBlock ).toBe( true );
expect( await isInDefaultBlock() ).toBe( true );
} );
} );

0 comments on commit ca8f61f

Please sign in to comment.