@wordpress/e2e-test-utils-playwright 0.1.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 (183) hide show
  1. package/LICENSE.md +788 -0
  2. package/README.md +89 -0
  3. package/build/admin/create-new-post.js +49 -0
  4. package/build/admin/create-new-post.js.map +1 -0
  5. package/build/admin/get-page-error.js +27 -0
  6. package/build/admin/get-page-error.js.map +1 -0
  7. package/build/admin/index.js +32 -0
  8. package/build/admin/index.js.map +1 -0
  9. package/build/admin/visit-admin-page.js +33 -0
  10. package/build/admin/visit-admin-page.js.map +1 -0
  11. package/build/admin/visit-site-editor.js +42 -0
  12. package/build/admin/visit-site-editor.js.map +1 -0
  13. package/build/config.js +13 -0
  14. package/build/config.js.map +1 -0
  15. package/build/editor/click-block-options-menu-item.js +17 -0
  16. package/build/editor/click-block-options-menu-item.js.map +1 -0
  17. package/build/editor/click-block-toolbar-button.js +17 -0
  18. package/build/editor/click-block-toolbar-button.js.map +1 -0
  19. package/build/editor/get-blocks.js +23 -0
  20. package/build/editor/get-blocks.js.map +1 -0
  21. package/build/editor/get-edited-post-content.js +15 -0
  22. package/build/editor/get-edited-post-content.js.map +1 -0
  23. package/build/editor/index.js +63 -0
  24. package/build/editor/index.js.map +1 -0
  25. package/build/editor/insert-block.js +20 -0
  26. package/build/editor/insert-block.js.map +1 -0
  27. package/build/editor/open-document-settings-sidebar.js +27 -0
  28. package/build/editor/open-document-settings-sidebar.js.map +1 -0
  29. package/build/editor/preview.js +22 -0
  30. package/build/editor/preview.js.map +1 -0
  31. package/build/editor/publish-post.js +30 -0
  32. package/build/editor/publish-post.js.map +1 -0
  33. package/build/editor/select-blocks.js +29 -0
  34. package/build/editor/select-blocks.js.map +1 -0
  35. package/build/editor/set-content.js +17 -0
  36. package/build/editor/set-content.js.map +1 -0
  37. package/build/editor/set-is-fixed-toolbar.js +20 -0
  38. package/build/editor/set-is-fixed-toolbar.js.map +1 -0
  39. package/build/editor/show-block-toolbar.js +20 -0
  40. package/build/editor/show-block-toolbar.js.map +1 -0
  41. package/build/editor/site-editor.js +19 -0
  42. package/build/editor/site-editor.js.map +1 -0
  43. package/build/editor/transform-block-to.js +24 -0
  44. package/build/editor/transform-block-to.js.map +1 -0
  45. package/build/index.js +30 -0
  46. package/build/index.js.map +1 -0
  47. package/build/page-utils/drag-files.js +115 -0
  48. package/build/page-utils/drag-files.js.map +1 -0
  49. package/build/page-utils/index.js +32 -0
  50. package/build/page-utils/index.js.map +1 -0
  51. package/build/page-utils/is-current-url.js +22 -0
  52. package/build/page-utils/is-current-url.js.map +1 -0
  53. package/build/page-utils/press-keys.js +123 -0
  54. package/build/page-utils/press-keys.js.map +1 -0
  55. package/build/page-utils/set-browser-viewport.js +47 -0
  56. package/build/page-utils/set-browser-viewport.js.map +1 -0
  57. package/build/request-utils/blocks.js +30 -0
  58. package/build/request-utils/blocks.js.map +1 -0
  59. package/build/request-utils/comments.js +52 -0
  60. package/build/request-utils/comments.js.map +1 -0
  61. package/build/request-utils/index.js +148 -0
  62. package/build/request-utils/index.js.map +1 -0
  63. package/build/request-utils/login.js +22 -0
  64. package/build/request-utils/login.js.map +1 -0
  65. package/build/request-utils/media.js +74 -0
  66. package/build/request-utils/media.js.map +1 -0
  67. package/build/request-utils/menus.js +121 -0
  68. package/build/request-utils/menus.js.map +1 -0
  69. package/build/request-utils/pages.js +59 -0
  70. package/build/request-utils/pages.js.map +1 -0
  71. package/build/request-utils/plugins.js +69 -0
  72. package/build/request-utils/plugins.js.map +1 -0
  73. package/build/request-utils/posts.js +47 -0
  74. package/build/request-utils/posts.js.map +1 -0
  75. package/build/request-utils/preferences.js +21 -0
  76. package/build/request-utils/preferences.js.map +1 -0
  77. package/build/request-utils/rest.js +130 -0
  78. package/build/request-utils/rest.js.map +1 -0
  79. package/build/request-utils/site-settings.js +34 -0
  80. package/build/request-utils/site-settings.js.map +1 -0
  81. package/build/request-utils/templates.js +39 -0
  82. package/build/request-utils/templates.js.map +1 -0
  83. package/build/request-utils/themes.js +56 -0
  84. package/build/request-utils/themes.js.map +1 -0
  85. package/build/request-utils/users.js +82 -0
  86. package/build/request-utils/users.js.map +1 -0
  87. package/build/request-utils/widgets.js +62 -0
  88. package/build/request-utils/widgets.js.map +1 -0
  89. package/build/test.js +122 -0
  90. package/build/test.js.map +1 -0
  91. package/build/types.js +3 -0
  92. package/build/types.js.map +1 -0
  93. package/build-types/admin/create-new-post.d.ts +19 -0
  94. package/build-types/admin/create-new-post.d.ts.map +1 -0
  95. package/build-types/admin/get-page-error.d.ts +17 -0
  96. package/build-types/admin/get-page-error.d.ts.map +1 -0
  97. package/build-types/admin/index.d.ts +33 -0
  98. package/build-types/admin/index.d.ts.map +1 -0
  99. package/build-types/admin/visit-admin-page.d.ts +13 -0
  100. package/build-types/admin/visit-admin-page.d.ts.map +1 -0
  101. package/build-types/admin/visit-site-editor.d.ts +19 -0
  102. package/build-types/admin/visit-site-editor.d.ts.map +1 -0
  103. package/build-types/config.d.ts +7 -0
  104. package/build-types/config.d.ts.map +1 -0
  105. package/build-types/editor/click-block-options-menu-item.d.ts +12 -0
  106. package/build-types/editor/click-block-options-menu-item.d.ts.map +1 -0
  107. package/build-types/editor/click-block-toolbar-button.d.ts +12 -0
  108. package/build-types/editor/click-block-toolbar-button.d.ts.map +1 -0
  109. package/build-types/editor/get-blocks.d.ts +13 -0
  110. package/build-types/editor/get-blocks.d.ts.map +1 -0
  111. package/build-types/editor/get-edited-post-content.d.ts +13 -0
  112. package/build-types/editor/get-edited-post-content.d.ts.map +1 -0
  113. package/build-types/editor/index.d.ts +61 -0
  114. package/build-types/editor/index.d.ts.map +1 -0
  115. package/build-types/editor/insert-block.d.ts +19 -0
  116. package/build-types/editor/insert-block.d.ts.map +1 -0
  117. package/build-types/editor/open-document-settings-sidebar.d.ts +12 -0
  118. package/build-types/editor/open-document-settings-sidebar.d.ts.map +1 -0
  119. package/build-types/editor/preview.d.ts +17 -0
  120. package/build-types/editor/preview.d.ts.map +1 -0
  121. package/build-types/editor/publish-post.d.ts +12 -0
  122. package/build-types/editor/publish-post.d.ts.map +1 -0
  123. package/build-types/editor/select-blocks.d.ts +10 -0
  124. package/build-types/editor/select-blocks.d.ts.map +1 -0
  125. package/build-types/editor/set-content.d.ts +13 -0
  126. package/build-types/editor/set-content.d.ts.map +1 -0
  127. package/build-types/editor/set-is-fixed-toolbar.d.ts +12 -0
  128. package/build-types/editor/set-is-fixed-toolbar.d.ts.map +1 -0
  129. package/build-types/editor/show-block-toolbar.d.ts +12 -0
  130. package/build-types/editor/show-block-toolbar.d.ts.map +1 -0
  131. package/build-types/editor/site-editor.d.ts +11 -0
  132. package/build-types/editor/site-editor.d.ts.map +1 -0
  133. package/build-types/editor/transform-block-to.d.ts +12 -0
  134. package/build-types/editor/transform-block-to.d.ts.map +1 -0
  135. package/build-types/index.d.ts +7 -0
  136. package/build-types/index.d.ts.map +1 -0
  137. package/build-types/page-utils/drag-files.d.ts +40 -0
  138. package/build-types/page-utils/drag-files.d.ts.map +1 -0
  139. package/build-types/page-utils/index.d.ts +32 -0
  140. package/build-types/page-utils/index.d.ts.map +1 -0
  141. package/build-types/page-utils/is-current-url.d.ts +11 -0
  142. package/build-types/page-utils/is-current-url.d.ts.map +1 -0
  143. package/build-types/page-utils/press-keys.d.ts +25 -0
  144. package/build-types/page-utils/press-keys.d.ts.map +1 -0
  145. package/build-types/page-utils/set-browser-viewport.d.ts +34 -0
  146. package/build-types/page-utils/set-browser-viewport.d.ts.map +1 -0
  147. package/build-types/request-utils/blocks.d.ts +8 -0
  148. package/build-types/request-utils/blocks.d.ts.map +1 -0
  149. package/build-types/request-utils/comments.d.ts +31 -0
  150. package/build-types/request-utils/comments.d.ts.map +1 -0
  151. package/build-types/request-utils/index.d.ts +111 -0
  152. package/build-types/request-utils/index.d.ts.map +1 -0
  153. package/build-types/request-utils/login.d.ts +11 -0
  154. package/build-types/request-utils/login.d.ts.map +1 -0
  155. package/build-types/request-utils/media.d.ts +54 -0
  156. package/build-types/request-utils/media.d.ts.map +1 -0
  157. package/build-types/request-utils/menus.d.ts +43 -0
  158. package/build-types/request-utils/menus.d.ts.map +1 -0
  159. package/build-types/request-utils/pages.d.ts +32 -0
  160. package/build-types/request-utils/pages.d.ts.map +1 -0
  161. package/build-types/request-utils/plugins.d.ts +28 -0
  162. package/build-types/request-utils/plugins.d.ts.map +1 -0
  163. package/build-types/request-utils/posts.d.ts +30 -0
  164. package/build-types/request-utils/posts.d.ts.map +1 -0
  165. package/build-types/request-utils/preferences.d.ts +11 -0
  166. package/build-types/request-utils/preferences.d.ts.map +1 -0
  167. package/build-types/request-utils/rest.d.ts +24 -0
  168. package/build-types/request-utils/rest.d.ts.map +1 -0
  169. package/build-types/request-utils/site-settings.d.ts +40 -0
  170. package/build-types/request-utils/site-settings.d.ts.map +1 -0
  171. package/build-types/request-utils/templates.d.ts +14 -0
  172. package/build-types/request-utils/templates.d.ts.map +1 -0
  173. package/build-types/request-utils/themes.d.ts +15 -0
  174. package/build-types/request-utils/themes.d.ts.map +1 -0
  175. package/build-types/request-utils/users.d.ts +40 -0
  176. package/build-types/request-utils/users.d.ts.map +1 -0
  177. package/build-types/request-utils/widgets.d.ts +15 -0
  178. package/build-types/request-utils/widgets.d.ts.map +1 -0
  179. package/build-types/test.d.ts +15 -0
  180. package/build-types/test.d.ts.map +1 -0
  181. package/build-types/types.d.ts +7 -0
  182. package/build-types/types.d.ts.map +1 -0
  183. package/package.json +47 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setContent = void 0;
4
+ /**
5
+ * Set the content of the editor.
6
+ *
7
+ * @param this
8
+ * @param html Serialized block HTML.
9
+ */
10
+ async function setContent(html) {
11
+ await this.page.evaluate((_html) => {
12
+ const blocks = window.wp.blocks.parse(_html);
13
+ window.wp.data.dispatch('core/block-editor').resetBlocks(blocks);
14
+ }, html);
15
+ }
16
+ exports.setContent = setContent;
17
+ //# sourceMappingURL=set-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-content.js","sourceRoot":"","sources":["../../src/editor/set-content.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACH,KAAK,UAAU,UAAU,CAAgB,IAAY;IACpD,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAE,KAAK,EAAG,EAAE;QACrC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAE,KAAK,CAAE,CAAC;QAE/C,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAE,mBAAmB,CAAE,CAAC,WAAW,CAAE,MAAM,CAAE,CAAC;IACtE,CAAC,EAAE,IAAI,CAAE,CAAC;AACX,CAAC;AAEQ,gCAAU"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setIsFixedToolbar = void 0;
4
+ /**
5
+ * Toggles the fixed toolbar option.
6
+ *
7
+ * @param this
8
+ * @param isFixed Boolean value true/false for on/off.
9
+ */
10
+ async function setIsFixedToolbar(isFixed) {
11
+ await this.page.evaluate((_isFixed) => {
12
+ const { select, dispatch } = window.wp.data;
13
+ const isCurrentlyFixed = select('core/edit-post').isFeatureActive('fixedToolbar');
14
+ if (isCurrentlyFixed !== _isFixed) {
15
+ dispatch('core/edit-post').toggleFeature('fixedToolbar');
16
+ }
17
+ }, isFixed);
18
+ }
19
+ exports.setIsFixedToolbar = setIsFixedToolbar;
20
+ //# sourceMappingURL=set-is-fixed-toolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-is-fixed-toolbar.js","sourceRoot":"","sources":["../../src/editor/set-is-fixed-toolbar.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CAAgB,OAAgB;IACtE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAE,QAAQ,EAAG,EAAE;QACxC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;QAC5C,MAAM,gBAAgB,GACrB,MAAM,CAAE,gBAAgB,CAAE,CAAC,eAAe,CAAE,cAAc,CAAE,CAAC;QAC9D,IAAK,gBAAgB,KAAK,QAAQ,EAAG;YACpC,QAAQ,CAAE,gBAAgB,CAAE,CAAC,aAAa,CAAE,cAAc,CAAE,CAAC;SAC7D;IACF,CAAC,EAAE,OAAO,CAAE,CAAC;AACd,CAAC;AATD,8CASC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.showBlockToolbar = void 0;
4
+ /**
5
+ * The block toolbar is not always visible while typing.
6
+ * Call this function to reveal it.
7
+ *
8
+ * @param this
9
+ */
10
+ async function showBlockToolbar() {
11
+ // Move the mouse to disable the isTyping mode. We need at least three
12
+ // mousemove events for it to work across windows (iframe). With three
13
+ // moves, it's a guarantee that at least two will be in the same window.
14
+ // Two events are required for the flag to be unset.
15
+ await this.page.mouse.move(50, 50);
16
+ await this.page.mouse.move(75, 75);
17
+ await this.page.mouse.move(100, 100);
18
+ }
19
+ exports.showBlockToolbar = showBlockToolbar;
20
+ //# sourceMappingURL=show-block-toolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-block-toolbar.js","sourceRoot":"","sources":["../../src/editor/show-block-toolbar.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB;IACrC,sEAAsE;IACtE,sEAAsE;IACtE,wEAAwE;IACxE,oDAAoD;IACpD,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAE,EAAE,EAAE,EAAE,CAAE,CAAC;IACrC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAE,EAAE,EAAE,EAAE,CAAE,CAAC;IACrC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAE,GAAG,EAAE,GAAG,CAAE,CAAC;AACxC,CAAC;AARD,4CAQC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.saveSiteEditorEntities = void 0;
4
+ /**
5
+ * Save entities in the site editor. Assumes the editor is in a dirty state.
6
+ *
7
+ * @param this
8
+ */
9
+ async function saveSiteEditorEntities() {
10
+ await this.page.click('role=region[name="Editor top bar"i] >> role=button[name="Save"i]');
11
+ // Second Save button in the entities panel.
12
+ await this.page.click('role=region[name="Save panel"i] >> role=button[name="Save"i]');
13
+ // A role selector cannot be used here because it needs to check that the `is-busy` class is not present.
14
+ await this.page.waitForSelector('[aria-label="Saved"].is-busy', {
15
+ state: 'hidden',
16
+ });
17
+ }
18
+ exports.saveSiteEditorEntities = saveSiteEditorEntities;
19
+ //# sourceMappingURL=site-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-editor.js","sourceRoot":"","sources":["../../src/editor/site-editor.ts"],"names":[],"mappings":";;;AAKA;;;;GAIG;AACI,KAAK,UAAU,sBAAsB;IAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,kEAAkE,CAClE,CAAC;IACF,4CAA4C;IAC5C,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,8DAA8D,CAC9D,CAAC;IACF,yGAAyG;IACzG,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAE,8BAA8B,EAAE;QAChE,KAAK,EAAE,QAAQ;KACf,CAAE,CAAC;AACL,CAAC;AAZD,wDAYC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformBlockTo = void 0;
4
+ /**
5
+ * Clicks the default block appender.
6
+ *
7
+ * @param this
8
+ * @param name Block name.
9
+ */
10
+ async function transformBlockTo(name) {
11
+ await this.page.evaluate(([blockName]) => {
12
+ const clientIds = window.wp.data
13
+ .select('core/block-editor')
14
+ .getSelectedBlockClientIds();
15
+ const blocks = window.wp.data
16
+ .select('core/block-editor')
17
+ .getBlocksByClientId(clientIds);
18
+ window.wp.data
19
+ .dispatch('core/block-editor')
20
+ .replaceBlocks(clientIds, window.wp.blocks.switchToBlockType(blocks, blockName));
21
+ }, [name]);
22
+ }
23
+ exports.transformBlockTo = transformBlockTo;
24
+ //# sourceMappingURL=transform-block-to.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-block-to.js","sourceRoot":"","sources":["../../src/editor/transform-block-to.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CAAgB,IAAY;IACjE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CACvB,CAAE,CAAE,SAAS,CAAE,EAAG,EAAE;QACnB,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI;aAC9B,MAAM,CAAE,mBAAmB,CAAE;aAC7B,yBAAyB,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI;aAC3B,MAAM,CAAE,mBAAmB,CAAE;aAC7B,mBAAmB,CAAE,SAAS,CAAE,CAAC;QACnC,MAAM,CAAC,EAAE,CAAC,IAAI;aACZ,QAAQ,CAAE,mBAAmB,CAAE;aAC/B,aAAa,CACb,SAAS,EACT,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAE,MAAM,EAAE,SAAS,CAAE,CACvD,CAAC;IACJ,CAAC,EACD,CAAE,IAAI,CAAE,CACR,CAAC;AACH,CAAC;AAlBD,4CAkBC"}
package/build/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.expect = exports.test = exports.RequestUtils = exports.PageUtils = exports.Editor = exports.Admin = void 0;
18
+ __exportStar(require("./types"), exports);
19
+ var admin_1 = require("./admin");
20
+ Object.defineProperty(exports, "Admin", { enumerable: true, get: function () { return admin_1.Admin; } });
21
+ var editor_1 = require("./editor");
22
+ Object.defineProperty(exports, "Editor", { enumerable: true, get: function () { return editor_1.Editor; } });
23
+ var page_utils_1 = require("./page-utils");
24
+ Object.defineProperty(exports, "PageUtils", { enumerable: true, get: function () { return page_utils_1.PageUtils; } });
25
+ var request_utils_1 = require("./request-utils");
26
+ Object.defineProperty(exports, "RequestUtils", { enumerable: true, get: function () { return request_utils_1.RequestUtils; } });
27
+ var test_1 = require("./test");
28
+ Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_1.test; } });
29
+ Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,+BAAsC;AAA7B,4FAAA,IAAI,OAAA;AAAE,8FAAA,MAAM,OAAA"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dragFiles = void 0;
4
+ /**
5
+ * External dependencies
6
+ */
7
+ const promises_1 = require("fs/promises");
8
+ const path_1 = require("path");
9
+ const mime_1 = require("mime");
10
+ /**
11
+ * Simulate dragging files from outside the current page.
12
+ *
13
+ * @param this
14
+ * @param files The files to be dragged.
15
+ * @return The methods of the drag operation.
16
+ */
17
+ async function dragFiles(files) {
18
+ const filesList = Array.isArray(files) ? files : [files];
19
+ const fileObjects = await Promise.all(filesList.map(async (filePathOrObject) => {
20
+ if (typeof filePathOrObject !== 'string') {
21
+ return {
22
+ name: filePathOrObject.name,
23
+ mimeType: filePathOrObject.mimeType ||
24
+ (0, mime_1.getType)(filePathOrObject.name),
25
+ base64: filePathOrObject.buffer.toString('base64'),
26
+ };
27
+ }
28
+ const base64 = await (0, promises_1.readFile)(filePathOrObject, 'base64');
29
+ const name = (0, path_1.basename)(filePathOrObject);
30
+ return {
31
+ name,
32
+ mimeType: (0, mime_1.getType)(filePathOrObject),
33
+ base64,
34
+ };
35
+ }));
36
+ const dataTransfer = await this.page.evaluateHandle(async (_fileObjects) => {
37
+ const dt = new DataTransfer();
38
+ const fileInstances = await Promise.all(_fileObjects.map(async (fileObject) => {
39
+ const blob = await fetch(`data:${fileObject.mimeType};base64,${fileObject.base64}`).then((res) => res.blob());
40
+ return new File([blob], fileObject.name, {
41
+ type: fileObject.mimeType ?? undefined,
42
+ });
43
+ }));
44
+ fileInstances.forEach((file) => {
45
+ dt.items.add(file);
46
+ });
47
+ return dt;
48
+ }, fileObjects);
49
+ // CDP doesn't actually support dragging files, this is only a _good enough_
50
+ // dummy data so that it will correctly send the relevant events.
51
+ const dragData = {
52
+ items: fileObjects.map((fileObject) => ({
53
+ mimeType: fileObject.mimeType ?? 'File',
54
+ data: fileObject.base64,
55
+ })),
56
+ files: fileObjects.map((fileObject) => fileObject.name),
57
+ // Copy = 1, Link = 2, Move = 16.
58
+ dragOperationsMask: 1,
59
+ };
60
+ const cdpSession = await this.context.newCDPSession(this.page);
61
+ const position = {
62
+ x: 0,
63
+ y: 0,
64
+ };
65
+ return {
66
+ /**
67
+ * Drag the files over an element (fires `dragenter` and `dragover` events).
68
+ *
69
+ * @param selectorOrLocator A selector or a locator to search for an element.
70
+ * @param options The optional options.
71
+ * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
72
+ */
73
+ dragOver: async (selectorOrLocator, options = {}) => {
74
+ const locator = typeof selectorOrLocator === 'string'
75
+ ? this.page.locator(selectorOrLocator)
76
+ : selectorOrLocator;
77
+ const boundingBox = await locator.boundingBox();
78
+ if (!boundingBox) {
79
+ throw new Error('Cannot find the element or the element is not visible on the viewport.');
80
+ }
81
+ position.x =
82
+ boundingBox.x +
83
+ (options.position?.x ?? boundingBox.width / 2);
84
+ position.y =
85
+ boundingBox.y +
86
+ (options.position?.y ?? boundingBox.height / 2);
87
+ await cdpSession.send('Input.dispatchDragEvent', {
88
+ type: 'dragEnter',
89
+ ...position,
90
+ data: dragData,
91
+ });
92
+ await cdpSession.send('Input.dispatchDragEvent', {
93
+ type: 'dragOver',
94
+ ...position,
95
+ data: dragData,
96
+ });
97
+ },
98
+ /**
99
+ * Drop the files at the current position.
100
+ */
101
+ drop: async () => {
102
+ const topMostElement = await this.page.evaluateHandle(({ x, y }) => {
103
+ return document.elementFromPoint(x, y);
104
+ }, position);
105
+ const elementHandle = topMostElement.asElement();
106
+ if (!elementHandle) {
107
+ throw new Error('Element not found.');
108
+ }
109
+ await elementHandle.dispatchEvent('drop', { dataTransfer });
110
+ await cdpSession.detach();
111
+ },
112
+ };
113
+ }
114
+ exports.dragFiles = dragFiles;
115
+ //# sourceMappingURL=drag-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-files.js","sourceRoot":"","sources":["../../src/page-utils/drag-files.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,0CAAuC;AACvC,+BAAgC;AAChC,+BAA+B;AAkB/B;;;;;;GAMG;AACH,KAA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AE,CAAC;QAC3B,CAAC;KACD,CAAC;AACH,CAAC;AAEQ,8BAAS"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageUtils = void 0;
4
+ /**
5
+ * Internal dependencies
6
+ */
7
+ const drag_files_1 = require("./drag-files");
8
+ const is_current_url_1 = require("./is-current-url");
9
+ const press_keys_1 = require("./press-keys");
10
+ const set_browser_viewport_1 = require("./set-browser-viewport");
11
+ class PageUtils {
12
+ browser;
13
+ page;
14
+ context;
15
+ constructor({ page }) {
16
+ this.page = page;
17
+ this.context = page.context();
18
+ this.browser = this.context.browser();
19
+ }
20
+ /** @borrows dragFiles as this.dragFiles */
21
+ dragFiles = drag_files_1.dragFiles.bind(this);
22
+ /** @borrows isCurrentURL as this.isCurrentURL */
23
+ isCurrentURL = is_current_url_1.isCurrentURL.bind(this);
24
+ /** @borrows pressKeys as this.pressKeys */
25
+ pressKeys = press_keys_1.pressKeys.bind(this);
26
+ /** @borrows setBrowserViewport as this.setBrowserViewport */
27
+ setBrowserViewport = set_browser_viewport_1.setBrowserViewport.bind(this);
28
+ /** @borrows setClipboardData as this.setClipboardData */
29
+ setClipboardData = press_keys_1.setClipboardData.bind(this);
30
+ }
31
+ exports.PageUtils = PageUtils;
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page-utils/index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,6CAAyC;AACzC,qDAAgD;AAChD,6CAA2D;AAC3D,iEAA4D;AAM5D,MAAM,SAAS;IACd,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,OAAO,CAAiB;IAExB,YAAa,EAAE,IAAI,EAA6B;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAG,CAAC;IACxC,CAAC;IAED,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,iDAAiD;IACjD,YAAY,GAAwB,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC9D,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,6DAA6D;IAC7D,kBAAkB,GACjB,yCAAkB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACjC,yDAAyD;IACzD,gBAAgB,GAA4B,6BAAgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CAC1E;AAEQ,8BAAS"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCurrentURL = void 0;
4
+ /**
5
+ * Internal dependencies
6
+ */
7
+ const config_1 = require("../config");
8
+ /**
9
+ * Checks if current path of the URL matches the provided path.
10
+ *
11
+ * @param this
12
+ * @param path String to be serialized as pathname.
13
+ *
14
+ * @return Boolean represents whether current URL is or not a WordPress path.
15
+ */
16
+ function isCurrentURL(path) {
17
+ const currentURL = new URL(this.page.url());
18
+ const expectedURL = new URL(path, config_1.WP_BASE_URL);
19
+ return expectedURL.pathname === currentURL.pathname;
20
+ }
21
+ exports.isCurrentURL = isCurrentURL;
22
+ //# sourceMappingURL=is-current-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-current-url.js","sourceRoot":"","sources":["../../src/page-utils/is-current-url.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,sCAAwC;AAGxC;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAmB,IAAY;IAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAE,CAAC;IAC9C,MAAM,WAAW,GAAG,IAAI,GAAG,CAAE,IAAI,EAAE,oBAAW,CAAE,CAAC;IAEjD,OAAO,WAAW,CAAC,QAAQ,KAAK,UAAU,CAAC,QAAQ,CAAC;AACrD,CAAC;AALD,oCAKC"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pressKeys = exports.setClipboardData = void 0;
4
+ /**
5
+ * External dependencies
6
+ */
7
+ const change_case_1 = require("change-case");
8
+ /**
9
+ * WordPress dependencies
10
+ */
11
+ const keycodes_1 = require("@wordpress/keycodes");
12
+ let clipboardDataHolder = {
13
+ plainText: '',
14
+ html: '',
15
+ };
16
+ /**
17
+ * Sets the clipboard data that can be pasted with
18
+ * `pressKeys( 'primary+v' )`.
19
+ *
20
+ * @param this
21
+ * @param clipboardData
22
+ * @param clipboardData.plainText
23
+ * @param clipboardData.html
24
+ */
25
+ function setClipboardData({ plainText = '', html = '' }) {
26
+ clipboardDataHolder = {
27
+ plainText,
28
+ html,
29
+ };
30
+ }
31
+ exports.setClipboardData = setClipboardData;
32
+ async function emulateClipboard(page, type) {
33
+ clipboardDataHolder = await page.evaluate(([_type, _clipboardData]) => {
34
+ const clipboardDataTransfer = new DataTransfer();
35
+ if (_type === 'paste') {
36
+ clipboardDataTransfer.setData('text/plain', _clipboardData.plainText);
37
+ clipboardDataTransfer.setData('text/html', _clipboardData.html);
38
+ }
39
+ else {
40
+ const selection = window.getSelection();
41
+ const plainText = selection.toString();
42
+ let html = plainText;
43
+ if (selection.rangeCount) {
44
+ const range = selection.getRangeAt(0);
45
+ const fragment = range.cloneContents();
46
+ html = Array.from(fragment.childNodes)
47
+ .map((node) => node.outerHTML ?? node.nodeValue)
48
+ .join('');
49
+ }
50
+ clipboardDataTransfer.setData('text/plain', plainText);
51
+ clipboardDataTransfer.setData('text/html', html);
52
+ }
53
+ document.activeElement?.dispatchEvent(new ClipboardEvent(_type, {
54
+ bubbles: true,
55
+ cancelable: true,
56
+ clipboardData: clipboardDataTransfer,
57
+ }));
58
+ return {
59
+ plainText: clipboardDataTransfer.getData('text/plain'),
60
+ html: clipboardDataTransfer.getData('text/html'),
61
+ };
62
+ }, [type, clipboardDataHolder]);
63
+ }
64
+ const isAppleOS = () => process.platform === 'darwin';
65
+ const isWebkit = (page) => page.context().browser().browserType().name() === 'webkit';
66
+ const browserCache = new WeakMap();
67
+ const getHasNaturalTabNavigation = async (page) => {
68
+ if (!isAppleOS() || !isWebkit(page)) {
69
+ return true;
70
+ }
71
+ if (browserCache.has(page.context().browser())) {
72
+ return browserCache.get(page.context().browser());
73
+ }
74
+ const testPage = await page.context().newPage();
75
+ await testPage.setContent(`<button>1</button><button>2</button>`);
76
+ await testPage.getByText('1').focus();
77
+ await testPage.keyboard.press('Tab');
78
+ const featureDetected = await testPage
79
+ .getByText('2')
80
+ .evaluate((node) => node === document.activeElement);
81
+ browserCache.set(page.context().browser(), featureDetected);
82
+ await testPage.close();
83
+ return featureDetected;
84
+ };
85
+ const modifiers = {
86
+ ...keycodes_1.modifiers,
87
+ shiftAlt: (_isApple) => _isApple() ? [keycodes_1.SHIFT, keycodes_1.ALT] : [keycodes_1.SHIFT, keycodes_1.CTRL],
88
+ };
89
+ async function pressKeys(key, { times, ...pressOptions } = {}) {
90
+ const hasNaturalTabNavigation = await getHasNaturalTabNavigation(this.page);
91
+ let command;
92
+ if (key.toLowerCase() === 'primary+c') {
93
+ command = () => emulateClipboard(this.page, 'copy');
94
+ }
95
+ else if (key.toLowerCase() === 'primary+x') {
96
+ command = () => emulateClipboard(this.page, 'cut');
97
+ }
98
+ else if (key.toLowerCase() === 'primary+v') {
99
+ command = () => emulateClipboard(this.page, 'paste');
100
+ }
101
+ else {
102
+ const keys = key.split('+').flatMap((keyCode) => {
103
+ if (Object.prototype.hasOwnProperty.call(modifiers, keyCode)) {
104
+ return modifiers[keyCode](isAppleOS).map((modifier) => modifier === keycodes_1.CTRL ? 'Control' : (0, change_case_1.capitalCase)(modifier));
105
+ }
106
+ else if (keyCode === 'Tab' && !hasNaturalTabNavigation) {
107
+ return ['Alt', 'Tab'];
108
+ }
109
+ return keyCode;
110
+ });
111
+ const normalizedKeys = keys.join('+');
112
+ command = () => this.page.keyboard.press(normalizedKeys);
113
+ }
114
+ times = times ?? 1;
115
+ for (let i = 0; i < times; i += 1) {
116
+ await command();
117
+ if (times > 1 && pressOptions.delay) {
118
+ await this.page.waitForTimeout(pressOptions.delay);
119
+ }
120
+ }
121
+ }
122
+ exports.pressKeys = pressKeys;
123
+ //# sourceMappingURL=press-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"press-keys.js","sourceRoot":"","sources":["../../src/page-utils/press-keys.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,6CAA0C;AAQ1C;;GAEG;AACH,kDAK6B;AAE7B,IAAI,mBAAmB,GAGnB;IACH,SAAS,EAAE,EAAE;IACb,IAAI,EAAE,EAAE;CACR,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,gBAAgB,CAE/B,EAAE,SAAS,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,EAA8B;IAEzD,mBAAmB,GAAG;QACrB,SAAS;QACT,IAAI;KACJ,CAAC;AACH,CAAC;AARD,4CAQC;AAED,KAAK,UAAU,gBAAgB,CAAE,IAAU,EAAE,IAA8B;IAC1E,mBAAmB,GAAG,MAAM,IAAI,CAAC,QAAQ,CACxC,CAAE,CAAE,KAAK,EAAE,cAAc,CAAE,EAAG,EAAE;QAC/B,MAAM,qBAAqB,GAAG,IAAI,YAAY,EAAE,CAAC;QAEjD,IAAK,KAAK,KAAK,OAAO,EAAG;YACxB,qBAAqB,CAAC,OAAO,CAC5B,YAAY,EACZ,cAAc,CAAC,SAAS,CACxB,CAAC;YACF,qBAAqB,CAAC,OAAO,CAC5B,WAAW,EACX,cAAc,CAAC,IAAI,CACnB,CAAC;SACF;aAAM;YACN,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAG,CAAC;YACzC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE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AG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAE,cAAc,CAAE,CAAC;KAC3D;IAED,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;IACnB,KAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,CAAC,EAAG;QACpC,MAAM,OAAO,EAAE,CAAC;QAEhB,IAAK,KAAK,GAAG,CAAC,IAAI,YAAY,CAAC,KAAK,EAAG;YACtC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAE,YAAY,CAAC,KAAK,CAAE,CAAC;SACrD;KACD;AACF,CAAC;AA1CD,8BA0CC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Named viewport options.
4
+ *
5
+ * @typedef {"large"|"medium"|"small"} WPDimensionsName
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.setBrowserViewport = void 0;
9
+ /**
10
+ * Viewport dimensions object.
11
+ *
12
+ * @typedef {Object} WPViewportDimensions
13
+ *
14
+ * @property {number} width Width, in pixels.
15
+ * @property {number} height Height, in pixels.
16
+ */
17
+ /**
18
+ * Predefined viewport dimensions to reference by name.
19
+ *
20
+ * @enum {WPViewportDimensions}
21
+ *
22
+ * @type {Record<WPDimensionsName, WPViewportDimensions>}
23
+ */
24
+ const PREDEFINED_DIMENSIONS = {
25
+ large: { width: 960, height: 700 },
26
+ medium: { width: 768, height: 700 },
27
+ small: { width: 600, height: 700 },
28
+ };
29
+ /**
30
+ * Valid argument argument type from which to derive viewport dimensions.
31
+ *
32
+ * @typedef {WPDimensionsName|WPViewportDimensions} WPViewport
33
+ */
34
+ /**
35
+ * Sets browser viewport to specified type.
36
+ *
37
+ * @this {import('./').PageUtils}
38
+ * @param {WPViewport} viewport Viewport name or dimensions object to assign.
39
+ */
40
+ async function setBrowserViewport(viewport) {
41
+ const dimensions = typeof viewport === 'string'
42
+ ? PREDEFINED_DIMENSIONS[viewport]
43
+ : viewport;
44
+ await this.page.setViewportSize(dimensions);
45
+ }
46
+ exports.setBrowserViewport = setBrowserViewport;
47
+ //# sourceMappingURL=set-browser-viewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-browser-viewport.js","sourceRoot":"","sources":["../../src/page-utils/set-browser-viewport.js"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG;IAC7B,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IAClC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;IACnC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;CAClC,CAAC;AAEF;;;;GAIG;AAEH;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CAAE,QAAQ;IACjD,MAAM,UAAU,GACf,OAAO,QAAQ,KAAK,QAAQ;QAC3B,CAAC,CAAC,qBAAqB,CAAE,QAAQ,CAAE;QACnC,CAAC,CAAC,QAAQ,CAAC;IAEb,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAE,UAAU,CAAE,CAAC;AAC/C,CAAC;AAPD,gDAOC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteAllBlocks = void 0;
4
+ /**
5
+ * Delete all blocks using REST API.
6
+ *
7
+ * @see https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks
8
+ * @this {import('./index').RequestUtils}
9
+ */
10
+ async function deleteAllBlocks() {
11
+ // List all blocks.
12
+ // https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks
13
+ const blocks = await this.rest({
14
+ path: '/wp/v2/blocks',
15
+ params: {
16
+ per_page: 100,
17
+ // All possible statuses.
18
+ status: 'publish,future,draft,pending,private,trash',
19
+ },
20
+ });
21
+ // Delete blocks.
22
+ // https://developer.wordpress.org/rest-api/reference/blocks/#delete-a-editor-block
23
+ // "/wp/v2/posts" not yet supports batch requests.
24
+ await this.batchRest(blocks.map((block) => ({
25
+ method: 'DELETE',
26
+ path: `/wp/v2/blocks/${block.id}?force=true`,
27
+ })));
28
+ }
29
+ exports.deleteAllBlocks = deleteAllBlocks;
30
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/request-utils/blocks.js"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,KAAK,UAAU,eAAe;IACpC,mBAAmB;IACnB,gFAAgF;IAChF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QAC/B,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;YACb,yBAAyB;YACzB,MAAM,EAAE,4CAA4C;SACpD;KACD,CAAE,CAAC;IAEJ,iBAAiB;IACjB,mFAAmF;IACnF,kDAAkD;IAClD,MAAM,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,GAAG,CAAE,CAAE,KAAK,EAAG,EAAE,CAAC,CAAE;QAC1B,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,iBAAkB,KAAK,CAAC,EAAG,aAAa;KAC9C,CAAE,CAAE,CACL,CAAC;AACH,CAAC;AArBD,0CAqBC"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteAllComments = exports.createComment = void 0;
4
+ /**
5
+ * Create new comment using the REST API.
6
+ *
7
+ * @param this
8
+ * @param payload
9
+ */
10
+ async function createComment(payload) {
11
+ const currentUser = await this.rest({
12
+ path: '/wp/v2/users/me',
13
+ method: 'GET',
14
+ });
15
+ const author = currentUser.id;
16
+ const comment = await this.rest({
17
+ method: 'POST',
18
+ path: '/wp/v2/comments',
19
+ data: { ...payload, author },
20
+ });
21
+ return comment;
22
+ }
23
+ exports.createComment = createComment;
24
+ /**
25
+ * Delete all comments using the REST API.
26
+ *
27
+ * @param this
28
+ */
29
+ async function deleteAllComments() {
30
+ // List all comments.
31
+ // https://developer.wordpress.org/rest-api/reference/comments/#list-comments
32
+ const comments = await this.rest({
33
+ path: '/wp/v2/comments',
34
+ params: {
35
+ per_page: 100,
36
+ // All possible statuses.
37
+ status: 'unapproved,approved,spam,trash',
38
+ },
39
+ });
40
+ // Delete all comments one by one.
41
+ // https://developer.wordpress.org/rest-api/reference/comments/#delete-a-comment
42
+ // "/wp/v2/comments" doesn't support batch requests yet.
43
+ await Promise.all(comments.map((comment) => this.rest({
44
+ method: 'DELETE',
45
+ path: `/wp/v2/comments/${comment.id}`,
46
+ params: {
47
+ force: true,
48
+ },
49
+ })));
50
+ }
51
+ exports.deleteAllComments = deleteAllComments;
52
+ //# sourceMappingURL=comments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/request-utils/comments.ts"],"names":[],"mappings":";;;AAqBA;;;;;GAKG;AACI,KAAK,UAAU,aAAa,CAElC,OAA6B;IAE7B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAU;QAC5C,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,KAAK;KACb,CAAE,CAAC;IAEJ,MAAM,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IAE9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAa;QAC3C,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE;KAC5B,CAAE,CAAC;IAEJ,OAAO,OAAO,CAAC;AAChB,CAAC;AAlBD,sCAkBC;AAED;;;;GAIG;AACI,KAAK,UAAU,iBAAiB;IACtC,qBAAqB;IACrB,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QACjC,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;YACb,yBAAyB;YACzB,MAAM,EAAE,gCAAgC;SACxC;KACD,CAAE,CAAC;IAEJ,kCAAkC;IAClC,gFAAgF;IAChF,wDAAwD;IACxD,MAAM,OAAO,CAAC,GAAG,CAChB,QAAQ,CAAC,GAAG,CAAE,CAAE,OAAgB,EAAG,EAAE,CACpC,IAAI,CAAC,IAAI,CAAE;QACV,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,mBAAoB,OAAO,CAAC,EAAG,EAAE;QACvC,MAAM,EAAE;YACP,KAAK,EAAE,IAAI;SACX;KACD,CAAE,CACH,CACD,CAAC;AACH,CAAC;AA1BD,8CA0BC"}