@wordpress/e2e-test-utils-playwright 1.48.0 → 1.48.2-next.v.202606191442.0

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.
Files changed (172) hide show
  1. package/build/admin/create-new-post.js +31 -0
  2. package/build/admin/create-new-post.js.map +1 -0
  3. package/build/admin/edit-post.js +20 -0
  4. package/build/admin/edit-post.js.map +1 -0
  5. package/{src/admin/get-page-error.ts → build/admin/get-page-error.js} +9 -12
  6. package/build/admin/get-page-error.js.map +1 -0
  7. package/build/admin/index.js +40 -0
  8. package/build/admin/index.js.map +1 -0
  9. package/build/admin/visit-admin-page.js +32 -0
  10. package/build/admin/visit-admin-page.js.map +1 -0
  11. package/build/admin/visit-site-editor.js +45 -0
  12. package/build/admin/visit-site-editor.js.map +1 -0
  13. package/build/admin/wait-for-site-editor.js +41 -0
  14. package/build/admin/wait-for-site-editor.js.map +1 -0
  15. package/build/config.js +13 -0
  16. package/build/config.js.map +1 -0
  17. package/build/editor/click-block-options-menu-item.js +17 -0
  18. package/build/editor/click-block-options-menu-item.js.map +1 -0
  19. package/build/editor/click-block-toolbar-button.js +16 -0
  20. package/build/editor/click-block-toolbar-button.js.map +1 -0
  21. package/build/editor/get-blocks.js +45 -0
  22. package/build/editor/get-blocks.js.map +1 -0
  23. package/build/editor/get-edited-post-content.js +15 -0
  24. package/build/editor/get-edited-post-content.js.map +1 -0
  25. package/build/editor/index.js +75 -0
  26. package/build/editor/index.js.map +1 -0
  27. package/build/editor/insert-block.js +23 -0
  28. package/build/editor/insert-block.js.map +1 -0
  29. package/build/editor/open-document-settings-sidebar.js +27 -0
  30. package/build/editor/open-document-settings-sidebar.js.map +1 -0
  31. package/build/editor/preview.js +21 -0
  32. package/build/editor/preview.js.map +1 -0
  33. package/build/editor/publish-post.js +45 -0
  34. package/build/editor/publish-post.js.map +1 -0
  35. package/build/editor/save-draft.js +18 -0
  36. package/build/editor/save-draft.js.map +1 -0
  37. package/build/editor/select-blocks.js +28 -0
  38. package/build/editor/select-blocks.js.map +1 -0
  39. package/build/editor/set-content.js +17 -0
  40. package/build/editor/set-content.js.map +1 -0
  41. package/build/editor/set-is-fixed-toolbar.js +18 -0
  42. package/build/editor/set-is-fixed-toolbar.js.map +1 -0
  43. package/build/editor/set-preferences.js +21 -0
  44. package/build/editor/set-preferences.js.map +1 -0
  45. package/build/editor/show-block-toolbar.js +19 -0
  46. package/build/editor/show-block-toolbar.js.map +1 -0
  47. package/build/editor/site-editor.js +44 -0
  48. package/build/editor/site-editor.js.map +1 -0
  49. package/build/editor/switch-editor-tool.js +33 -0
  50. package/build/editor/switch-editor-tool.js.map +1 -0
  51. package/build/editor/switch-to-legacy-canvas.js +18 -0
  52. package/build/editor/switch-to-legacy-canvas.js.map +1 -0
  53. package/build/editor/transform-block-to.js +24 -0
  54. package/build/editor/transform-block-to.js.map +1 -0
  55. package/build/index.js +19 -0
  56. package/build/index.js.map +1 -0
  57. package/build/lighthouse/index.js +61 -0
  58. package/build/lighthouse/index.js.map +1 -0
  59. package/build/metrics/index.js +314 -0
  60. package/build/metrics/index.js.map +1 -0
  61. package/build/page-utils/drag-files.js +119 -0
  62. package/build/page-utils/drag-files.js.map +1 -0
  63. package/build/page-utils/emulate-network-conditions.js +71 -0
  64. package/build/page-utils/emulate-network-conditions.js.map +1 -0
  65. package/build/page-utils/index.js +37 -0
  66. package/build/page-utils/index.js.map +1 -0
  67. package/build/page-utils/is-current-url.js +21 -0
  68. package/build/page-utils/is-current-url.js.map +1 -0
  69. package/build/page-utils/keycodes.js +41 -0
  70. package/build/page-utils/keycodes.js.map +1 -0
  71. package/build/page-utils/press-keys.js +141 -0
  72. package/build/page-utils/press-keys.js.map +1 -0
  73. package/{src → build}/page-utils/set-browser-viewport.js +12 -14
  74. package/build/page-utils/set-browser-viewport.js.map +1 -0
  75. package/build/request-utils/blocks.js +40 -0
  76. package/build/request-utils/blocks.js.map +1 -0
  77. package/build/request-utils/comments.js +52 -0
  78. package/build/request-utils/comments.js.map +1 -0
  79. package/build/request-utils/gutenberg-experiments.js +47 -0
  80. package/build/request-utils/gutenberg-experiments.js.map +1 -0
  81. package/build/request-utils/index.js +196 -0
  82. package/build/request-utils/index.js.map +1 -0
  83. package/build/request-utils/login.js +21 -0
  84. package/build/request-utils/login.js.map +1 -0
  85. package/build/request-utils/media.js +106 -0
  86. package/build/request-utils/media.js.map +1 -0
  87. package/build/request-utils/menus.js +116 -0
  88. package/build/request-utils/menus.js.map +1 -0
  89. package/build/request-utils/pages.js +53 -0
  90. package/build/request-utils/pages.js.map +1 -0
  91. package/build/request-utils/patterns.js +27 -0
  92. package/build/request-utils/patterns.js.map +1 -0
  93. package/build/request-utils/plugins.js +85 -0
  94. package/build/request-utils/plugins.js.map +1 -0
  95. package/build/request-utils/posts.js +42 -0
  96. package/build/request-utils/posts.js.map +1 -0
  97. package/build/request-utils/preferences.js +54 -0
  98. package/build/request-utils/preferences.js.map +1 -0
  99. package/{src/request-utils/records.ts → build/request-utils/records.js} +10 -15
  100. package/build/request-utils/records.js.map +1 -0
  101. package/build/request-utils/rest.js +181 -0
  102. package/build/request-utils/rest.js.map +1 -0
  103. package/build/request-utils/site-settings.js +33 -0
  104. package/build/request-utils/site-settings.js.map +1 -0
  105. package/build/request-utils/templates.js +54 -0
  106. package/build/request-utils/templates.js.map +1 -0
  107. package/build/request-utils/themes.js +69 -0
  108. package/build/request-utils/themes.js.map +1 -0
  109. package/build/request-utils/users.js +81 -0
  110. package/build/request-utils/users.js.map +1 -0
  111. package/build/request-utils/widgets.js +61 -0
  112. package/build/request-utils/widgets.js.map +1 -0
  113. package/build/test.js +189 -0
  114. package/build/test.js.map +1 -0
  115. package/build/types.js +3 -0
  116. package/build/types.js.map +1 -0
  117. package/package.json +8 -5
  118. package/src/admin/create-new-post.ts +0 -47
  119. package/src/admin/edit-post.ts +0 -24
  120. package/src/admin/index.ts +0 -52
  121. package/src/admin/visit-admin-page.ts +0 -43
  122. package/src/admin/visit-site-editor.ts +0 -62
  123. package/src/admin/wait-for-site-editor.ts +0 -52
  124. package/src/config.ts +0 -12
  125. package/src/editor/click-block-options-menu-item.ts +0 -18
  126. package/src/editor/click-block-toolbar-button.ts +0 -21
  127. package/src/editor/get-blocks.ts +0 -75
  128. package/src/editor/get-edited-post-content.ts +0 -19
  129. package/src/editor/index.ts +0 -95
  130. package/src/editor/insert-block.ts +0 -54
  131. package/src/editor/open-document-settings-sidebar.ts +0 -31
  132. package/src/editor/preview.ts +0 -32
  133. package/src/editor/publish-post.ts +0 -51
  134. package/src/editor/save-draft.ts +0 -20
  135. package/src/editor/select-blocks.ts +0 -48
  136. package/src/editor/set-content.ts +0 -24
  137. package/src/editor/set-is-fixed-toolbar.ts +0 -20
  138. package/src/editor/set-preferences.ts +0 -37
  139. package/src/editor/show-block-toolbar.ts +0 -20
  140. package/src/editor/site-editor.ts +0 -55
  141. package/src/editor/switch-editor-tool.ts +0 -34
  142. package/src/editor/switch-to-legacy-canvas.ts +0 -20
  143. package/src/editor/transform-block-to.ts +0 -34
  144. package/src/index.ts +0 -8
  145. package/src/lighthouse/index.ts +0 -75
  146. package/src/metrics/index.ts +0 -441
  147. package/src/page-utils/drag-files.ts +0 -173
  148. package/src/page-utils/emulate-network-conditions.ts +0 -101
  149. package/src/page-utils/index.ts +0 -54
  150. package/src/page-utils/is-current-url.ts +0 -20
  151. package/src/page-utils/keycodes.ts +0 -48
  152. package/src/page-utils/press-keys.ts +0 -195
  153. package/src/request-utils/blocks.ts +0 -58
  154. package/src/request-utils/comments.ts +0 -80
  155. package/src/request-utils/gutenberg-experiments.ts +0 -62
  156. package/src/request-utils/index.ts +0 -222
  157. package/src/request-utils/login.ts +0 -34
  158. package/src/request-utils/media.ts +0 -102
  159. package/src/request-utils/menus.ts +0 -145
  160. package/src/request-utils/pages.ts +0 -75
  161. package/src/request-utils/patterns.ts +0 -31
  162. package/src/request-utils/plugins.ts +0 -103
  163. package/src/request-utils/posts.ts +0 -69
  164. package/src/request-utils/preferences.ts +0 -63
  165. package/src/request-utils/rest.ts +0 -222
  166. package/src/request-utils/site-settings.ts +0 -58
  167. package/src/request-utils/templates.ts +0 -83
  168. package/src/request-utils/themes.ts +0 -110
  169. package/src/request-utils/users.ts +0 -125
  170. package/src/request-utils/widgets.js +0 -68
  171. package/src/test.ts +0 -204
  172. package/src/types.ts +0 -13
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Editor } from './index';
5
-
6
- /**
7
- * The block toolbar is not always visible while typing.
8
- * Call this function to reveal it.
9
- *
10
- * @param this
11
- */
12
- export async function showBlockToolbar( this: Editor ) {
13
- // Move the mouse to disable the isTyping mode. We need at least three
14
- // mousemove events for it to work across windows (iframe). With three
15
- // moves, it's a guarantee that at least two will be in the same window.
16
- // Two events are required for the flag to be unset.
17
- await this.page.mouse.move( 50, 50 );
18
- await this.page.mouse.move( 75, 75 );
19
- await this.page.mouse.move( 100, 100 );
20
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Editor } from './index';
5
-
6
- interface Options {
7
- // If the only dirty entity is the current one, skip opening the save panel.
8
- isOnlyCurrentEntityDirty?: boolean;
9
- }
10
-
11
- /**
12
- * Save entities in the site editor. Assumes the editor is in a dirty state.
13
- *
14
- * @param this
15
- * @param options
16
- */
17
- export async function saveSiteEditorEntities(
18
- this: Editor,
19
- options: Options = {}
20
- ) {
21
- const editorTopBar = this.page.getByRole( 'region', {
22
- name: 'Editor top bar',
23
- } );
24
-
25
- // If we have changes in a single entity which can be published the label is `Publish`.
26
- const saveButton = editorTopBar.getByRole( 'button', {
27
- name: 'Save',
28
- exact: true,
29
- } );
30
- const publishButton = editorTopBar.getByRole( 'button', {
31
- name: 'Publish',
32
- } );
33
- const publishButtonIsVisible = ! ( await saveButton.isVisible() );
34
- // First Save button in the top bar.
35
- const buttonToClick = publishButtonIsVisible ? publishButton : saveButton;
36
- await buttonToClick.click();
37
-
38
- if ( ! options.isOnlyCurrentEntityDirty ) {
39
- // Second Save button in the entities panel.
40
- await this.page
41
- .getByRole( 'region', {
42
- name: /(Editor publish|Save panel)/,
43
- } )
44
- .getByRole( 'button', { name: 'Save', exact: true } )
45
- .click();
46
- }
47
- // The text in the notice can be different based on the edited entity, whether
48
- // we are saving multiple entities and whether we publish or update. So for now,
49
- // we locate it based on the last part.
50
- await this.page
51
- .getByRole( 'button', { name: 'Dismiss this notice' } )
52
- .getByText( /(updated|published)\./ )
53
- .first()
54
- .waitFor();
55
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Editor } from './index';
5
-
6
- /**
7
- * Switch the editor tool being used.
8
- *
9
- * @param this
10
- * @param label The text string of the button label.
11
- */
12
- export async function switchEditorTool( this: Editor, label: string ) {
13
- const toolsToolbar = this.page.getByRole( 'toolbar', {
14
- name: 'Document tools',
15
- } );
16
- await toolsToolbar
17
- .getByRole( 'button', {
18
- name: 'Tools',
19
- } )
20
- .click();
21
- const menu = this.page.getByRole( 'menu', {
22
- name: 'Tools',
23
- } );
24
- await menu
25
- .getByRole( 'menuitemradio', {
26
- name: label,
27
- } )
28
- .click();
29
- await toolsToolbar
30
- .getByRole( 'button', {
31
- name: 'Tools',
32
- } )
33
- .click();
34
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Editor } from './index';
5
-
6
- /**
7
- * Switches to legacy (non-iframed) canvas.
8
- *
9
- * @param this
10
- */
11
- export async function switchToLegacyCanvas( this: Editor ) {
12
- await this.page.waitForFunction( () => window?.wp?.blocks );
13
-
14
- await this.page.evaluate( () => {
15
- window.wp.blocks.registerBlockType( 'test/v2', {
16
- apiVersion: '2',
17
- title: 'test',
18
- } );
19
- } );
20
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { Editor } from './index';
5
-
6
- /**
7
- * Clicks the default block appender.
8
- *
9
- * @param this
10
- * @param name Block name.
11
- */
12
- export async function transformBlockTo( this: Editor, name: string ) {
13
- await this.page.waitForFunction(
14
- () => window?.wp?.blocks && window?.wp?.data
15
- );
16
-
17
- await this.page.evaluate(
18
- ( [ blockName ] ) => {
19
- const clientIds = window.wp.data
20
- .select( 'core/block-editor' )
21
- .getSelectedBlockClientIds();
22
- const blocks = window.wp.data
23
- .select( 'core/block-editor' )
24
- .getBlocksByClientId( clientIds );
25
- window.wp.data
26
- .dispatch( 'core/block-editor' )
27
- .replaceBlocks(
28
- clientIds,
29
- window.wp.blocks.switchToBlockType( blocks, blockName )
30
- );
31
- },
32
- [ name ]
33
- );
34
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export type * from './types';
2
- export { Admin } from './admin';
3
- export { Editor } from './editor';
4
- export { PageUtils } from './page-utils';
5
- export { RequestUtils } from './request-utils';
6
- export { Metrics } from './metrics';
7
- export { Lighthouse } from './lighthouse';
8
- export { test, expect } from './test';
@@ -1,75 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { Page } from '@playwright/test';
5
- import lighthouse from 'lighthouse/core/index.cjs';
6
-
7
- type LighthouseConstructorProps = {
8
- page: Page;
9
- port: number;
10
- };
11
-
12
- export class Lighthouse {
13
- page: Page;
14
- port: number;
15
-
16
- constructor( { page, port }: LighthouseConstructorProps ) {
17
- this.page = page;
18
- this.port = port;
19
- }
20
-
21
- /**
22
- * Returns the Lighthouse report for the current URL.
23
- *
24
- * Runs several Lighthouse audits in a separate browser window and returns
25
- * the summary.
26
- */
27
- async getReport() {
28
- // From https://github.com/GoogleChrome/lighthouse/blob/36cac182a6c637b1671c57326d7c0241633d0076/core/config/default-config.js#L381-L446
29
- const audits = {
30
- 'largest-contentful-paint': 'LCP',
31
- 'total-blocking-time': 'TBT',
32
- interactive: 'TTI',
33
- 'cumulative-layout-shift': 'CLS',
34
- 'interaction-to-next-paint': 'INP',
35
- };
36
-
37
- const report = await lighthouse(
38
- this.page.url(),
39
- { port: this.port },
40
- {
41
- extends: 'lighthouse:default',
42
- settings: {
43
- // "provided" means no throttling.
44
- // TODO: Make configurable.
45
- throttlingMethod: 'provided',
46
- // Default is "mobile".
47
- // See https://github.com/GoogleChrome/lighthouse/blob/main/docs/emulation.md
48
- // TODO: Make configurable.
49
- formFactor: 'desktop',
50
- screenEmulation: {
51
- disabled: true,
52
- },
53
- // Speeds up the report.
54
- disableFullPageScreenshot: true,
55
- // Only run certain audits to speed things up.
56
- onlyAudits: Object.keys( audits ),
57
- },
58
- }
59
- );
60
-
61
- const result: Record< string, number > = {};
62
-
63
- if ( ! report ) {
64
- return result;
65
- }
66
-
67
- const { lhr } = report;
68
-
69
- for ( const [ audit, acronym ] of Object.entries( audits ) ) {
70
- result[ acronym ] = lhr.audits[ audit ]?.numericValue || 0;
71
- }
72
-
73
- return result;
74
- }
75
- }