Skip to content

Commit

Permalink
Add: Generic end 2 end test to the block transforms. (#12336)
Browse files Browse the repository at this point in the history
## Description
This is a second try on PR #10536, after a recommendation by @gziolo to try to make the PR smaller so it becomes easier to review.
In order to make the PR smaller, I temporarily created a list of test fixtures that intersects with the set of all fixtures so most fixtures are ignored. Another PR will follow that corrects the fixtures (mainly media ones) so they are reliable and can be used in this tests (e.g: don't trigger 404 requests).
All the mechanisms are present in this PR the only change that will happen in the other PR is the removal of the intersection and its list, the update of some media fixtures and the creation of new snapshots.

This is a high-level test that is going to Guarantee that every possible transform on Gutenberg is tested and works as expected (the result matches the save snapshot).

## How has this been tested?
Verify all test cases pass.
  • Loading branch information
jorgefilipecosta authored Mar 22, 2019
1 parent 3f28c95 commit f4de109
Show file tree
Hide file tree
Showing 6 changed files with 612 additions and 34 deletions.
83 changes: 49 additions & 34 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Clicks on More Menu item, searches for the button with the text provided and cli

### createEmbeddingMatcher

[src/index.js#L51-L51](src/index.js#L51-L51)
[src/index.js#L52-L52](src/index.js#L52-L52)

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

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

### createJSONResponse

[src/index.js#L51-L51](src/index.js#L51-L51)
[src/index.js#L52-L52](src/index.js#L52-L52)

Respond to a request with a JSON response.

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

### createURLMatcher

[src/index.js#L51-L51](src/index.js#L51-L51)
[src/index.js#L52-L52](src/index.js#L52-L52)

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

Expand Down Expand Up @@ -251,10 +251,25 @@ that the current selected block can be transformed into.

`Promise`: Promise resolving with an array containing all possible block transforms

### getEditedPostContent
### getBlockSetting

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

Returns a string containing the block title associated with the provided block name.

**Parameters**

- **blockName** `string`: Block name.
- **setting** `string`: Block setting e.g: title, attributes....

**Returns**

`Promise`: Promise resolving with a string containing the block title.

### getEditedPostContent

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

Returns a promise which resolves with the edited post content (HTML string).

**Returns**
Expand All @@ -263,7 +278,7 @@ Returns a promise which resolves with the edited post content (HTML string).

### hasBlockSwitcher

[src/index.js#L22-L22](src/index.js#L22-L22)
[src/index.js#L23-L23](src/index.js#L23-L23)

Returns a boolean indicating if the current selected block has a block switcher or not.

Expand All @@ -273,7 +288,7 @@ Returns a boolean indicating if the current selected block has a block switcher

### insertBlock

[src/index.js#L23-L23](src/index.js#L23-L23)
[src/index.js#L24-L24](src/index.js#L24-L24)

Opens the inserter, searches for the given term, then selects the first
result that appears.
Expand All @@ -285,7 +300,7 @@ result that appears.

### installPlugin

[src/index.js#L24-L24](src/index.js#L24-L24)
[src/index.js#L25-L25](src/index.js#L25-L25)

Installs a plugin from the WP.org repository.

Expand All @@ -296,7 +311,7 @@ Installs a plugin from the WP.org repository.

### isCurrentURL

[src/index.js#L25-L25](src/index.js#L25-L25)
[src/index.js#L26-L26](src/index.js#L26-L26)

Checks if current URL is a WordPress path.

Expand All @@ -311,7 +326,7 @@ Checks if current URL is a WordPress path.

### isInDefaultBlock

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

Checks if the block that is focused is the default block.

Expand All @@ -321,7 +336,7 @@ Checks if the block that is focused is the default block.

### loginUser

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

Performs log in with specified username and password.

Expand All @@ -332,7 +347,7 @@ Performs log in with specified username and password.

### mockOrTransform

[src/index.js#L51-L51](src/index.js#L51-L51)
[src/index.js#L52-L52](src/index.js#L52-L52)

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 All @@ -349,38 +364,38 @@ deserialised JSON response for the request.

### observeFocusLoss

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

Binds to the document on page load which throws an error if a `focusout`
event occurs without a related target (i.e. focus loss).

### openAllBlockInserterCategories

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

Opens all block inserter categories.

### openDocumentSettingsSidebar

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

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

### openGlobalBlockInserter

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

Opens the global block inserter.

### openPublishPanel

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

Opens the publish panel.

### pressKeyTimes

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

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

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

### pressKeyWithModifier

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

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

### publishPost

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

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

### publishPostWithPrePublishChecksDisabled

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

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

### saveDraft

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

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

### searchForBlock

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

Search for block in the global inserter

Expand All @@ -450,7 +465,7 @@ Search for block in the global inserter

### selectBlockByClientId

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

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

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

### setBrowserViewport

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

Sets browser viewport to specified type.

Expand All @@ -470,7 +485,7 @@ Sets browser viewport to specified type.

### setPostContent

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

Sets code editor content

Expand All @@ -484,7 +499,7 @@ Sets code editor content

### setUpResponseMocking

[src/index.js#L51-L51](src/index.js#L51-L51)
[src/index.js#L52-L52](src/index.js#L52-L52)

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

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

### switchEditorModeTo

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

Switches editor mode.

Expand All @@ -525,21 +540,21 @@ Switches editor mode.

### switchUserToAdmin

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

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

### switchUserToTest

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

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#L45-L45](src/index.js#L45-L45)
[src/index.js#L46-L46](src/index.js#L46-L46)

Toggles the screen option with the given label.

Expand All @@ -550,7 +565,7 @@ Toggles the screen option with the given label.

### transformBlockTo

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

Converts editor's block type.

Expand All @@ -560,7 +575,7 @@ Converts editor's block type.

### uninstallPlugin

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

Uninstalls a plugin.

Expand All @@ -570,7 +585,7 @@ Uninstalls a plugin.

### visitAdminPage

[src/index.js#L48-L48](src/index.js#L48-L48)
[src/index.js#L49-L49](src/index.js#L49-L49)

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

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

### waitForWindowDimensions

[src/index.js#L49-L49](src/index.js#L49-L49)
[src/index.js#L50-L50](src/index.js#L50-L50)

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
13 changes: 13 additions & 0 deletions packages/e2e-test-utils/src/get-block-setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Returns a string containing the block title associated with the provided block name.
* @param {string} blockName Block name.
* @param {string} setting Block setting e.g: title, attributes....
*
* @return {Promise} Promise resolving with a string containing the block title.
*/
export async function getBlockSetting( blockName, setting ) {
return page.evaluate( ( _blockName, _setting ) => {
const blockType = wp.data.select( 'core/blocks' ).getBlockType( _blockName );
return blockType && blockType[ _setting ];
}, blockName, setting );
}
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 @@ -18,6 +18,7 @@ export { findSidebarPanelWithTitle } from './find-sidebar-panel-with-title';
export { getAllBlockInserterItemTitles } from './get-all-block-inserter-item-titles';
export { getAllBlocks } from './get-all-blocks';
export { getAvailableBlockTransforms } from './get-available-block-transforms';
export { getBlockSetting } from './get-block-setting';
export { getEditedPostContent } from './get-edited-post-content';
export { hasBlockSwitcher } from './has-block-switcher';
export { insertBlock } from './insert-block';
Expand Down
Loading

0 comments on commit f4de109

Please sign in to comment.