Skip to content

Commit

Permalink
Add: End 2 end test global block inserter restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Feb 22, 2019
1 parent bc06562 commit f7ffd84
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 4 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 @@ -24,6 +24,7 @@ export { isCurrentURL } from './is-current-url';
export { loginUser } from './login-user';
export { observeFocusLoss } from './observe-focus-loss';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
export { openGlobalInserter } from './open-global-inserter';
export { openPublishPanel } from './open-publish-panel';
export { pressKeyTimes } from './press-key-times';
export { pressKeyWithModifier } from './press-key-with-modifier';
Expand Down
9 changes: 9 additions & 0 deletions packages/e2e-test-utils/src/open-global-inserter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Opens the global inserter
*/
export async function openGlobalInserter() {
await page.click( '.edit-post-header [aria-label="Add block"]' );
// Waiting here is necessary because sometimes the inserter takes more time to
// render than Puppeteer takes to complete the 'click' action
await page.waitForSelector( '.editor-inserter__menu' );
}
10 changes: 6 additions & 4 deletions packages/e2e-test-utils/src/search-for-block.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* Internal dependencies
*/
import { openGlobalInserter } from './open-global-inserter';

/**
* Search for block in the global inserter
*
* @param {string} searchTerm The text to search the inserter for.
*/
export async function searchForBlock( searchTerm ) {
await page.click( '.edit-post-header [aria-label="Add block"]' );
// Waiting here is necessary because sometimes the inserter takes more time to
// render than Puppeteer takes to complete the 'click' action
await page.waitForSelector( '.editor-inserter__menu' );
await openGlobalInserter();
await page.keyboard.type( searchTerm );
}
83 changes: 83 additions & 0 deletions packages/e2e-tests/specs/__snapshots__/inserter.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Inserter all blocks should appear 1`] = `
Array [
"Amazon Kindle",
"Animoto",
"Archives",
"Audio",
"Button",
"Calendar",
"Categories",
"Classic",
"Cloudup",
"Code",
"CollegeHumor",
"Columns",
"Cover",
"Crowdsignal",
"Custom HTML",
"Dailymotion",
"Embed",
"Facebook",
"File",
"Flickr",
"Gallery",
"Heading",
"Hulu",
"Image",
"Imgur",
"Inline Image",
"Instagram",
"Issuu",
"Kickstarter",
"Latest Comments",
"Latest Posts",
"List",
"Media & Text",
"Meetup.com",
"Mixcloud",
"More",
"Page Break",
"Paragraph",
"Preformatted",
"Pullquote",
"Quote",
"RSS",
"Reddit",
"ReverbNation",
"Screencast",
"Scribd",
"Search",
"Separator",
"Shortcode",
"Slideshare",
"SmugMug",
"SoundCloud",
"Spacer",
"Speaker Deck",
"Spotify",
"TED",
"Table",
"Tag Cloud",
"Tumblr",
"Twitter",
"Verse",
"Video",
"VideoPress",
"Vimeo",
"WordPress",
"WordPress.tv",
"YouTube",
]
`;

exports[`Inserter media & text block should restrict allowed blocks 1`] = `
Array [
"Button",
"Heading",
"Inline Image",
"List",
"Paragraph",
]
`;
68 changes: 68 additions & 0 deletions packages/e2e-tests/specs/inserter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import { sortBy, uniq } from 'lodash';

/**
* WordPress dependencies
*/
import {
createNewPost,
insertBlock,
openGlobalInserter,
} from '@wordpress/e2e-test-utils';

describe( 'Inserter', () => {
const openAllInserterCategories = async () => {
const notOpenCategoryPanels = await page.$$(
'.editor-inserter__results .components-panel__body:not(.is-opened)'
);
for ( const categoryPanel of notOpenCategoryPanels ) {
await categoryPanel.click();
}
};

const getAllInserterItemTitles = async () => {
const inserterItemTitles = await page.evaluate( () => {
return Array.from(
document.querySelectorAll(
'.editor-inserter__results .editor-block-types-list__item-title'
)
).map(
( inserterItem ) => {
return inserterItem.innerText;
}
);
} );
return sortBy( uniq( inserterItemTitles ) );
};

beforeEach( async () => {
await createNewPost();
} );

it( 'all blocks should appear', async () => {
await page.click( '.editor-default-block-appender' );
await openGlobalInserter();
await openAllInserterCategories();
expect( await getAllInserterItemTitles() ).toMatchSnapshot();
} );

it( 'media & text block should restrict allowed blocks', async () => {
await insertBlock( 'Media & Text' );
await page.click( '.wp-block-media-text .editor-rich-text' );
await openGlobalInserter();
await openAllInserterCategories();
expect( await getAllInserterItemTitles() ).toMatchSnapshot();
} );

it( 'no blocks should be allowed inside columns', async () => {
await insertBlock( 'Columns' );
await page.click( '[aria-label="Block Navigation"]' );
const columnBlockMenuItem = ( await page.$x( '//button[contains(concat(" ", @class, " "), " editor-block-navigation__item-button ")][text()="Column"]' ) )[ 0 ];
await columnBlockMenuItem.click();
await openGlobalInserter();
await openAllInserterCategories();
expect( await getAllInserterItemTitles() ).toHaveLength( 0 );
} );
} );

0 comments on commit f7ffd84

Please sign in to comment.