-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: End 2 end test global block inserter restrictions
- Loading branch information
1 parent
bc06562
commit f7ffd84
Showing
5 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
packages/e2e-tests/specs/__snapshots__/inserter.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); | ||
} ); |