-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathvisit-site-editor.ts
75 lines (68 loc) · 1.97 KB
/
visit-site-editor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Internal dependencies
*/
import type { Admin } from './';
interface SiteEditorOptions {
postId?: string | number;
postType?: string;
path?: string;
canvas?: string;
showWelcomeGuide?: boolean;
}
/**
* Visits the Site Editor main page.
*
* @param this
* @param options Options to visit the site editor.
*/
export async function visitSiteEditor(
this: Admin,
options: SiteEditorOptions = {}
) {
const { postId, postType, path, canvas } = options;
const query = new URLSearchParams();
if ( postId ) {
query.set( 'postId', String( postId ) );
}
if ( postType ) {
query.set( 'postType', postType );
}
if ( path ) {
query.set( 'path', path );
}
if ( canvas ) {
query.set( 'canvas', canvas );
}
await this.visitAdminPage( 'site-editor.php', query.toString() );
if ( ! options.showWelcomeGuide ) {
await this.editor.setPreferences( 'core/edit-site', {
welcomeGuide: false,
welcomeGuideStyles: false,
welcomeGuidePage: false,
welcomeGuideTemplate: false,
} );
}
/**
* @todo This is a workaround for the fact that the editor canvas is seen as
* ready and visible before the loading spinner is hidden. Ideally, the
* content underneath the loading overlay should be marked inert until the
* loading is done.
*/
if ( ! query.size || postId || canvas === 'edit' ) {
const canvasLoader = this.page.locator(
// Spinner was used instead of the progress bar in an earlier
// version of the site editor.
'.edit-site-canvas-loader, .edit-site-canvas-spinner'
);
// Wait for the canvas loader to appear first, so that the locator that
// waits for the hidden state doesn't resolve prematurely.
await canvasLoader.waitFor( { state: 'visible', timeout: 60_000 } );
await canvasLoader.waitFor( {
state: 'hidden',
// Bigger timeout is needed for larger entities, like the Large Post
// HTML fixture that we load for performance tests, which often
// doesn't make it under the default timeout value.
timeout: 60_000,
} );
}
}