@wordpress/e2e-test-utils-playwright 1.48.0 → 1.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/admin/create-new-post.js +31 -0
- package/build/admin/create-new-post.js.map +1 -0
- package/build/admin/edit-post.js +20 -0
- package/build/admin/edit-post.js.map +1 -0
- package/{src/admin/get-page-error.ts → build/admin/get-page-error.js} +9 -12
- package/build/admin/get-page-error.js.map +1 -0
- package/build/admin/index.js +40 -0
- package/build/admin/index.js.map +1 -0
- package/build/admin/visit-admin-page.js +32 -0
- package/build/admin/visit-admin-page.js.map +1 -0
- package/build/admin/visit-site-editor.js +45 -0
- package/build/admin/visit-site-editor.js.map +1 -0
- package/build/admin/wait-for-site-editor.js +41 -0
- package/build/admin/wait-for-site-editor.js.map +1 -0
- package/build/config.js +13 -0
- package/build/config.js.map +1 -0
- package/build/editor/click-block-options-menu-item.js +17 -0
- package/build/editor/click-block-options-menu-item.js.map +1 -0
- package/build/editor/click-block-toolbar-button.js +16 -0
- package/build/editor/click-block-toolbar-button.js.map +1 -0
- package/build/editor/get-blocks.js +45 -0
- package/build/editor/get-blocks.js.map +1 -0
- package/build/editor/get-edited-post-content.js +15 -0
- package/build/editor/get-edited-post-content.js.map +1 -0
- package/build/editor/index.js +75 -0
- package/build/editor/index.js.map +1 -0
- package/build/editor/insert-block.js +23 -0
- package/build/editor/insert-block.js.map +1 -0
- package/build/editor/open-document-settings-sidebar.js +27 -0
- package/build/editor/open-document-settings-sidebar.js.map +1 -0
- package/build/editor/preview.js +21 -0
- package/build/editor/preview.js.map +1 -0
- package/build/editor/publish-post.js +45 -0
- package/build/editor/publish-post.js.map +1 -0
- package/build/editor/save-draft.js +18 -0
- package/build/editor/save-draft.js.map +1 -0
- package/build/editor/select-blocks.js +28 -0
- package/build/editor/select-blocks.js.map +1 -0
- package/build/editor/set-content.js +17 -0
- package/build/editor/set-content.js.map +1 -0
- package/build/editor/set-is-fixed-toolbar.js +18 -0
- package/build/editor/set-is-fixed-toolbar.js.map +1 -0
- package/build/editor/set-preferences.js +21 -0
- package/build/editor/set-preferences.js.map +1 -0
- package/build/editor/show-block-toolbar.js +19 -0
- package/build/editor/show-block-toolbar.js.map +1 -0
- package/build/editor/site-editor.js +44 -0
- package/build/editor/site-editor.js.map +1 -0
- package/build/editor/switch-editor-tool.js +33 -0
- package/build/editor/switch-editor-tool.js.map +1 -0
- package/build/editor/switch-to-legacy-canvas.js +18 -0
- package/build/editor/switch-to-legacy-canvas.js.map +1 -0
- package/build/editor/transform-block-to.js +24 -0
- package/build/editor/transform-block-to.js.map +1 -0
- package/build/index.js +19 -0
- package/build/index.js.map +1 -0
- package/build/lighthouse/index.js +61 -0
- package/build/lighthouse/index.js.map +1 -0
- package/build/metrics/index.js +314 -0
- package/build/metrics/index.js.map +1 -0
- package/build/page-utils/drag-files.js +119 -0
- package/build/page-utils/drag-files.js.map +1 -0
- package/build/page-utils/emulate-network-conditions.js +71 -0
- package/build/page-utils/emulate-network-conditions.js.map +1 -0
- package/build/page-utils/index.js +37 -0
- package/build/page-utils/index.js.map +1 -0
- package/build/page-utils/is-current-url.js +21 -0
- package/build/page-utils/is-current-url.js.map +1 -0
- package/build/page-utils/keycodes.js +41 -0
- package/build/page-utils/keycodes.js.map +1 -0
- package/build/page-utils/press-keys.js +141 -0
- package/build/page-utils/press-keys.js.map +1 -0
- package/{src → build}/page-utils/set-browser-viewport.js +12 -14
- package/build/page-utils/set-browser-viewport.js.map +1 -0
- package/build/request-utils/blocks.js +40 -0
- package/build/request-utils/blocks.js.map +1 -0
- package/build/request-utils/comments.js +52 -0
- package/build/request-utils/comments.js.map +1 -0
- package/build/request-utils/gutenberg-experiments.js +47 -0
- package/build/request-utils/gutenberg-experiments.js.map +1 -0
- package/build/request-utils/index.js +196 -0
- package/build/request-utils/index.js.map +1 -0
- package/build/request-utils/login.js +21 -0
- package/build/request-utils/login.js.map +1 -0
- package/build/request-utils/media.js +106 -0
- package/build/request-utils/media.js.map +1 -0
- package/build/request-utils/menus.js +116 -0
- package/build/request-utils/menus.js.map +1 -0
- package/build/request-utils/pages.js +53 -0
- package/build/request-utils/pages.js.map +1 -0
- package/build/request-utils/patterns.js +27 -0
- package/build/request-utils/patterns.js.map +1 -0
- package/build/request-utils/plugins.js +85 -0
- package/build/request-utils/plugins.js.map +1 -0
- package/build/request-utils/posts.js +42 -0
- package/build/request-utils/posts.js.map +1 -0
- package/build/request-utils/preferences.js +54 -0
- package/build/request-utils/preferences.js.map +1 -0
- package/{src/request-utils/records.ts → build/request-utils/records.js} +10 -15
- package/build/request-utils/records.js.map +1 -0
- package/build/request-utils/rest.js +181 -0
- package/build/request-utils/rest.js.map +1 -0
- package/build/request-utils/site-settings.js +33 -0
- package/build/request-utils/site-settings.js.map +1 -0
- package/build/request-utils/templates.js +54 -0
- package/build/request-utils/templates.js.map +1 -0
- package/build/request-utils/themes.js +69 -0
- package/build/request-utils/themes.js.map +1 -0
- package/build/request-utils/users.js +81 -0
- package/build/request-utils/users.js.map +1 -0
- package/build/request-utils/widgets.js +61 -0
- package/build/request-utils/widgets.js.map +1 -0
- package/build/test.js +189 -0
- package/build/test.js.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build-types/admin/index.d.ts.map +1 -1
- package/build-types/config.d.ts.map +1 -1
- package/build-types/editor/index.d.ts.map +1 -1
- package/build-types/lighthouse/index.d.ts.map +1 -1
- package/build-types/metrics/index.d.ts.map +1 -1
- package/build-types/page-utils/index.d.ts.map +1 -1
- package/build-types/page-utils/press-keys.d.ts +1 -1
- package/build-types/page-utils/set-browser-viewport.d.ts +22 -12
- package/build-types/page-utils/set-browser-viewport.d.ts.map +1 -1
- package/build-types/request-utils/index.d.ts +2 -2
- package/build-types/request-utils/index.d.ts.map +1 -1
- package/build-types/request-utils/pages.d.ts +1 -1
- package/build-types/request-utils/pages.d.ts.map +1 -1
- package/build-types/request-utils/widgets.d.ts +2 -2
- package/build-types/request-utils/widgets.d.ts.map +1 -1
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -5
- package/src/admin/create-new-post.ts +0 -47
- package/src/admin/edit-post.ts +0 -24
- package/src/admin/index.ts +0 -52
- package/src/admin/visit-admin-page.ts +0 -43
- package/src/admin/visit-site-editor.ts +0 -62
- package/src/admin/wait-for-site-editor.ts +0 -52
- package/src/config.ts +0 -12
- package/src/editor/click-block-options-menu-item.ts +0 -18
- package/src/editor/click-block-toolbar-button.ts +0 -21
- package/src/editor/get-blocks.ts +0 -75
- package/src/editor/get-edited-post-content.ts +0 -19
- package/src/editor/index.ts +0 -95
- package/src/editor/insert-block.ts +0 -54
- package/src/editor/open-document-settings-sidebar.ts +0 -31
- package/src/editor/preview.ts +0 -32
- package/src/editor/publish-post.ts +0 -51
- package/src/editor/save-draft.ts +0 -20
- package/src/editor/select-blocks.ts +0 -48
- package/src/editor/set-content.ts +0 -24
- package/src/editor/set-is-fixed-toolbar.ts +0 -20
- package/src/editor/set-preferences.ts +0 -37
- package/src/editor/show-block-toolbar.ts +0 -20
- package/src/editor/site-editor.ts +0 -55
- package/src/editor/switch-editor-tool.ts +0 -34
- package/src/editor/switch-to-legacy-canvas.ts +0 -20
- package/src/editor/transform-block-to.ts +0 -34
- package/src/index.ts +0 -8
- package/src/lighthouse/index.ts +0 -75
- package/src/metrics/index.ts +0 -441
- package/src/page-utils/drag-files.ts +0 -173
- package/src/page-utils/emulate-network-conditions.ts +0 -101
- package/src/page-utils/index.ts +0 -54
- package/src/page-utils/is-current-url.ts +0 -20
- package/src/page-utils/keycodes.ts +0 -48
- package/src/page-utils/press-keys.ts +0 -195
- package/src/request-utils/blocks.ts +0 -58
- package/src/request-utils/comments.ts +0 -80
- package/src/request-utils/gutenberg-experiments.ts +0 -62
- package/src/request-utils/index.ts +0 -222
- package/src/request-utils/login.ts +0 -34
- package/src/request-utils/media.ts +0 -102
- package/src/request-utils/menus.ts +0 -145
- package/src/request-utils/pages.ts +0 -75
- package/src/request-utils/patterns.ts +0 -31
- package/src/request-utils/plugins.ts +0 -103
- package/src/request-utils/posts.ts +0 -69
- package/src/request-utils/preferences.ts +0 -63
- package/src/request-utils/rest.ts +0 -222
- package/src/request-utils/site-settings.ts +0 -58
- package/src/request-utils/templates.ts +0 -83
- package/src/request-utils/themes.ts +0 -110
- package/src/request-utils/users.ts +0 -125
- package/src/request-utils/widgets.js +0 -68
- package/src/test.ts +0 -204
- package/src/types.ts +0 -13
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from './';
|
|
5
|
-
|
|
6
|
-
interface SiteEditorOptions {
|
|
7
|
-
postId?: string | number;
|
|
8
|
-
postType?: string;
|
|
9
|
-
path?: string;
|
|
10
|
-
canvas?: string;
|
|
11
|
-
activeView?: string;
|
|
12
|
-
showWelcomeGuide?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Visits the Site Editor main page.
|
|
17
|
-
*
|
|
18
|
-
* @param this
|
|
19
|
-
* @param options Options to visit the site editor.
|
|
20
|
-
*/
|
|
21
|
-
export async function visitSiteEditor(
|
|
22
|
-
this: Admin,
|
|
23
|
-
options: SiteEditorOptions = {}
|
|
24
|
-
) {
|
|
25
|
-
const { postId, postType, path, canvas, activeView } = options;
|
|
26
|
-
const query = new URLSearchParams();
|
|
27
|
-
|
|
28
|
-
if ( postId ) {
|
|
29
|
-
query.set( 'postId', String( postId ) );
|
|
30
|
-
}
|
|
31
|
-
if ( postType ) {
|
|
32
|
-
query.set( 'postType', postType );
|
|
33
|
-
}
|
|
34
|
-
if ( path ) {
|
|
35
|
-
query.set( 'path', path );
|
|
36
|
-
}
|
|
37
|
-
if ( canvas ) {
|
|
38
|
-
query.set( 'canvas', canvas );
|
|
39
|
-
}
|
|
40
|
-
if ( activeView ) {
|
|
41
|
-
query.set( 'activeView', activeView );
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await this.visitAdminPage( 'site-editor.php', query.toString() );
|
|
45
|
-
|
|
46
|
-
if ( ! options.showWelcomeGuide ) {
|
|
47
|
-
await this.editor.setPreferences( 'core/edit-site', {
|
|
48
|
-
welcomeGuide: false,
|
|
49
|
-
welcomeGuideStyles: false,
|
|
50
|
-
welcomeGuidePage: false,
|
|
51
|
-
welcomeGuideTemplate: false,
|
|
52
|
-
} );
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Wait until the editor is loaded. The logic is a copy of the
|
|
57
|
-
* `waitWhileSiteEditorLoading` function in the `edit-site` package.
|
|
58
|
-
*/
|
|
59
|
-
if ( ! query.size || postId || canvas === 'edit' ) {
|
|
60
|
-
await this.waitForSiteEditor();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from './';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Waits for the Site Editor to finish loading, i.e., for all resolvers
|
|
8
|
-
* in the `core` store to finish and then pause for a short period.
|
|
9
|
-
*
|
|
10
|
-
* @param this
|
|
11
|
-
*/
|
|
12
|
-
export async function waitForSiteEditor( this: Admin ) {
|
|
13
|
-
await this.page.evaluate( () => {
|
|
14
|
-
const MAX_LOADING_TIME = 10000;
|
|
15
|
-
const MAX_PAUSE_TIME = 100;
|
|
16
|
-
|
|
17
|
-
return new Promise< void >( ( resolve ) => {
|
|
18
|
-
let pauseTimeout: ReturnType< typeof setTimeout > | undefined;
|
|
19
|
-
|
|
20
|
-
function finish() {
|
|
21
|
-
unsubscribe();
|
|
22
|
-
clearTimeout( pauseTimeout );
|
|
23
|
-
clearTimeout( maxTimeout );
|
|
24
|
-
resolve();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const maxTimeout = setTimeout( finish, MAX_LOADING_TIME );
|
|
28
|
-
|
|
29
|
-
function checkResolving() {
|
|
30
|
-
const isResolving = window.wp.data
|
|
31
|
-
.select( 'core' )
|
|
32
|
-
.hasResolvingSelectors();
|
|
33
|
-
|
|
34
|
-
if ( isResolving ) {
|
|
35
|
-
clearTimeout( pauseTimeout );
|
|
36
|
-
pauseTimeout = undefined;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if ( ! pauseTimeout ) {
|
|
41
|
-
pauseTimeout = setTimeout( finish, MAX_PAUSE_TIME );
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const unsubscribe = window.wp.data.subscribe(
|
|
46
|
-
checkResolving,
|
|
47
|
-
'core'
|
|
48
|
-
);
|
|
49
|
-
checkResolving();
|
|
50
|
-
} );
|
|
51
|
-
} );
|
|
52
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
WP_USERNAME = 'admin',
|
|
3
|
-
WP_PASSWORD = 'password',
|
|
4
|
-
WP_BASE_URL = 'http://localhost:8889',
|
|
5
|
-
} = process.env;
|
|
6
|
-
|
|
7
|
-
const WP_ADMIN_USER = {
|
|
8
|
-
username: WP_USERNAME,
|
|
9
|
-
password: WP_PASSWORD,
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
export { WP_ADMIN_USER, WP_USERNAME, WP_PASSWORD, WP_BASE_URL };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks a block toolbar button.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param label The text string of the button label.
|
|
11
|
-
*/
|
|
12
|
-
export async function clickBlockOptionsMenuItem( this: Editor, label: string ) {
|
|
13
|
-
await this.clickBlockToolbarButton( 'Options' );
|
|
14
|
-
await this.page
|
|
15
|
-
.getByRole( 'menu', { name: 'Options' } )
|
|
16
|
-
.getByRole( 'menuitem', { name: label } )
|
|
17
|
-
.click();
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks a block toolbar button.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param label The text string of the button label.
|
|
11
|
-
*/
|
|
12
|
-
export async function clickBlockToolbarButton( this: Editor, label: string ) {
|
|
13
|
-
await this.showBlockToolbar();
|
|
14
|
-
|
|
15
|
-
const blockToolbar = this.page.locator(
|
|
16
|
-
'role=toolbar[name="Block tools"i]'
|
|
17
|
-
);
|
|
18
|
-
const button = blockToolbar.locator( `role=button[name="${ label }"]` );
|
|
19
|
-
|
|
20
|
-
await button.click();
|
|
21
|
-
}
|
package/src/editor/get-blocks.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
type Block = {
|
|
7
|
-
name: string;
|
|
8
|
-
attributes: Record< string, unknown >;
|
|
9
|
-
innerBlocks: Block[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns the edited blocks.
|
|
14
|
-
*
|
|
15
|
-
* @param options
|
|
16
|
-
* @param options.clientId Limit the results to be only under a partial tree of the specified clientId.
|
|
17
|
-
* @param options.full Whether to return the full block data or just the name and attributes.
|
|
18
|
-
*
|
|
19
|
-
* @return The blocks.
|
|
20
|
-
*/
|
|
21
|
-
export async function getBlocks(
|
|
22
|
-
this: Editor,
|
|
23
|
-
{ clientId, full = false }: { clientId?: string; full?: boolean } = {}
|
|
24
|
-
) {
|
|
25
|
-
await this.page.waitForFunction(
|
|
26
|
-
() => window?.wp?.blocks && window?.wp?.data
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return await this.page.evaluate(
|
|
30
|
-
( [ _full, _clientId ] ) => {
|
|
31
|
-
// Serialize serializable attributes of blocks.
|
|
32
|
-
function serializeAttributes(
|
|
33
|
-
attributes: Record< string, unknown >
|
|
34
|
-
) {
|
|
35
|
-
return Object.fromEntries(
|
|
36
|
-
Object.entries( attributes ).map( ( [ key, value ] ) => {
|
|
37
|
-
// Serialize RichTextData to string.
|
|
38
|
-
if (
|
|
39
|
-
value instanceof window.wp.richText.RichTextData
|
|
40
|
-
) {
|
|
41
|
-
return [ key, ( value as string ).toString() ];
|
|
42
|
-
}
|
|
43
|
-
return [ key, value ];
|
|
44
|
-
} )
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Remove other unpredictable properties like clientId from blocks for testing purposes.
|
|
49
|
-
function recursivelyTransformBlocks( blocks: Block[] ): Block[] {
|
|
50
|
-
return blocks.map( ( block ) => ( {
|
|
51
|
-
name: block.name,
|
|
52
|
-
attributes: serializeAttributes( block.attributes ),
|
|
53
|
-
innerBlocks: recursivelyTransformBlocks(
|
|
54
|
-
block.innerBlocks
|
|
55
|
-
),
|
|
56
|
-
} ) );
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const blocks = window.wp.data
|
|
60
|
-
.select( 'core/block-editor' )
|
|
61
|
-
.getBlocks( _clientId ) as Block[];
|
|
62
|
-
|
|
63
|
-
// The editor might still contain an unmodified empty block even when it's technically "empty".
|
|
64
|
-
if (
|
|
65
|
-
blocks.length === 1 &&
|
|
66
|
-
window.wp.blocks.isUnmodifiedDefaultBlock( blocks[ 0 ] )
|
|
67
|
-
) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return _full ? blocks : recursivelyTransformBlocks( blocks );
|
|
72
|
-
},
|
|
73
|
-
[ full, clientId ]
|
|
74
|
-
);
|
|
75
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns a promise which resolves with the edited post content (HTML string).
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
*
|
|
11
|
-
* @return Promise resolving with post content markup.
|
|
12
|
-
*/
|
|
13
|
-
export async function getEditedPostContent( this: Editor ) {
|
|
14
|
-
await this.page.waitForFunction( () => window?.wp?.data );
|
|
15
|
-
|
|
16
|
-
return await this.page.evaluate( () =>
|
|
17
|
-
window.wp.data.select( 'core/editor' ).getEditedPostContent()
|
|
18
|
-
);
|
|
19
|
-
}
|
package/src/editor/index.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type {
|
|
5
|
-
Browser,
|
|
6
|
-
Page,
|
|
7
|
-
BrowserContext,
|
|
8
|
-
FrameLocator,
|
|
9
|
-
} from '@playwright/test';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { clickBlockOptionsMenuItem } from './click-block-options-menu-item';
|
|
15
|
-
import { clickBlockToolbarButton } from './click-block-toolbar-button';
|
|
16
|
-
import { getBlocks } from './get-blocks';
|
|
17
|
-
import { getEditedPostContent } from './get-edited-post-content';
|
|
18
|
-
import { insertBlock } from './insert-block';
|
|
19
|
-
import { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
|
|
20
|
-
import { openPreviewPage } from './preview';
|
|
21
|
-
import { publishPost } from './publish-post';
|
|
22
|
-
import { saveDraft } from './save-draft';
|
|
23
|
-
import { selectBlocks } from './select-blocks';
|
|
24
|
-
import { setContent } from './set-content';
|
|
25
|
-
import { setPreferences } from './set-preferences';
|
|
26
|
-
import { showBlockToolbar } from './show-block-toolbar';
|
|
27
|
-
import { saveSiteEditorEntities } from './site-editor';
|
|
28
|
-
import { setIsFixedToolbar } from './set-is-fixed-toolbar';
|
|
29
|
-
import { switchToLegacyCanvas } from './switch-to-legacy-canvas';
|
|
30
|
-
import { transformBlockTo } from './transform-block-to';
|
|
31
|
-
import { switchEditorTool } from './switch-editor-tool';
|
|
32
|
-
|
|
33
|
-
type EditorConstructorProps = {
|
|
34
|
-
page: Page;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export class Editor {
|
|
38
|
-
browser: Browser;
|
|
39
|
-
page: Page;
|
|
40
|
-
context: BrowserContext;
|
|
41
|
-
|
|
42
|
-
constructor( { page }: EditorConstructorProps ) {
|
|
43
|
-
this.page = page;
|
|
44
|
-
this.context = page.context();
|
|
45
|
-
this.browser = this.context.browser()!;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get canvas(): FrameLocator {
|
|
49
|
-
return this.page.frameLocator( '[name="editor-canvas"]' );
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @borrows clickBlockOptionsMenuItem as this.clickBlockOptionsMenuItem */
|
|
53
|
-
clickBlockOptionsMenuItem: typeof clickBlockOptionsMenuItem =
|
|
54
|
-
clickBlockOptionsMenuItem.bind( this );
|
|
55
|
-
/** @borrows clickBlockToolbarButton as this.clickBlockToolbarButton */
|
|
56
|
-
clickBlockToolbarButton: typeof clickBlockToolbarButton =
|
|
57
|
-
clickBlockToolbarButton.bind( this );
|
|
58
|
-
/** @borrows getBlocks as this.getBlocks */
|
|
59
|
-
getBlocks: typeof getBlocks = getBlocks.bind( this );
|
|
60
|
-
/** @borrows getEditedPostContent as this.getEditedPostContent */
|
|
61
|
-
getEditedPostContent: typeof getEditedPostContent =
|
|
62
|
-
getEditedPostContent.bind( this );
|
|
63
|
-
/** @borrows insertBlock as this.insertBlock */
|
|
64
|
-
insertBlock: typeof insertBlock = insertBlock.bind( this );
|
|
65
|
-
/** @borrows openDocumentSettingsSidebar as this.openDocumentSettingsSidebar */
|
|
66
|
-
openDocumentSettingsSidebar: typeof openDocumentSettingsSidebar =
|
|
67
|
-
openDocumentSettingsSidebar.bind( this );
|
|
68
|
-
/** @borrows openPreviewPage as this.openPreviewPage */
|
|
69
|
-
openPreviewPage: typeof openPreviewPage = openPreviewPage.bind( this );
|
|
70
|
-
/** @borrows publishPost as this.publishPost */
|
|
71
|
-
publishPost: typeof publishPost = publishPost.bind( this );
|
|
72
|
-
/** @borrows saveDraft as this.saveDraft */
|
|
73
|
-
saveDraft: typeof saveDraft = saveDraft.bind( this );
|
|
74
|
-
/** @borrows saveSiteEditorEntities as this.saveSiteEditorEntities */
|
|
75
|
-
saveSiteEditorEntities: typeof saveSiteEditorEntities =
|
|
76
|
-
saveSiteEditorEntities.bind( this );
|
|
77
|
-
/** @borrows selectBlocks as this.selectBlocks */
|
|
78
|
-
selectBlocks: typeof selectBlocks = selectBlocks.bind( this );
|
|
79
|
-
/** @borrows setContent as this.setContent */
|
|
80
|
-
setContent: typeof setContent = setContent.bind( this );
|
|
81
|
-
/** @borrows setPreferences as this.setPreferences */
|
|
82
|
-
setPreferences: typeof setPreferences = setPreferences.bind( this );
|
|
83
|
-
/** @borrows showBlockToolbar as this.showBlockToolbar */
|
|
84
|
-
showBlockToolbar: typeof showBlockToolbar = showBlockToolbar.bind( this );
|
|
85
|
-
/** @borrows setIsFixedToolbar as this.setIsFixedToolbar */
|
|
86
|
-
setIsFixedToolbar: typeof setIsFixedToolbar =
|
|
87
|
-
setIsFixedToolbar.bind( this );
|
|
88
|
-
/** @borrows switchEditorTool as this.switchEditorTool */
|
|
89
|
-
switchEditorTool: typeof switchEditorTool = switchEditorTool.bind( this );
|
|
90
|
-
/** @borrows switchToLegacyCanvas as this.switchToLegacyCanvas */
|
|
91
|
-
switchToLegacyCanvas: typeof switchToLegacyCanvas =
|
|
92
|
-
switchToLegacyCanvas.bind( this );
|
|
93
|
-
/** @borrows transformBlockTo as this.transformBlockTo */
|
|
94
|
-
transformBlockTo: typeof transformBlockTo = transformBlockTo.bind( this );
|
|
95
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
interface BlockRepresentation {
|
|
7
|
-
name: string;
|
|
8
|
-
attributes?: Object;
|
|
9
|
-
innerBlocks?: BlockRepresentation[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Insert a block.
|
|
14
|
-
*
|
|
15
|
-
* @param blockRepresentation Inserted block representation.
|
|
16
|
-
* @param options
|
|
17
|
-
* @param options.clientId Client ID of the parent block to insert into.
|
|
18
|
-
*/
|
|
19
|
-
async function insertBlock(
|
|
20
|
-
this: Editor,
|
|
21
|
-
blockRepresentation: BlockRepresentation,
|
|
22
|
-
{ clientId }: { clientId?: string } = {}
|
|
23
|
-
) {
|
|
24
|
-
await this.page.waitForFunction(
|
|
25
|
-
() => window?.wp?.blocks && window?.wp?.data
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
await this.page.evaluate(
|
|
29
|
-
( [ _blockRepresentation, _clientId ] ) => {
|
|
30
|
-
function recursiveCreateBlock( {
|
|
31
|
-
name,
|
|
32
|
-
attributes = {},
|
|
33
|
-
innerBlocks = [],
|
|
34
|
-
}: BlockRepresentation ): Object {
|
|
35
|
-
return window.wp.blocks.createBlock(
|
|
36
|
-
name,
|
|
37
|
-
attributes,
|
|
38
|
-
innerBlocks.map( ( innerBlock ) =>
|
|
39
|
-
recursiveCreateBlock( innerBlock )
|
|
40
|
-
)
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
const block = recursiveCreateBlock( _blockRepresentation );
|
|
44
|
-
|
|
45
|
-
window.wp.data
|
|
46
|
-
.dispatch( 'core/block-editor' )
|
|
47
|
-
.insertBlock( block, undefined, _clientId );
|
|
48
|
-
},
|
|
49
|
-
[ blockRepresentation, clientId ] as const
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type { BlockRepresentation };
|
|
54
|
-
export { insertBlock };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks on the button in the header which opens Document Settings sidebar when
|
|
8
|
-
* it is closed.
|
|
9
|
-
*
|
|
10
|
-
* @param this
|
|
11
|
-
*/
|
|
12
|
-
export async function openDocumentSettingsSidebar( this: Editor ) {
|
|
13
|
-
const toggleButton = this.page
|
|
14
|
-
.getByRole( 'region', { name: 'Editor top bar' } )
|
|
15
|
-
.getByRole( 'button', {
|
|
16
|
-
name: 'Settings',
|
|
17
|
-
exact: true,
|
|
18
|
-
disabled: false,
|
|
19
|
-
} );
|
|
20
|
-
|
|
21
|
-
const isClosed =
|
|
22
|
-
( await toggleButton.getAttribute( 'aria-expanded' ) ) === 'false';
|
|
23
|
-
|
|
24
|
-
if ( isClosed ) {
|
|
25
|
-
await toggleButton.click();
|
|
26
|
-
await this.page
|
|
27
|
-
.getByRole( 'region', { name: 'Editor settings' } )
|
|
28
|
-
.getByRole( 'button', { name: 'Close Settings' } )
|
|
29
|
-
.waitFor();
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/editor/preview.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Page } from '@playwright/test';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import type { Editor } from './index';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Opens the preview page of an edited post.
|
|
13
|
-
*
|
|
14
|
-
* @param this
|
|
15
|
-
*
|
|
16
|
-
* @return preview page.
|
|
17
|
-
*/
|
|
18
|
-
export async function openPreviewPage( this: Editor ): Promise< Page > {
|
|
19
|
-
const editorTopBar = this.page.locator(
|
|
20
|
-
'role=region[name="Editor top bar"i]'
|
|
21
|
-
);
|
|
22
|
-
const previewButton = editorTopBar.locator( 'role=button[name="View"i]' );
|
|
23
|
-
|
|
24
|
-
await previewButton.click();
|
|
25
|
-
|
|
26
|
-
const [ previewPage ] = await Promise.all( [
|
|
27
|
-
this.context.waitForEvent( 'page' ),
|
|
28
|
-
this.page.click( 'role=menuitem[name="Preview in new tab"i]' ),
|
|
29
|
-
] );
|
|
30
|
-
|
|
31
|
-
return previewPage;
|
|
32
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Publishes the post, resolving once the request is complete (once a notice
|
|
8
|
-
* is displayed).
|
|
9
|
-
*
|
|
10
|
-
* @param this
|
|
11
|
-
*/
|
|
12
|
-
export async function publishPost( this: Editor ) {
|
|
13
|
-
// If we have changes in other entities, the label is `Save` instead of `Publish`.
|
|
14
|
-
const saveButton = this.page
|
|
15
|
-
.getByRole( 'region', { name: 'Editor top bar' } )
|
|
16
|
-
.getByRole( 'button', { name: 'Save', exact: true } );
|
|
17
|
-
const publishButton = this.page
|
|
18
|
-
.getByRole( 'region', { name: 'Editor top bar' } )
|
|
19
|
-
.getByRole( 'button', { name: 'Publish', exact: true } );
|
|
20
|
-
const buttonToClick = ( await saveButton.isVisible() )
|
|
21
|
-
? saveButton
|
|
22
|
-
: publishButton;
|
|
23
|
-
await buttonToClick.click();
|
|
24
|
-
|
|
25
|
-
const entitiesSaveButton = this.page
|
|
26
|
-
.getByRole( 'region', { name: 'Editor publish' } )
|
|
27
|
-
.getByRole( 'button', { name: 'Save', exact: true } );
|
|
28
|
-
const isEntitiesSavePanelVisible = await entitiesSaveButton.isVisible();
|
|
29
|
-
|
|
30
|
-
// Save any entities.
|
|
31
|
-
if ( isEntitiesSavePanelVisible ) {
|
|
32
|
-
// Handle saving entities.
|
|
33
|
-
await entitiesSaveButton.click();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Handle saving just the post.
|
|
37
|
-
await this.page
|
|
38
|
-
.getByRole( 'region', {
|
|
39
|
-
name: 'Editor publish',
|
|
40
|
-
} )
|
|
41
|
-
.getByRole( 'button', { name: 'Publish', exact: true } )
|
|
42
|
-
.click();
|
|
43
|
-
|
|
44
|
-
await this.page
|
|
45
|
-
.getByRole( 'button', { name: 'Dismiss this notice' } )
|
|
46
|
-
.filter( { hasText: 'published' } )
|
|
47
|
-
.waitFor();
|
|
48
|
-
const postId = new URL( this.page.url() ).searchParams.get( 'post' );
|
|
49
|
-
|
|
50
|
-
return typeof postId === 'string' ? parseInt( postId, 10 ) : null;
|
|
51
|
-
}
|
package/src/editor/save-draft.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Saves the post as a draft, resolving once the request is complete (once a notice
|
|
8
|
-
* is displayed).
|
|
9
|
-
*/
|
|
10
|
-
export async function saveDraft( this: Editor ) {
|
|
11
|
-
await this.page
|
|
12
|
-
.getByRole( 'region', { name: 'Editor top bar' } )
|
|
13
|
-
.getByRole( 'button', { name: 'Save draft' } )
|
|
14
|
-
.click();
|
|
15
|
-
|
|
16
|
-
await this.page
|
|
17
|
-
.getByRole( 'button', { name: 'Dismiss this notice' } )
|
|
18
|
-
.filter( { hasText: 'Draft saved' } )
|
|
19
|
-
.waitFor();
|
|
20
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Locator } from '@playwright/test';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import type { Editor } from './index';
|
|
10
|
-
|
|
11
|
-
export async function selectBlocks(
|
|
12
|
-
this: Editor,
|
|
13
|
-
startSelectorOrLocator: string | Locator,
|
|
14
|
-
endSelectorOrLocator?: string | Locator
|
|
15
|
-
) {
|
|
16
|
-
const startBlock =
|
|
17
|
-
typeof startSelectorOrLocator === 'string'
|
|
18
|
-
? this.canvas.locator( startSelectorOrLocator )
|
|
19
|
-
: startSelectorOrLocator;
|
|
20
|
-
|
|
21
|
-
const endBlock =
|
|
22
|
-
typeof endSelectorOrLocator === 'string'
|
|
23
|
-
? this.canvas.locator( endSelectorOrLocator )
|
|
24
|
-
: endSelectorOrLocator;
|
|
25
|
-
|
|
26
|
-
const startClientId = await startBlock.getAttribute( 'data-block' );
|
|
27
|
-
const endClientId = await endBlock?.getAttribute( 'data-block' );
|
|
28
|
-
|
|
29
|
-
if ( endClientId ) {
|
|
30
|
-
await this.page.evaluate(
|
|
31
|
-
( [ startId, endId ] ) => {
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
wp.data
|
|
34
|
-
.dispatch( 'core/block-editor' )
|
|
35
|
-
.multiSelect( startId, endId );
|
|
36
|
-
},
|
|
37
|
-
[ startClientId, endClientId ]
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
await this.page.evaluate(
|
|
41
|
-
( [ clientId ] ) => {
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
wp.data.dispatch( 'core/block-editor' ).selectBlock( clientId );
|
|
44
|
-
},
|
|
45
|
-
[ startClientId ]
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Set the content of the editor.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param html Serialized block HTML.
|
|
11
|
-
*/
|
|
12
|
-
async function setContent( this: Editor, html: string ) {
|
|
13
|
-
await this.page.waitForFunction(
|
|
14
|
-
() => window?.wp?.blocks && window?.wp?.data
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
await this.page.evaluate( ( _html ) => {
|
|
18
|
-
const blocks = window.wp.blocks.parse( _html );
|
|
19
|
-
|
|
20
|
-
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( blocks );
|
|
21
|
-
}, html );
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { setContent };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Toggles the fixed toolbar option.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param isFixed Boolean value true/false for on/off.
|
|
11
|
-
*/
|
|
12
|
-
export async function setIsFixedToolbar( this: Editor, isFixed: boolean ) {
|
|
13
|
-
await this.page.waitForFunction( () => window?.wp?.data );
|
|
14
|
-
|
|
15
|
-
await this.page.evaluate( ( _isFixed ) => {
|
|
16
|
-
window.wp.data
|
|
17
|
-
.dispatch( 'core/preferences' )
|
|
18
|
-
.set( 'core', 'fixedToolbar', _isFixed );
|
|
19
|
-
}, isFixed );
|
|
20
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
type PreferencesContext =
|
|
7
|
-
| 'core/edit-post'
|
|
8
|
-
| 'core/edit-site'
|
|
9
|
-
| 'core/customize-widgets';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Set the preferences of the editor.
|
|
13
|
-
*
|
|
14
|
-
* @param this
|
|
15
|
-
* @param context Context to set preferences for.
|
|
16
|
-
* @param preferences Preferences to set.
|
|
17
|
-
*/
|
|
18
|
-
export async function setPreferences(
|
|
19
|
-
this: Editor,
|
|
20
|
-
context: PreferencesContext,
|
|
21
|
-
preferences: Record< string, any >
|
|
22
|
-
) {
|
|
23
|
-
await this.page.waitForFunction( () => window?.wp?.data );
|
|
24
|
-
|
|
25
|
-
await this.page.evaluate(
|
|
26
|
-
async ( props ) => {
|
|
27
|
-
for ( const [ key, value ] of Object.entries(
|
|
28
|
-
props.preferences
|
|
29
|
-
) ) {
|
|
30
|
-
await window.wp.data
|
|
31
|
-
.dispatch( 'core/preferences' )
|
|
32
|
-
.set( props.context, key, value );
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
{ context, preferences }
|
|
36
|
-
);
|
|
37
|
-
}
|