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 Mar 5, 2019
1 parent 29b3dc5 commit 546b667
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 27 deletions.
52 changes: 29 additions & 23 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Clicks on More Menu item, searches for the button with the text provided and cli

### createEmbeddingMatcher

[src/index.js#L46-L46](src/index.js#L46-L46)
[src/index.js#L47-L47](src/index.js#L47-L47)

Creates a function to determine if a request is embedding a certain URL.

Expand All @@ -92,7 +92,7 @@ Creates a function to determine if a request is embedding a certain URL.

### createJSONResponse

[src/index.js#L46-L46](src/index.js#L46-L46)
[src/index.js#L47-L47](src/index.js#L47-L47)

Respond to a request with a JSON response.

Expand Down Expand Up @@ -131,7 +131,7 @@ Creates new URL by parsing base URL, WPPath and query string.

### createURLMatcher

[src/index.js#L46-L46](src/index.js#L46-L46)
[src/index.js#L47-L47](src/index.js#L47-L47)

Creates a function to determine if a request is calling a URL with the substring present.

Expand Down Expand Up @@ -302,7 +302,7 @@ Performs log in with specified username and password.

### mockOrTransform

[src/index.js#L46-L46](src/index.js#L46-L46)
[src/index.js#L47-L47](src/index.js#L47-L47)

Mocks a request with the supplied mock object, or allows it to run with an optional transform, based on the
deserialised JSON response for the request.
Expand Down Expand Up @@ -330,15 +330,21 @@ event occurs without a related target (i.e. focus loss).

Clicks on the button in the header which opens Document Settings sidebar when it is closed.

### openPublishPanel
### openGlobalInserter

[src/index.js#L27-L27](src/index.js#L27-L27)

Opens the global inserter

### openPublishPanel

[src/index.js#L28-L28](src/index.js#L28-L28)

Opens the publish panel.

### pressKeyTimes

[src/index.js#L28-L28](src/index.js#L28-L28)
[src/index.js#L29-L29](src/index.js#L29-L29)

Presses the given keyboard key a number of times in sequence.

Expand All @@ -353,7 +359,7 @@ Presses the given keyboard key a number of times in sequence.

### pressKeyWithModifier

[src/index.js#L29-L29](src/index.js#L29-L29)
[src/index.js#L30-L30](src/index.js#L30-L30)

Performs a key press with modifier (Shift, Control, Meta, Alt), where each modifier
is normalized to platform-specific modifier.
Expand All @@ -365,7 +371,7 @@ is normalized to platform-specific modifier.

### publishPost

[src/index.js#L30-L30](src/index.js#L30-L30)
[src/index.js#L31-L31](src/index.js#L31-L31)

Publishes the post, resolving once the request is complete (once a notice
is displayed).
Expand All @@ -376,7 +382,7 @@ is displayed).

### publishPostWithPrePublishChecksDisabled

[src/index.js#L31-L31](src/index.js#L31-L31)
[src/index.js#L32-L32](src/index.js#L32-L32)

Publishes the post without the pre-publish checks,
resolving once the request is complete (once a notice is displayed).
Expand All @@ -387,7 +393,7 @@ resolving once the request is complete (once a notice is displayed).

### saveDraft

[src/index.js#L32-L32](src/index.js#L32-L32)
[src/index.js#L33-L33](src/index.js#L33-L33)

Saves the post as a draft, resolving once the request is complete (once the
"Saved" indicator is displayed).
Expand All @@ -398,7 +404,7 @@ Saves the post as a draft, resolving once the request is complete (once the

### searchForBlock

[src/index.js#L33-L33](src/index.js#L33-L33)
[src/index.js#L34-L34](src/index.js#L34-L34)

Search for block in the global inserter

Expand All @@ -408,7 +414,7 @@ Search for block in the global inserter

### selectBlockByClientId

[src/index.js#L34-L34](src/index.js#L34-L34)
[src/index.js#L35-L35](src/index.js#L35-L35)

Given the clientId of a block, selects the block on the editor.

Expand All @@ -418,7 +424,7 @@ Given the clientId of a block, selects the block on the editor.

### setBrowserViewport

[src/index.js#L35-L35](src/index.js#L35-L35)
[src/index.js#L36-L36](src/index.js#L36-L36)

Sets browser viewport to specified type.

Expand All @@ -428,7 +434,7 @@ Sets browser viewport to specified type.

### setPostContent

[src/index.js#L36-L36](src/index.js#L36-L36)
[src/index.js#L37-L37](src/index.js#L37-L37)

Sets code editor content

Expand All @@ -442,7 +448,7 @@ Sets code editor content

### setUpResponseMocking

[src/index.js#L46-L46](src/index.js#L46-L46)
[src/index.js#L47-L47](src/index.js#L47-L47)

Sets up mock checks and responses. Accepts a list of mock settings with the following properties:

Expand Down Expand Up @@ -473,7 +479,7 @@ If none of the mock settings match the request, the request is allowed to contin

### switchEditorModeTo

[src/index.js#L37-L37](src/index.js#L37-L37)
[src/index.js#L38-L38](src/index.js#L38-L38)

Switches editor mode.

Expand All @@ -483,21 +489,21 @@ Switches editor mode.

### switchUserToAdmin

[src/index.js#L38-L38](src/index.js#L38-L38)
[src/index.js#L39-L39](src/index.js#L39-L39)

Switches the current user to the admin user (if the user
running the test is not already the admin user).

### switchUserToTest

[src/index.js#L39-L39](src/index.js#L39-L39)
[src/index.js#L40-L40](src/index.js#L40-L40)

Switches the current user to whichever user we should be
running the tests as (if we're not already that user).

### toggleScreenOption

[src/index.js#L40-L40](src/index.js#L40-L40)
[src/index.js#L41-L41](src/index.js#L41-L41)

Toggles the screen option with the given label.

Expand All @@ -508,7 +514,7 @@ Toggles the screen option with the given label.

### transformBlockTo

[src/index.js#L41-L41](src/index.js#L41-L41)
[src/index.js#L42-L42](src/index.js#L42-L42)

Converts editor's block type.

Expand All @@ -518,7 +524,7 @@ Converts editor's block type.

### uninstallPlugin

[src/index.js#L42-L42](src/index.js#L42-L42)
[src/index.js#L43-L43](src/index.js#L43-L43)

Uninstalls a plugin.

Expand All @@ -528,7 +534,7 @@ Uninstalls a plugin.

### visitAdminPage

[src/index.js#L43-L43](src/index.js#L43-L43)
[src/index.js#L44-L44](src/index.js#L44-L44)

Visits admin page; if user is not logged in then it logging in it first, then visits admin page.

Expand All @@ -539,7 +545,7 @@ Visits admin page; if user is not logged in then it logging in it first, then vi

### waitForWindowDimensions

[src/index.js#L44-L44](src/index.js#L44-L44)
[src/index.js#L45-L45](src/index.js#L45-L45)

Function that waits until the page viewport has the required dimensions.
It is being used to address a problem where after using setViewport the execution may continue,
Expand Down
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",
]
`;
Loading

0 comments on commit 546b667

Please sign in to comment.