diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 5af26217..9ea4a806 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -22,6 +22,9 @@ jobs: # The type of runner that the job will run on name: Run Login with google plugin test Cases runs-on: ubuntu-latest + env: + GMAIL_UNAME: ${{ secrets.GMAIL_UNAME }} + GMAIL_PASS: ${{ secrets.GMAIL_PASS }} # Steps represent a sequence of tasks that will be executed as part of the job steps: diff --git a/tests/e2e-playwright/.env b/tests/e2e-playwright/.env deleted file mode 100644 index 78db2dfa..00000000 --- a/tests/e2e-playwright/.env +++ /dev/null @@ -1,2 +0,0 @@ -EMAIL=mylogintest5@gmail.com -PASSWORD=qateam@123 \ No newline at end of file diff --git a/tests/e2e-playwright/.gitignore b/tests/e2e-playwright/.gitignore index a60031a1..1e645859 100644 --- a/tests/e2e-playwright/.gitignore +++ b/tests/e2e-playwright/.gitignore @@ -1,3 +1,2 @@ node_modules artifacts -build \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build-types/config.d.ts b/tests/e2e-playwright/e2e-test-utils-playwright/build-types/config.d.ts index 8a64ee8f..4afd5c39 100644 --- a/tests/e2e-playwright/e2e-test-utils-playwright/build-types/config.d.ts +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build-types/config.d.ts @@ -1,6 +1,6 @@ declare const WP_ADMIN_USER: { - readonly username: "cool-wilson"; - readonly password: "GOEZZtOOwpZsxrhPTz"; + readonly username: "automation"; + readonly password: "automation"; }; declare const WP_USERNAME: string, WP_PASSWORD: string, WP_BASE_URL: string; export { WP_ADMIN_USER, WP_USERNAME, WP_PASSWORD, WP_BASE_URL }; diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js new file mode 100644 index 00000000..89880777 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js @@ -0,0 +1,49 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createNewPost = void 0; +/** + * WordPress dependencies + */ +const url_1 = require("@wordpress/url"); +/** + * Creates new post. + * + * @this {import('.').Editor} + * @param {Object} object Object to create new post, along with tips enabling option. + * @param {string} [object.postType] Post type of the new post. + * @param {string} [object.title] Title of the new post. + * @param {string} [object.content] Content of the new post. + * @param {string} [object.excerpt] Excerpt of the new post. + * @param {boolean} [object.showWelcomeGuide] Whether to show the welcome guide. + */ +async function createNewPost({ postType, title, content, excerpt, showWelcomeGuide = false, } = {}) { + const query = (0, url_1.addQueryArgs)('', { + post_type: postType, + post_title: title, + content, + excerpt, + }).slice(1); + await this.visitAdminPage('post-new.php', query); + await this.page.waitForSelector('.edit-post-layout'); + const isWelcomeGuideActive = await this.page.evaluate(() => window.wp.data + .select('core/edit-post') + .isFeatureActive('welcomeGuide')); + const isFullscreenMode = await this.page.evaluate(() => window.wp.data + .select('core/edit-post') + .isFeatureActive('fullscreenMode')); + if (showWelcomeGuide !== isWelcomeGuideActive) { + await this.page.evaluate(() => window.wp.data + .dispatch('core/edit-post') + .toggleFeature('welcomeGuide')); + await this.page.reload(); + await this.page.waitForSelector('.edit-post-layout'); + } + if (isFullscreenMode) { + await this.page.evaluate(() => window.wp.data + .dispatch('core/edit-post') + .toggleFeature('fullscreenMode')); + await this.page.waitForSelector('body:not(.is-fullscreen-mode)'); + } +} +exports.createNewPost = createNewPost; +//# sourceMappingURL=create-new-post.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js.map new file mode 100644 index 00000000..59e63ffa --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/create-new-post.js.map @@ -0,0 +1 @@ +{"version":3,"file":"create-new-post.js","sourceRoot":"","sources":["../../src/admin/create-new-post.js"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,wCAA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AI,CAAC,IAAI,CAAC,QAAQ,CAAE,GAAG,EAAE,CAC9B,MAAM,CAAC,EAAE,CAAC,IAAI;aACZ,QAAQ,CAAE,gBAAgB,CAAE;aAC5B,aAAa,CAAE,gBAAgB,CAAE,CACnC,CAAC;QAEF,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAE,+BAA+B,CAAE,CAAC;KACnE;AACF,CAAC;AAjDD,sCAiDC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js new file mode 100644 index 00000000..aa88761a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getPageError = void 0; +/** + * Regular expression matching a displayed PHP error within a markup string. + * + * @see https://github.com/php/php-src/blob/598175e/main/main.c#L1257-L1297 + * + * @type {RegExp} + */ +const REGEXP_PHP_ERROR = /()?(Fatal error|Recoverable fatal error|Warning|Parse error|Notice|Strict Standards|Deprecated|Unknown error)(<\/b>)?: (.*?) in (.*?) on line ()?\d+(<\/b>)?/; +/** + * Returns a promise resolving to one of either a string or null. A string will + * be resolved if an error message is present in the contents of the page. If no + * error is present, a null value will be resolved instead. This requires the + * environment be configured to display errors. + * + * @see http://php.net/manual/en/function.error-reporting.php + * + * @param {Admin} this + * + * @return {Promise} Promise resolving to a string or null, depending + * whether a page error is present. + */ +async function getPageError() { + const content = await this.page.content(); + const match = content.match(REGEXP_PHP_ERROR); + return match ? match[0] : null; +} +exports.getPageError = getPageError; +//# sourceMappingURL=get-page-error.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js.map new file mode 100644 index 00000000..458265c9 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/get-page-error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"get-page-error.js","sourceRoot":"","sources":["../../src/admin/get-page-error.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACH,MAAM,gBAAgB,GACrB,oKAAoK,CAAC;AAEtK;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,YAAY;IACjC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAE,gBAAgB,CAAE,CAAC;IAChD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC;AAJD,oCAIC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js new file mode 100644 index 00000000..363e42e9 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js @@ -0,0 +1,31 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Admin = void 0; +/** + * Internal dependencies + */ +/** + * Internal dependencies + */ +const create_new_post_1 = require("./create-new-post"); +const get_page_error_1 = require("./get-page-error"); +const visit_admin_page_1 = require("./visit-admin-page"); +const visit_site_editor_1 = require("./visit-site-editor"); +class Admin { + browser; + page; + pageUtils; + context; + constructor({ page, pageUtils }) { + this.page = page; + this.context = page.context(); + this.browser = this.context.browser(); + this.pageUtils = pageUtils; + } + createNewPost = create_new_post_1.createNewPost.bind(this); + getPageError = get_page_error_1.getPageError.bind(this); + visitAdminPage = visit_admin_page_1.visitAdminPage.bind(this); + visitSiteEditor = visit_site_editor_1.visitSiteEditor.bind(this); +} +exports.Admin = Admin; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js.map new file mode 100644 index 00000000..3fb0e31a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH;;GAEG;AACH,uDAAkD;AAClD,qDAAgD;AAChD,yDAAoD;AACpD,2DAAsD;AAQtD,MAAa,KAAK;IACjB,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,SAAS,CAAY;IACrB,OAAO,CAAiB;IAExB,YAAa,EAAE,IAAI,EAAE,SAAS,EAAyB;QACtD,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;QACvC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,aAAa,GAAG,+BAAa,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC3C,YAAY,GAAG,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACzC,cAAc,GAAG,iCAAc,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC7C,eAAe,GAAG,mCAAe,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CAC/C;AAjBD,sBAiBC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js new file mode 100644 index 00000000..6c06853e --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js @@ -0,0 +1,33 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.visitAdminPage = void 0; +/** + * External dependencies + */ +const path_1 = require("path"); +/** + * Visits admin page and handle errors. + * + * @param {Admin} this + * @param {string} adminPath String to be serialized as pathname. + * @param {string} query String to be serialized as query portion of URL. + */ +async function visitAdminPage(adminPath, query) { + await this.page.goto((0, path_1.join)('wp-admin', adminPath) + (query ? `?${query}` : '')); + // Handle upgrade required screen + if (this.pageUtils.isCurrentURL('wp-admin/upgrade.php')) { + // Click update + await this.page.click('.button.button-large.button-primary'); + // Click continue + await this.page.click('.button.button-large'); + } + if (this.pageUtils.isCurrentURL('wp-login.php')) { + throw new Error('Not logged in'); + } + const error = await this.getPageError(); + if (error) { + throw new Error('Unexpected error in page content: ' + error); + } +} +exports.visitAdminPage = visitAdminPage; +//# sourceMappingURL=visit-admin-page.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js.map new file mode 100644 index 00000000..344cfd04 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-admin-page.js.map @@ -0,0 +1 @@ +{"version":3,"file":"visit-admin-page.js","sourceRoot":"","sources":["../../src/admin/visit-admin-page.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+BAA4B;AAO5B;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAEnC,SAAiB,EACjB,KAAa;IAEb,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnB,IAAA,WAAI,EAAE,UAAU,EAAE,SAAS,CAAE,GAAG,CAAE,KAAK,CAAC,CAAC,CAAC,IAAK,KAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAE,CAC9D,CAAC;IAEF,iCAAiC;IACjC,IAAK,IAAI,CAAC,SAAS,CAAC,YAAY,CAAE,sBAAsB,CAAE,EAAG;QAC5D,eAAe;QACf,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,qCAAqC,CAAE,CAAC;QAC/D,iBAAiB;QACjB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,sBAAsB,CAAE,CAAC;KAChD;IAED,IAAK,IAAI,CAAC,SAAS,CAAC,YAAY,CAAE,cAAc,CAAE,EAAG;QACpD,MAAM,IAAI,KAAK,CAAE,eAAe,CAAE,CAAC;KACnC;IAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IACxC,IAAK,KAAK,EAAG;QACZ,MAAM,IAAI,KAAK,CAAE,oCAAoC,GAAG,KAAK,CAAE,CAAC;KAChE;AACF,CAAC;AAzBD,wCAyBC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js new file mode 100644 index 00000000..b5850226 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.visitSiteEditor = void 0; +/** + * WordPress dependencies + */ +const url_1 = require("@wordpress/url"); +const CANVAS_SELECTOR = 'iframe[title="Editor canvas"i]'; +/** + * Visits the Site Editor main page + * + * By default, it also skips the welcome guide. The option can be disabled if need be. + * + * @param {Admin} this + * @param {SiteEditorQueryParams} query Query params to be serialized as query portion of URL. + * @param {boolean} skipWelcomeGuide Whether to skip the welcome guide as part of the navigation. + */ +async function visitSiteEditor(query, skipWelcomeGuide = true) { + const path = (0, url_1.addQueryArgs)('', { + ...query, + }).slice(1); + await this.visitAdminPage('site-editor.php', path); + await this.page.waitForSelector(CANVAS_SELECTOR); + if (skipWelcomeGuide) { + await this.page.evaluate(() => { + // TODO, type `window.wp`. + // @ts-ignore + window.wp.data + .dispatch('core/preferences') + .set('core/edit-site', 'welcomeGuide', false); + // @ts-ignore + window.wp.data + .dispatch('core/preferences') + .toggle('core/edit-site', 'welcomeGuideStyles', false); + }); + } +} +exports.visitSiteEditor = visitSiteEditor; +//# sourceMappingURL=visit-site-editor.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js.map new file mode 100644 index 00000000..1d719b7d --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/admin/visit-site-editor.js.map @@ -0,0 +1 @@ +{"version":3,"file":"visit-site-editor.js","sourceRoot":"","sources":["../../src/admin/visit-site-editor.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,wCAA8C;AAY9C,MAAM,eAAe,GAAG,gCAAgC,CAAC;AAEzD;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CAEpC,KAA4B,EAC5B,gBAAgB,GAAG,IAAI;IAEvB,MAAM,IAAI,GAAG,IAAA,kBAAY,EAAE,EAAE,EAAE;QAC9B,GAAG,KAAK;KACR,CAAE,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC;IAEf,MAAM,IAAI,CAAC,cAAc,CAAE,iBAAiB,EAAE,IAAI,CAAE,CAAC;IACrD,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAE,eAAe,CAAE,CAAC;IAEnD,IAAK,gBAAgB,EAAG;QACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,GAAG,EAAE;YAC9B,0BAA0B;YAC1B,aAAa;YACb,MAAM,CAAC,EAAE,CAAC,IAAI;iBACZ,QAAQ,CAAE,kBAAkB,CAAE;iBAC9B,GAAG,CAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,CAAE,CAAC;YAEjD,aAAa;YACb,MAAM,CAAC,EAAE,CAAC,IAAI;iBACZ,QAAQ,CAAE,kBAAkB,CAAE;iBAC9B,MAAM,CAAE,gBAAgB,EAAE,oBAAoB,EAAE,KAAK,CAAE,CAAC;QAC3D,CAAC,CAAE,CAAC;KACJ;AACF,CAAC;AA1BD,0CA0BC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js new file mode 100644 index 00000000..d7812d77 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.WP_BASE_URL = exports.WP_PASSWORD = exports.WP_USERNAME = exports.WP_ADMIN_USER = void 0; +const WP_ADMIN_USER = { + username: 'automation', + password: 'automation', +}; +exports.WP_ADMIN_USER = WP_ADMIN_USER; +const { WP_USERNAME = WP_ADMIN_USER.username, WP_PASSWORD = WP_ADMIN_USER.password, WP_BASE_URL = 'http://login-with-google.com', } = process.env; +exports.WP_USERNAME = WP_USERNAME; +exports.WP_PASSWORD = WP_PASSWORD; +exports.WP_BASE_URL = WP_BASE_URL; +//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js.map new file mode 100644 index 00000000..84fe441b --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,MAAM,aAAa,GAAG;IACrB,QAAQ,EAAE,YAAY;IACtB,QAAQ,EAAE,YAAY;CACb,CAAC;AAQF,sCAAa;AANtB,MAAM,EACL,WAAW,GAAG,aAAa,CAAC,QAAQ,EACpC,WAAW,GAAG,aAAa,CAAC,QAAQ,EACpC,WAAW,GAAG,8BAA8B,GAC5C,GAAG,OAAO,CAAC,GAAG,CAAC;AAEQ,kCAAW;AAAE,kCAAW;AAAE,kCAAW"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js new file mode 100644 index 00000000..75e8296e --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.clickBlockOptionsMenuItem = void 0; +/** + * Clicks a block toolbar button. + * + * @param {Editor} this + * @param {string} label The text string of the button label. + */ +async function clickBlockOptionsMenuItem(label) { + await this.clickBlockToolbarButton('Options'); + await this.page + .locator(`role=menu[name="Options"i] >> role=menuitem[name="${label}"i]`) + .click(); +} +exports.clickBlockOptionsMenuItem = clickBlockOptionsMenuItem; +//# sourceMappingURL=click-block-options-menu-item.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js.map new file mode 100644 index 00000000..44963823 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-options-menu-item.js.map @@ -0,0 +1 @@ +{"version":3,"file":"click-block-options-menu-item.js","sourceRoot":"","sources":["../../src/editor/click-block-options-menu-item.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,yBAAyB,CAAgB,KAAa;IAC3E,MAAM,IAAI,CAAC,uBAAuB,CAAE,SAAS,CAAE,CAAC;IAChD,MAAM,IAAI,CAAC,IAAI;SACb,OAAO,CACP,qDAAsD,KAAM,KAAK,CACjE;SACA,KAAK,EAAE,CAAC;AACX,CAAC;AAPD,8DAOC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js new file mode 100644 index 00000000..3ab5ca38 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.clickBlockToolbarButton = void 0; +/** + * Clicks a block toolbar button. + * + * @param {Editor} this + * @param {string} label The text string of the button label. + */ +async function clickBlockToolbarButton(label) { + await this.showBlockToolbar(); + const blockToolbar = this.page.locator('role=toolbar[name="Block tools"i]'); + const button = blockToolbar.locator(`role=button[name="${label}"]`); + await button.click(); +} +exports.clickBlockToolbarButton = clickBlockToolbarButton; +//# sourceMappingURL=click-block-toolbar-button.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js.map new file mode 100644 index 00000000..dd780e4a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/click-block-toolbar-button.js.map @@ -0,0 +1 @@ +{"version":3,"file":"click-block-toolbar-button.js","sourceRoot":"","sources":["../../src/editor/click-block-toolbar-button.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,uBAAuB,CAAgB,KAAa;IACzE,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAE9B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CACrC,mCAAmC,CACnC,CAAC;IACF,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAE,qBAAsB,KAAM,IAAI,CAAE,CAAC;IAExE,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;AACtB,CAAC;AATD,0DASC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js new file mode 100644 index 00000000..ad0db98e --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getEditedPostContent = void 0; +/** + * Returns a promise which resolves with the edited post content (HTML string). + * + * @param {Editor} this + * + * @return {Promise} Promise resolving with post content markup. + */ +async function getEditedPostContent() { + return await this.page.evaluate(() => + // @ts-ignore (Reason: wp isn't typed) + window.wp.data.select('core/editor').getEditedPostContent()); +} +exports.getEditedPostContent = getEditedPostContent; +//# sourceMappingURL=get-edited-post-content.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js.map new file mode 100644 index 00000000..12e85b9a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/get-edited-post-content.js.map @@ -0,0 +1 @@ +{"version":3,"file":"get-edited-post-content.js","sourceRoot":"","sources":["../../src/editor/get-edited-post-content.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB;IACzC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,GAAG,EAAE;IACrC,sCAAsC;IACtC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAE,aAAa,CAAE,CAAC,oBAAoB,EAAE,CAC7D,CAAC;AACH,CAAC;AALD,oDAKC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js new file mode 100644 index 00000000..8a22e594 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js @@ -0,0 +1,55 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Editor = void 0; +/** + * Internal dependencies + */ +const click_block_options_menu_item_1 = require("./click-block-options-menu-item"); +const click_block_toolbar_button_1 = require("./click-block-toolbar-button"); +const get_edited_post_content_1 = require("./get-edited-post-content"); +const insert_block_1 = require("./insert-block"); +const open_document_settings_sidebar_1 = require("./open-document-settings-sidebar"); +const preview_1 = require("./preview"); +const publish_post_1 = require("./publish-post"); +const select_blocks_1 = require("./select-blocks"); +const show_block_toolbar_1 = require("./show-block-toolbar"); +const site_editor_1 = require("./site-editor"); +const transform_block_to_1 = require("./transform-block-to"); +class Editor { + browser; + page; + context; + #hasIframe; + constructor({ page, hasIframe = false }) { + this.page = page; + this.context = page.context(); + this.browser = this.context.browser(); + this.#hasIframe = hasIframe; + } + get canvas() { + let frame; + if (this.#hasIframe) { + frame = this.page.frame('editor-canvas'); + } + else { + frame = this.page; + } + if (!frame) { + throw new Error('EditorUtils: unable to find editor canvas iframe or page'); + } + return frame; + } + clickBlockOptionsMenuItem = click_block_options_menu_item_1.clickBlockOptionsMenuItem.bind(this); + clickBlockToolbarButton = click_block_toolbar_button_1.clickBlockToolbarButton.bind(this); + getEditedPostContent = get_edited_post_content_1.getEditedPostContent.bind(this); + insertBlock = insert_block_1.insertBlock.bind(this); + openDocumentSettingsSidebar = open_document_settings_sidebar_1.openDocumentSettingsSidebar.bind(this); + openPreviewPage = preview_1.openPreviewPage.bind(this); + publishPost = publish_post_1.publishPost.bind(this); + saveSiteEditorEntities = site_editor_1.saveSiteEditorEntities.bind(this); + selectBlocks = select_blocks_1.selectBlocks.bind(this); + showBlockToolbar = show_block_toolbar_1.showBlockToolbar.bind(this); + transformBlockTo = transform_block_to_1.transformBlockTo.bind(this); +} +exports.Editor = Editor; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js.map new file mode 100644 index 00000000..ebda8036 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,mFAA4E;AAC5E,6EAAuE;AACvE,uEAAiE;AACjE,iDAA6C;AAC7C,qFAA+E;AAC/E,uCAA4C;AAC5C,iDAA6C;AAC7C,mDAA+C;AAC/C,6DAAwD;AACxD,+CAAuD;AACvD,6DAAwD;AAOxD,MAAa,MAAM;IAClB,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,OAAO,CAA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AgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACjD,gBAAgB,GAAG,qCAAgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CACjD;AAzCD,wBAyCC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js new file mode 100644 index 00000000..35d6adf3 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.insertBlock = void 0; +/** + * Insert a block. + * + * @param {Editor} this + * @param {BlockRepresentation} blockRepresentation Inserted block representation. + */ +async function insertBlock(blockRepresentation) { + await this.page.evaluate((_blockRepresentation) => { + function recursiveCreateBlock({ name, attributes = {}, innerBlocks = [], }) { + // @ts-ignore (Reason: wp isn't typed). + return window.wp.blocks.createBlock(name, attributes, innerBlocks.map((innerBlock) => recursiveCreateBlock(innerBlock))); + } + const block = recursiveCreateBlock(_blockRepresentation); + // @ts-ignore (Reason: wp isn't typed). + window.wp.data.dispatch('core/block-editor').insertBlock(block); + }, blockRepresentation); +} +exports.insertBlock = insertBlock; +//# sourceMappingURL=insert-block.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js.map new file mode 100644 index 00000000..e88df5a3 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/insert-block.js.map @@ -0,0 +1 @@ +{"version":3,"file":"insert-block.js","sourceRoot":"","sources":["../../src/editor/insert-block.ts"],"names":[],"mappings":";;;AAWA;;;;;GAKG;AACH,KAAK,UAAU,WAAW,CAEzB,mBAAwC;IAExC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,CAAE,oBAAoB,EAAG,EAAE;QACpD,SAAS,oBAAoB,CAAE,EAC9B,IAAI,EACJ,UAAU,GAAG,EAAE,EACf,WAAW,GAAG,EAAE,GACK;YACrB,uCAAuC;YACvC,OAAO,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAClC,IAAI,EACJ,UAAU,EACV,WAAW,CAAC,GAAG,CAAE,CAAE,UAAU,EAAG,EAAE,CACjC,oBAAoB,CAAE,UAAU,CAAE,CAClC,CACD,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,oBAAoB,CAAE,oBAAoB,CAAE,CAAC;QAE3D,uCAAuC;QACvC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAE,mBAAmB,CAAE,CAAC,WAAW,CAAE,KAAK,CAAE,CAAC;IACrE,CAAC,EAAE,mBAAmB,CAAE,CAAC;AAC1B,CAAC;AAGQ,kCAAW"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js new file mode 100644 index 00000000..5b414826 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openDocumentSettingsSidebar = void 0; +const { expect } = require('../test'); +/** + * Clicks on the button in the header which opens Document Settings sidebar when it is closed. + * + * @param {Editor} this + */ +async function openDocumentSettingsSidebar() { + const editorSettings = this.page.locator('role=region[name="Editor settings"i]'); + if (!(await editorSettings.isVisible())) { + await this.page.click('role=region[name="Editor top bar"i] >> role=button[name="Settings"i]'); + await expect(editorSettings).toBeVisible(); + } +} +exports.openDocumentSettingsSidebar = openDocumentSettingsSidebar; +//# sourceMappingURL=open-document-settings-sidebar.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js.map new file mode 100644 index 00000000..6931f3b1 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/open-document-settings-sidebar.js.map @@ -0,0 +1 @@ +{"version":3,"file":"open-document-settings-sidebar.js","sourceRoot":"","sources":["../../src/editor/open-document-settings-sidebar.ts"],"names":[],"mappings":";;;AAIA,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAE,SAAS,CAAE,CAAC;AAExC;;;;GAIG;AACI,KAAK,UAAU,2BAA2B;IAChD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CACvC,sCAAsC,CACtC,CAAC;IAEF,IAAK,CAAE,CAAE,MAAM,cAAc,CAAC,SAAS,EAAE,CAAE,EAAG;QAC7C,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,sEAAsE,CACtE,CAAC;QAEF,MAAM,MAAM,CAAE,cAAc,CAAE,CAAC,WAAW,EAAE,CAAC;KAC7C;AACF,CAAC;AAZD,kEAYC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js new file mode 100644 index 00000000..67ad6da9 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.openPreviewPage = void 0; +/** + * Opens the preview page of an edited post. + * + * @param {Editor} this + * + * @return {Promise} preview page. + */ +async function openPreviewPage() { + const editorTopBar = this.page.locator('role=region[name="Editor top bar"i]'); + const previewButton = editorTopBar.locator('role=button[name="Preview"i]'); + await previewButton.click(); + const [previewPage] = await Promise.all([ + this.context.waitForEvent('page'), + this.page.click('role=menuitem[name="Preview in new tab"i]'), + ]); + return previewPage; +} +exports.openPreviewPage = openPreviewPage; +//# sourceMappingURL=preview.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js.map new file mode 100644 index 00000000..11f42ac1 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/preview.js.map @@ -0,0 +1 @@ +{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/editor/preview.ts"],"names":[],"mappings":";;;AAUA;;;;;;GAMG;AACI,KAAK,UAAU,eAAe;IACpC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CACrC,qCAAqC,CACrC,CAAC;IACF,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CACzC,8BAA8B,CAC9B,CAAC;IACF,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC;IAE5B,MAAM,CAAE,WAAW,CAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAE;QAC1C,IAAI,CAAC,OAAO,CAAC,YAAY,CAAE,MAAM,CAAE;QACnC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,2CAA2C,CAAE;KAC9D,CAAE,CAAC;IAEJ,OAAO,WAAW,CAAC;AACpB,CAAC;AAfD,0CAeC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js new file mode 100644 index 00000000..21b325c6 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.publishPost = void 0; +/** + * Publishes the post, resolving once the request is complete (once a notice + * is displayed). + * + * @param {Editor} this + */ +async function publishPost() { + await this.page.click('role=button[name="Publish"i]'); + const publishEditorPanel = this.page.locator('role=region[name="Publish editor"i]'); + const isPublishEditorVisible = await publishEditorPanel.isVisible(); + // Save any entities. + if (isPublishEditorVisible) { + // Handle saving entities. + await this.page.click('role=region[name="Editor publish"i] >> role=button[name="Save"i]'); + } + // Handle saving just the post. + await this.page.click('role=region[name="Editor publish"i] >> role=button[name="Publish"i]'); + const urlString = await this.page.inputValue('role=textbox[name="Post address"i]'); + const url = new URL(urlString); + const postId = url.searchParams.get('p'); + return typeof postId === 'string' ? parseInt(postId, 10) : null; +} +exports.publishPost = publishPost; +//# sourceMappingURL=publish-post.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js.map new file mode 100644 index 00000000..0c2fbeda --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/publish-post.js.map @@ -0,0 +1 @@ +{"version":3,"file":"publish-post.js","sourceRoot":"","sources":["../../src/editor/publish-post.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,UAAU,WAAW;IAChC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,8BAA8B,CAAE,CAAC;IACxD,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAC3C,qCAAqC,CACrC,CAAC;IAEF,MAAM,sBAAsB,GAAG,MAAM,kBAAkB,CAAC,SAAS,EAAE,CAAC;IAEpE,qBAAqB;IACrB,IAAK,sBAAsB,EAAG;QAC7B,0BAA0B;QAC1B,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,kEAAkE,CAClE,CAAC;KACF;IAED,+BAA+B;IAC/B,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpB,qEAAqE,CACrE,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAC3C,oCAAoC,CACpC,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAE,SAAS,CAAE,CAAC;IACjC,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAE,GAAG,CAAE,CAAC;IAE3C,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAE,MAAM,EAAE,EAAE,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACnE,CAAC;AA5BD,kCA4BC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js new file mode 100644 index 00000000..622e0f64 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.selectBlocks = void 0; +async function selectBlocks(startSelectorOrLocator, endSelectorOrLocator) { + const startBlock = typeof startSelectorOrLocator === 'string' + ? this.canvas.locator(startSelectorOrLocator) + : startSelectorOrLocator; + const endBlock = typeof endSelectorOrLocator === 'string' + ? this.canvas.locator(endSelectorOrLocator) + : endSelectorOrLocator; + const startClientId = await startBlock.getAttribute('data-block'); + const endClientId = await endBlock?.getAttribute('data-block'); + if (endClientId) { + await this.page.evaluate(([startId, endId]) => { + // @ts-ignore + wp.data + .dispatch('core/block-editor') + .multiSelect(startId, endId); + }, [startClientId, endClientId]); + } + else { + await this.page.evaluate(([clientId]) => { + // @ts-ignore + wp.data.dispatch('core/block-editor').selectBlock(clientId); + }, [startClientId]); + } +} +exports.selectBlocks = selectBlocks; +//# sourceMappingURL=select-blocks.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js.map new file mode 100644 index 00000000..c147c1e8 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/select-blocks.js.map @@ -0,0 +1 @@ +{"version":3,"file":"select-blocks.js","sourceRoot":"","sources":["../../src/editor/select-blocks.ts"],"names":[],"mappings":";;;AAUO,KAAK,UAAU,YAAY,CAEjC,sBAAwC,EACxC,oBAAuC;IAEvC,MAAM,UAAU,GACf,OAAO,sBAAsB,KAAK,QAAQ;QACzC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAE,sBAAsB,CAAE;QAC/C,CAAC,CAAC,sBAAsB,CAAC;IAE3B,MAAM,QAAQ,GACb,OAAO,oBAAoB,KAAK,QAAQ;QACvC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAE,oBAAoB,CAAE;QAC7C,CAAC,CAAC,oBAAoB,CAAC;IAEzB,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,YAAY,CAAE,YAAY,CAAE,CAAC;IACpE,MAAM,WAAW,GAAG,MAAM,QAAQ,EAAE,YAAY,CAAE,YAAY,CAAE,CAAC;IAEjE,IAAK,WAAW,EAAG;QAClB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CACvB,CAAE,CAAE,OAAO,EAAE,KAAK,CAAE,EAAG,EAAE;YACxB,aAAa;YACb,EAAE,CAAC,IAAI;iBACL,QAAQ,CAAE,mBAAmB,CAAE;iBAC/B,WAAW,CAAE,OAAO,EAAE,KAAK,CAAE,CAAC;QACjC,CAAC,EACD,CAAE,aAAa,EAAE,WAAW,CAAE,CAC9B,CAAC;KACF;SAAM;QACN,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CACvB,CAAE,CAAE,QAAQ,CAAE,EAAG,EAAE;YAClB,aAAa;YACb,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAE,mBAAmB,CAAE,CAAC,WAAW,CAAE,QAAQ,CAAE,CAAC;QACjE,CAAC,EACD,CAAE,aAAa,CAAE,CACjB,CAAC;KACF;AACF,CAAC;AArCD,oCAqCC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js new file mode 100644 index 00000000..43253260 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.showBlockToolbar = void 0; +/** + * The block toolbar is not always visible while typing. + * Call this function to reveal it. + * + * @param {Editor} this + */ +async function showBlockToolbar() { + // Move the mouse to disable the isTyping mode. We need at least three + // mousemove events for it to work across windows (iframe). With three + // moves, it's a guarantee that at least two will be in the same window. + // Two events are required for the flag to be unset. + await this.page.mouse.move(50, 50); + await this.page.mouse.move(75, 75); + await this.page.mouse.move(100, 100); +} +exports.showBlockToolbar = showBlockToolbar; +//# sourceMappingURL=show-block-toolbar.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js.map new file mode 100644 index 00000000..9246db27 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/show-block-toolbar.js.map @@ -0,0 +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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js new file mode 100644 index 00000000..defbfd20 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.saveSiteEditorEntities = void 0; +/** + * Save entities in the site editor. Assumes the editor is in a dirty state. + * + * @param {Editor} this + */ +async function saveSiteEditorEntities() { + await this.page.click('role=region[name="Editor top bar"i] >> role=button[name="Save"i]'); + // Second Save button in the entities panel. + await this.page.click('role=region[name="Editor publish"i] >> role=button[name="Save"i]'); + await this.page.waitForSelector('role=region[name="Editor top bar"i] >> role=button[name="Save"i][disabled]'); +} +exports.saveSiteEditorEntities = saveSiteEditorEntities; +//# sourceMappingURL=site-editor.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js.map new file mode 100644 index 00000000..bfdcc1dd --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/site-editor.js.map @@ -0,0 +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,kEAAkE,CAClE,CAAC;IACF,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAC9B,4EAA4E,CAC5E,CAAC;AACH,CAAC;AAXD,wDAWC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js new file mode 100644 index 00000000..61669ba0 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.transformBlockTo = void 0; +/** + * Clicks the default block appender. + * + * @param {Editor} this + * @param {string} name Block name. + */ +async function transformBlockTo(name) { + await this.page.evaluate(([blockName]) => { + // @ts-ignore (Reason: wp isn't typed) + const clientIds = window.wp.data + .select('core/block-editor') + .getSelectedBlockClientIds(); + // @ts-ignore (Reason: wp isn't typed) + const blocks = window.wp.data + .select('core/block-editor') + .getBlocksByClientId(clientIds); + // @ts-ignore (Reason: wp isn't typed) + window.wp.data.dispatch('core/block-editor').replaceBlocks(clientIds, + // @ts-ignore (Reason: wp isn't typed) + window.wp.blocks.switchToBlockType(blocks, blockName)); + }, [name]); +} +exports.transformBlockTo = transformBlockTo; +//# sourceMappingURL=transform-block-to.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js.map new file mode 100644 index 00000000..78cc6ebf --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/editor/transform-block-to.js.map @@ -0,0 +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,sCAAsC;QACtC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI;aAC9B,MAAM,CAAE,mBAAmB,CAAE;aAC7B,yBAAyB,EAAE,CAAC;QAC9B,sCAAsC;QACtC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI;aAC3B,MAAM,CAAE,mBAAmB,CAAE;aAC7B,mBAAmB,CAAE,SAAS,CAAE,CAAC;QACnC,sCAAsC;QACtC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAE,mBAAmB,CAAE,CAAC,aAAa,CAC3D,SAAS;QACT,sCAAsC;QACtC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAE,MAAM,EAAE,SAAS,CAAE,CACvD,CAAC;IACH,CAAC,EACD,CAAE,IAAI,CAAE,CACR,CAAC;AACH,CAAC;AApBD,4CAoBC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js new file mode 100644 index 00000000..d21487ba --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.expect = exports.test = exports.RequestUtils = exports.PageUtils = exports.Editor = exports.Admin = void 0; +var admin_1 = require("./admin"); +Object.defineProperty(exports, "Admin", { enumerable: true, get: function () { return admin_1.Admin; } }); +var editor_1 = require("./editor"); +Object.defineProperty(exports, "Editor", { enumerable: true, get: function () { return editor_1.Editor; } }); +var page_utils_1 = require("./page-utils"); +Object.defineProperty(exports, "PageUtils", { enumerable: true, get: function () { return page_utils_1.PageUtils; } }); +var request_utils_1 = require("./request-utils"); +Object.defineProperty(exports, "RequestUtils", { enumerable: true, get: function () { return request_utils_1.RequestUtils; } }); +var test_1 = require("./test"); +Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_1.test; } }); +Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } }); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js.map new file mode 100644 index 00000000..41b06397 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js new file mode 100644 index 00000000..1ed858fa --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PageUtils = void 0; +/** + * Internal dependencies + */ +const is_current_url_1 = require("./is-current-url"); +const press_key_with_modifier_1 = require("./press-key-with-modifier"); +const press_key_times_1 = require("./press-key-times"); +const set_browser_viewport_1 = require("./set-browser-viewport"); +class PageUtils { + browser; + page; + context; + constructor({ page }) { + this.page = page; + this.context = page.context(); + this.browser = this.context.browser(); + } + isCurrentURL = is_current_url_1.isCurrentURL.bind(this); + pressKeyTimes = press_key_times_1.pressKeyTimes.bind(this); + pressKeyWithModifier = press_key_with_modifier_1.pressKeyWithModifier.bind(this); + setBrowserViewport = set_browser_viewport_1.setBrowserViewport.bind(this); + setClipboardData = press_key_with_modifier_1.setClipboardData.bind(this); +} +exports.PageUtils = PageUtils; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js.map new file mode 100644 index 00000000..8de1ba91 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page-utils/index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,qDAAgD;AAChD,uEAGmC;AACnC,uDAAkD;AAClD,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,YAAY,GAAG,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACzC,aAAa,GAAG,+BAAa,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC3C,oBAAoB,GAAG,8CAAoB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACzD,kBAAkB,GAAG,yCAAkB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,gBAAgB,GAAG,0CAAgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CACjD;AAEQ,8BAAS"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js new file mode 100644 index 00000000..d9aa0abf --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isCurrentURL = void 0; +/** + * Internal dependencies + */ +const config_1 = require("../config"); +/** + * Checks if current path of the URL matches the provided path. + * + * @param {PageUtils} this + * @param {string} path String to be serialized as pathname. + * + * @return {boolean} Boolean represents whether current URL is or not a WordPress path. + */ +function isCurrentURL(path) { + const currentURL = new URL(this.page.url()); + const expectedURL = new URL(path, config_1.WP_BASE_URL); + return expectedURL.pathname === currentURL.pathname; +} +exports.isCurrentURL = isCurrentURL; +//# sourceMappingURL=is-current-url.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js.map new file mode 100644 index 00000000..5173611d --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/is-current-url.js.map @@ -0,0 +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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js new file mode 100644 index 00000000..8a5f0d94 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.pressKeyTimes = void 0; +/** + * Presses the given keyboard key a number of times in sequence. + * + * @param {string} key Key to press. + * @param {number} count Number of times to press. + */ +async function pressKeyTimes(key, count) { + while (count--) { + await this.page.keyboard.press(key); + } +} +exports.pressKeyTimes = pressKeyTimes; +//# sourceMappingURL=press-key-times.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js.map new file mode 100644 index 00000000..55e46d04 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-times.js.map @@ -0,0 +1 @@ +{"version":3,"file":"press-key-times.js","sourceRoot":"","sources":["../../src/page-utils/press-key-times.js"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,KAAK,UAAU,aAAa,CAAE,GAAG,EAAE,KAAK;IAC9C,OAAQ,KAAK,EAAE,EAAG;QACjB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAE,GAAG,CAAE,CAAC;KACtC;AACF,CAAC;AAJD,sCAIC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js new file mode 100644 index 00000000..41fef0bf --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js @@ -0,0 +1,91 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.pressKeyWithModifier = exports.setClipboardData = void 0; +/** + * External dependencies + */ +const lodash_1 = require("lodash"); +/** + * WordPress dependencies + */ +const keycodes_1 = require("@wordpress/keycodes"); +let clipboardDataHolder = { + plainText: '', + html: '', +}; +/** + * Sets the clipboard data that can be pasted with + * `pressKeyWithModifier( 'primary', 'v' )`. + * + * @param this + * @param clipboardData + * @param clipboardData.plainText + * @param clipboardData.html + */ +function setClipboardData({ plainText = '', html = '' }) { + clipboardDataHolder = { + plainText, + html, + }; +} +exports.setClipboardData = setClipboardData; +async function emulateClipboard(page, type) { + clipboardDataHolder = await page.evaluate(([_type, _clipboardData]) => { + const clipboardDataTransfer = new DataTransfer(); + if (_type === 'paste') { + clipboardDataTransfer.setData('text/plain', _clipboardData.plainText); + clipboardDataTransfer.setData('text/html', _clipboardData.html); + } + else { + const selection = window.getSelection(); + const plainText = selection.toString(); + let html = plainText; + if (selection.rangeCount) { + const range = selection.getRangeAt(0); + const fragment = range.cloneContents(); + html = Array.from(fragment.childNodes) + .map((node) => node.outerHTML ?? node.nodeValue) + .join(''); + } + clipboardDataTransfer.setData('text/plain', plainText); + clipboardDataTransfer.setData('text/html', html); + } + document.activeElement?.dispatchEvent(new ClipboardEvent(_type, { + bubbles: true, + cancelable: true, + clipboardData: clipboardDataTransfer, + })); + return { + plainText: clipboardDataTransfer.getData('text/plain'), + html: clipboardDataTransfer.getData('text/html'), + }; + }, [type, clipboardDataHolder]); +} +/** + * Performs a key press with modifier (Shift, Control, Meta, Alt), where each modifier + * is normalized to platform-specific modifier. + * + * @param this + * @param modifier + * @param key + */ +async function pressKeyWithModifier(modifier, key) { + if (modifier.toLowerCase() === 'primary' && key.toLowerCase() === 'c') { + return await emulateClipboard(this.page, 'copy'); + } + if (modifier.toLowerCase() === 'primary' && key.toLowerCase() === 'x') { + return await emulateClipboard(this.page, 'cut'); + } + if (modifier.toLowerCase() === 'primary' && key.toLowerCase() === 'v') { + return await emulateClipboard(this.page, 'paste'); + } + const isAppleOS = () => process.platform === 'darwin'; + const overWrittenModifiers = { + ...keycodes_1.modifiers, + shiftAlt: (_isApple) => _isApple() ? [keycodes_1.SHIFT, keycodes_1.ALT] : [keycodes_1.SHIFT, keycodes_1.CTRL], + }; + const mappedModifiers = overWrittenModifiers[modifier](isAppleOS).map((keycode) => (keycode === keycodes_1.CTRL ? 'Control' : (0, lodash_1.capitalize)(keycode))); + await this.page.keyboard.press(`${mappedModifiers.join('+')}+${key}`); +} +exports.pressKeyWithModifier = pressKeyWithModifier; +//# sourceMappingURL=press-key-with-modifier.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js.map new file mode 100644 index 00000000..35e1a361 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/press-key-with-modifier.js.map @@ -0,0 +1 @@ +{"version":3,"file":"press-key-with-modifier.js","sourceRoot":"","sources":["../../src/page-utils/press-key-with-modifier.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mCAAoC;AAGpC;;GAEG;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AG,EAAE,CACvC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAE,gBAAK,EAAE,cAAG,CAAE,CAAC,CAAC,CAAC,CAAE,gBAAK,EAAE,eAAI,CAAE;KAC9C,CAAC;IACF,MAAM,eAAe,GAAG,oBAAoB,CAAE,QAAQ,CAAE,CAAE,SAAS,CAAE,CAAC,GAAG,CACxE,CAAE,OAAO,EAAG,EAAE,CAAC,CAAE,OAAO,KAAK,eAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,mBAAU,EAAE,OAAO,CAAE,CAAE,CACvE,CAAC;IAEF,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAC7B,GAAI,eAAe,CAAC,IAAI,CAAE,GAAG,CAAG,IAAK,GAAI,EAAE,CAC3C,CAAC;AACH,CAAC;AA9BD,oDA8BC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js new file mode 100644 index 00000000..0e7e00c9 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js @@ -0,0 +1,47 @@ +"use strict"; +/** + * Named viewport options. + * + * @typedef {"large"|"medium"|"small"} WPDimensionsName + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.setBrowserViewport = void 0; +/** + * Viewport dimensions object. + * + * @typedef {Object} WPViewportDimensions + * + * @property {number} width Width, in pixels. + * @property {number} height Height, in pixels. + */ +/** + * Predefined viewport dimensions to reference by name. + * + * @enum {WPViewportDimensions} + * + * @type {Record} + */ +const PREDEFINED_DIMENSIONS = { + large: { width: 960, height: 700 }, + medium: { width: 768, height: 700 }, + small: { width: 600, height: 700 }, +}; +/** + * Valid argument argument type from which to derive viewport dimensions. + * + * @typedef {WPDimensionsName|WPViewportDimensions} WPViewport + */ +/** + * Sets browser viewport to specified type. + * + * @this {import('./').PageUtils} + * @param {WPViewport} viewport Viewport name or dimensions object to assign. + */ +async function setBrowserViewport(viewport) { + const dimensions = typeof viewport === 'string' + ? PREDEFINED_DIMENSIONS[viewport] + : viewport; + await this.page.setViewportSize(dimensions); +} +exports.setBrowserViewport = setBrowserViewport; +//# sourceMappingURL=set-browser-viewport.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js.map new file mode 100644 index 00000000..74acf606 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/page-utils/set-browser-viewport.js.map @@ -0,0 +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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js new file mode 100644 index 00000000..f7f4b992 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAllBlocks = void 0; +/** + * Delete all blocks using REST API. + * + * @see https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks + * @this {import('./index').RequestUtils} + */ +async function deleteAllBlocks() { + // List all blocks. + // https://developer.wordpress.org/rest-api/reference/blocks/#list-editor-blocks + const blocks = await this.rest({ + path: '/wp/v2/blocks', + params: { + per_page: 100, + // All possible statuses. + status: 'publish,future,draft,pending,private,trash', + }, + }); + // Delete blocks. + // https://developer.wordpress.org/rest-api/reference/blocks/#delete-a-editor-block + // "/wp/v2/posts" not yet supports batch requests. + await this.batchRest(blocks.map((block) => ({ + method: 'DELETE', + path: `/wp/v2/blocks/${block.id}?force=true`, + }))); +} +exports.deleteAllBlocks = deleteAllBlocks; +//# sourceMappingURL=blocks.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js.map new file mode 100644 index 00000000..01ca4f61 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/blocks.js.map @@ -0,0 +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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js new file mode 100644 index 00000000..d12166d2 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js @@ -0,0 +1,52 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAllComments = exports.createComment = void 0; +/** + * Create new comment using the REST API. + * + * @param {} this RequestUtils. + * @param {} payload CreateCommentPayload. + */ +async function createComment(payload) { + const currentUser = await this.rest({ + path: '/wp/v2/users/me', + method: 'GET', + }); + const author = currentUser.id; + const comment = await this.rest({ + method: 'POST', + path: '/wp/v2/comments', + data: { ...payload, author }, + }); + return comment; +} +exports.createComment = createComment; +/** + * Delete all comments using the REST API. + * + * @param {} this RequestUtils. + */ +async function deleteAllComments() { + // List all comments. + // https://developer.wordpress.org/rest-api/reference/comments/#list-comments + const comments = await this.rest({ + path: '/wp/v2/comments', + params: { + per_page: 100, + // All possible statuses. + status: 'unapproved,approved,spam,trash', + }, + }); + // Delete all comments one by one. + // https://developer.wordpress.org/rest-api/reference/comments/#delete-a-comment + // "/wp/v2/comments" doesn't support batch requests yet. + await Promise.all(comments.map((comment) => this.rest({ + method: 'DELETE', + path: `/wp/v2/comments/${comment.id}`, + params: { + force: true, + }, + }))); +} +exports.deleteAllComments = deleteAllComments; +//# sourceMappingURL=comments.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js.map new file mode 100644 index 00000000..bfdcbacf --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/comments.js.map @@ -0,0 +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"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js new file mode 100644 index 00000000..169f1016 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js @@ -0,0 +1,99 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RequestUtils = void 0; +/** + * External dependencies + */ +const fs = require("fs/promises"); +const path = require("path"); +const test_1 = require("@playwright/test"); +/** + * Internal dependencies + */ +const config_1 = require("../config"); +const login_1 = require("./login"); +const media_1 = require("./media"); +const rest_1 = require("./rest"); +const plugins_1 = require("./plugins"); +const templates_1 = require("./templates"); +const themes_1 = require("./themes"); +const blocks_1 = require("./blocks"); +const comments_1 = require("./comments"); +const posts_1 = require("./posts"); +const preferences_1 = require("./preferences"); +const widgets_1 = require("./widgets"); +class RequestUtils { + request; + user; + maxBatchSize; + storageState; + storageStatePath; + baseURL; + pluginsMap = null; + static async setup({ user, storageStatePath, baseURL = config_1.WP_BASE_URL, }) { + let storageState; + if (storageStatePath) { + await fs.mkdir(path.dirname(storageStatePath), { + recursive: true, + }); + try { + storageState = JSON.parse(await fs.readFile(storageStatePath, 'utf-8')); + } + catch (error) { + if (error instanceof Error && + error.code === 'ENOENT') { + // Ignore errors if the state is not found. + } + else { + throw error; + } + } + } + const requestContext = await test_1.request.newContext({ + baseURL, + storageState: storageState && { + cookies: storageState.cookies, + origins: [], + }, + }); + const requestUtils = new RequestUtils(requestContext, { + user, + storageState, + storageStatePath, + baseURL, + }); + return requestUtils; + } + constructor(requestContext, { user = config_1.WP_ADMIN_USER, storageState, storageStatePath, baseURL = config_1.WP_BASE_URL, } = {}) { + this.user = user; + this.request = requestContext; + this.storageStatePath = storageStatePath; + this.storageState = storageState; + this.baseURL = baseURL; + } + login = login_1.login.bind(this); + setupRest = rest_1.setupRest.bind(this); + // .bind() drops the generic types. Re-casting it to keep the type signature. + rest = rest_1.rest.bind(this); + getMaxBatchSize = rest_1.getMaxBatchSize.bind(this); + // .bind() drops the generic types. Re-casting it to keep the type signature. + batchRest = rest_1.batchRest.bind(this); + getPluginsMap = plugins_1.getPluginsMap.bind(this); + activatePlugin = plugins_1.activatePlugin.bind(this); + deactivatePlugin = plugins_1.deactivatePlugin.bind(this); + activateTheme = themes_1.activateTheme.bind(this); + deleteAllBlocks = blocks_1.deleteAllBlocks; + deleteAllPosts = posts_1.deleteAllPosts.bind(this); + createComment = comments_1.createComment.bind(this); + deleteAllComments = comments_1.deleteAllComments.bind(this); + deleteAllWidgets = widgets_1.deleteAllWidgets.bind(this); + addWidgetBlock = widgets_1.addWidgetBlock.bind(this); + deleteAllTemplates = templates_1.deleteAllTemplates.bind(this); + resetPreferences = preferences_1.resetPreferences.bind(this); + listMedia = media_1.listMedia.bind(this); + uploadMedia = media_1.uploadMedia.bind(this); + deleteMedia = media_1.deleteMedia.bind(this); + deleteAllMedia = media_1.deleteAllMedia.bind(this); +} +exports.RequestUtils = RequestUtils; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js.map new file mode 100644 index 00000000..21b7a561 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-utils/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,kCAAkC;AAClC,6BAA6B;AAC7B,2CAA2C;AAG3C;;GAEG;AACH,sCAAuD;AAEvD,mCAAgC;AAChC,mCAA8E;AAC9E,iCAAqE;AACrE,uCAA4E;AAC5E,2CAAiD;AACjD,qCAAyC;AACzC,qCAA2C;AAC3C,yCAA8D;AAC9D,mCAAyC;AACzC,+CAAiD;AACjD,uCAA6D;AAQ7D,MAAM,YAAY;IACjB,OAAO,CAAoB;IAC3B,IAAI,CAAO;IACX,YAAY,CAAU;IACtB,YAAY,CAAgB;IAC5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nC,WAAW,GAAG,mBAAW,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACvC,WAAW,GAAG,mBAAW,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACvC,cAAc,GAAG,sBAAc,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CAC7C;AAGQ,oCAAY"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js new file mode 100644 index 00000000..115a0251 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.login = void 0; +async function login(user = this.user) { + // Login to admin using request context. + let response = await this.request.post('wp-login.php', { + failOnStatusCode: true, + form: { + log: user.username, + pwd: user.password, + }, + }); + await response.dispose(); + // Get the nonce. + response = await this.request.get('wp-admin/admin-ajax.php?action=rest-nonce', { + failOnStatusCode: true, + }); + const nonce = await response.text(); + return nonce; +} +exports.login = login; +//# sourceMappingURL=login.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js.map new file mode 100644 index 00000000..3b979267 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/login.js.map @@ -0,0 +1 @@ +{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/request-utils/login.ts"],"names":[],"mappings":";;;AAUA,KAAK,UAAU,KAAK,CAAsB,OAAa,IAAI,CAAC,IAAI;IAC/D,wCAAwC;IACxC,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAE,cAAc,EAAE;QACvD,gBAAgB,EAAE,IAAI;QACtB,IAAI,EAAE;YACL,GAAG,EAAE,IAAI,CAAC,QAAQ;YAClB,GAAG,EAAE,IAAI,CAAC,QAAQ;SAClB;KACD,CAAE,CAAC;IACJ,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IAEzB,iBAAiB;IACjB,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAChC,2CAA2C,EAC3C;QACC,gBAAgB,EAAE,IAAI;KACtB,CACD,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEpC,OAAO,KAAK,CAAC;AACd,CAAC;AAEQ,sBAAK"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js new file mode 100644 index 00000000..5d0256b5 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js @@ -0,0 +1,74 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAllMedia = exports.deleteMedia = exports.uploadMedia = exports.listMedia = void 0; +/** + * External dependencies + */ +const fs = require("fs"); +/** + * List all media files. + * + * @see https://developer.wordpress.org/rest-api/reference/media/#list-media + * @param this + */ +async function listMedia() { + const response = await this.rest({ + method: 'GET', + path: '/wp/v2/media', + params: { + per_page: 100, + }, + }); + return response; +} +exports.listMedia = listMedia; +/** + * Upload a media file. + * + * @see https://developer.wordpress.org/rest-api/reference/media/#create-a-media-item + * @param this + * @param filePathOrData The path or data of the file being uploaded. + */ +async function uploadMedia(filePathOrData) { + const file = typeof filePathOrData === 'string' + ? fs.createReadStream(filePathOrData) + : filePathOrData; + const response = await this.rest({ + method: 'POST', + path: '/wp/v2/media', + multipart: { + file, + }, + }); + return response; +} +exports.uploadMedia = uploadMedia; +/** + * delete a media file. + * + * @see https://developer.wordpress.org/rest-api/reference/media/#delete-a-media-item + * @param this + * @param mediaId The ID of the media file. + */ +async function deleteMedia(mediaId) { + const response = await this.rest({ + method: 'DELETE', + path: `/wp/v2/media/${mediaId}`, + params: { force: true }, + }); + return response; +} +exports.deleteMedia = deleteMedia; +/** + * delete all media files. + * + * @param this + */ +async function deleteAllMedia() { + const files = await this.listMedia(); + // The media endpoint doesn't support batch request yet. + const responses = await Promise.all(files.map((media) => this.deleteMedia(media.id))); + return responses; +} +exports.deleteAllMedia = deleteAllMedia; +//# sourceMappingURL=media.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js.map new file mode 100644 index 00000000..f7d64e7b --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/media.js.map @@ -0,0 +1 @@ +{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/request-utils/media.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yBAAyB;AAoBzB;;;;;GAKG;AACH,KAAK,UAAU,SAAS;IACvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAa;QAC5C,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;SACb;KACD,CAAE,CAAC;IAEJ,OAAO,QAAQ,CAAC;AACjB,CAAC;AA8DQ,8BAAS;AA5DlB;;;;;;GAMG;AACH,KAAK,UAAU,WAAW,CAEzB,cAAsC;IAEtC,MAAM,IAAI,GACT,OAAO,cAAc,KAAK,QAAQ;QACjC,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAE,cAAc,CAAE;QACvC,CAAC,CAAC,cAAc,CAAC;IAEnB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAW;QAC1C,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,cAAc;QACpB,SAAS,EAAE;YACV,IAAI;SACJ;KACD,CAAE,CAAC;IAEJ,OAAO,QAAQ,CAAC;AACjB,CAAC;AAmCmB,kCAAW;AAjC/B;;;;;;GAMG;AACH,KAAK,UAAU,WAAW,CAAsB,OAAe;IAC9D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QACjC,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,gBAAiB,OAAQ,EAAE;QACjC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;KACvB,CAAE,CAAC;IAEJ,OAAO,QAAQ,CAAC;AACjB,CAAC;AAkBgC,kCAAW;AAhB5C;;;;GAIG;AACH,KAAK,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;IAErC,wDAAwD;IACxD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,KAAK,CAAC,GAAG,CAAE,CAAE,KAAK,EAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAE,KAAK,CAAC,EAAE,CAAE,CAAE,CACtD,CAAC;IAEF,OAAO,SAAS,CAAC;AAClB,CAAC;AAE6C,wCAAc"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js new file mode 100644 index 00000000..5684d0bf --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js @@ -0,0 +1,69 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deactivatePlugin = exports.activatePlugin = exports.getPluginsMap = void 0; +/** + * External dependencies + */ +const lodash_1 = require("lodash"); +/** + * Fetch the plugins from API and cache them in memory, + * since they are unlikely to change during testing. + * + * @param {} this RequestUtils. + * @param {} [forceRefetch] Force refetch the installed plugins to update the cache. + */ +async function getPluginsMap(forceRefetch = false) { + if (!forceRefetch && this.pluginsMap) { + return this.pluginsMap; + } + const plugins = await this.rest({ + path: '/wp/v2/plugins', + }); + this.pluginsMap = {}; + for (const plugin of plugins) { + // Ideally, we should be using sanitize_title() in PHP rather than kebabCase(), + // but we don't have the exact port of it in JS. + this.pluginsMap[(0, lodash_1.kebabCase)(plugin.name)] = plugin.plugin; + } + return this.pluginsMap; +} +exports.getPluginsMap = getPluginsMap; +/** + * Activates an installed plugin. + * + * @param {this} this RequestUtils. + * @param {string} slug Plugin slug. + */ +async function activatePlugin(slug) { + const pluginsMap = await this.getPluginsMap(); + const plugin = pluginsMap[slug]; + if (!plugin) { + throw new Error(`The plugin "${slug}" isn't installed`); + } + await this.rest({ + method: 'PUT', + path: `/wp/v2/plugins/${plugin}`, + data: { status: 'active' }, + }); +} +exports.activatePlugin = activatePlugin; +/** + * Deactivates an active plugin. + * + * @param {this} this RequestUtils. + * @param {string} slug Plugin slug. + */ +async function deactivatePlugin(slug) { + const pluginsMap = await this.getPluginsMap(); + const plugin = pluginsMap[slug]; + if (!plugin) { + throw new Error(`The plugin "${slug}" isn't installed`); + } + await this.rest({ + method: 'PUT', + path: `/wp/v2/plugins/${plugin}`, + data: { status: 'inactive' }, + }); +} +exports.deactivatePlugin = deactivatePlugin; +//# sourceMappingURL=plugins.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js.map new file mode 100644 index 00000000..6c37e373 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/plugins.js.map @@ -0,0 +1 @@ +{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/request-utils/plugins.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mCAAmC;AAOnC;;;;;;GAMG;AACH,KAAK,UAAU,aAAa,CAAsB,YAAY,GAAG,KAAK;IACrE,IAAK,CAAE,YAAY,IAAI,IAAI,CAAC,UAAU,EAAG;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC;KACvB;IAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QAChC,IAAI,EAAE,gBAAgB;KACtB,CAAE,CAAC;IACJ,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACrB,KAAM,MAAM,M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wright/e2e-test-utils-playwright/build/request-utils/posts.js new file mode 100644 index 00000000..36113c8a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/posts.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAllPosts = void 0; +/** + * Delete all posts using REST API. + * + * @this {import('./index').RequestUtils} + */ +async function deleteAllPosts() { + // List all posts. + // https://developer.wordpress.org/rest-api/reference/posts/#list-posts + const posts = await this.rest({ + path: '/wp/v2/posts', + params: { + per_page: 100, + // All possible statuses. + status: 'publish,future,draft,pending,private,trash', + }, + }); + // Delete all posts one by one. + // https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post + // "/wp/v2/posts" not yet supports batch requests. + await Promise.all(posts.map((post) => this.rest({ + method: 'DELETE', + path: `/wp/v2/posts/${post.id}`, + params: { + force: true, + }, + }))); +} +exports.deleteAllPosts = deleteAllPosts; +//# sourceMappingURL=posts.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/posts.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/posts.js.map new file mode 100644 index 00000000..d49a67b2 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/posts.js.map @@ -0,0 +1 @@ +{"version":3,"file":"posts.js","sourceRoot":"","sources":["../../src/request-utils/posts.js"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,KAAK,UAAU,cAAc;IACnC,kBAAkB;IAClB,uEAAuE;IACvE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QAC9B,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;YACb,yBAAyB;YACzB,MAAM,EAAE,4CAA4C;SACpD;KACD,CAAE,CAAC;IAEJ,+BAA+B;IAC/B,0EAA0E;IAC1E,kDAAkD;IAClD,MAAM,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAE,CAAE,IAAI,EAAG,EAAE,CACrB,IAAI,CAAC,IAAI,CAAE;QACV,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,gBAAiB,IAAI,CAAC,EAAG,EAAE;QACjC,MAAM,EAAE;YACP,KAAK,EAAE,IAAI;SACX;KACD,CAAE,CACH,CACD,CAAC;AACH,CAAC;AA1BD,wCA0BC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js new file mode 100644 index 00000000..8e172b73 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js @@ -0,0 +1,21 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.resetPreferences = void 0; +/** + * Reset user preferences + * + * @param {this} this Request utils. + */ +async function resetPreferences() { + await this.rest({ + path: '/wp/v2/users/me', + method: 'PUT', + data: { + meta: { + persisted_preferences: {}, + }, + }, + }); +} +exports.resetPreferences = resetPreferences; +//# sourceMappingURL=preferences.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js.map new file mode 100644 index 00000000..6855b3d0 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/preferences.js.map @@ -0,0 +1 @@ +{"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../src/request-utils/preferences.ts"],"names":[],"mappings":";;;AAKA;;;;GAIG;AACI,KAAK,UAAU,gBAAgB;IACrC,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE;YACL,IAAI,EAAE;gBACL,qBAAqB,EAAE,EAAE;aACzB;SACD;KACD,CAAE,CAAC;AACL,CAAC;AAVD,4CAUC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js new file mode 100644 index 00000000..9276d328 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js @@ -0,0 +1,130 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.batchRest = exports.getMaxBatchSize = exports.rest = exports.setupRest = void 0; +/** + * External dependencies + */ +const fs = require("fs/promises"); +const path_1 = require("path"); +/** + * Internal dependencies + */ +const config_1 = require("../config"); +function splitRequestsToChunks(requests, chunkSize) { + const arr = [...requests]; + const cache = []; + while (arr.length) { + cache.push(arr.splice(0, chunkSize)); + } + return cache; +} +async function getAPIRootURL(request) { + // Discover the API root url using link header. + // See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header + const response = await request.head(config_1.WP_BASE_URL); + const links = response.headers().link; + const restLink = links?.match(/<([^>]+)>; rel="https:\/\/api\.w\.org\/"/); + if (!restLink) { + throw new Error(`Failed to discover REST API endpoint. + Link header: ${links}`); + } + const [, rootURL] = restLink; + return rootURL; +} +async function setupRest() { + const [nonce, rootURL] = await Promise.all([ + this.login(), + getAPIRootURL(this.request), + ]); + const { cookies } = await this.request.storageState(); + const storageState = { + cookies, + nonce, + rootURL, + }; + if (this.storageStatePath) { + await fs.mkdir((0, path_1.dirname)(this.storageStatePath), { recursive: true }); + await fs.writeFile(this.storageStatePath, JSON.stringify(storageState), 'utf-8'); + } + this.storageState = storageState; + return storageState; +} +exports.setupRest = setupRest; +async function rest(options) { + const { path, ...fetchOptions } = options; + if (!path) { + throw new Error('"path" is required to make a REST call'); + } + if (!this.storageState?.nonce || !this.storageState?.rootURL) { + await this.setupRest(); + } + const relativePath = path.startsWith('/') ? path.slice(1) : path; + const url = this.storageState.rootURL + relativePath; + try { + const response = await this.request.fetch(url, { + ...fetchOptions, + failOnStatusCode: false, + headers: { + 'X-WP-Nonce': this.storageState.nonce, + ...(fetchOptions.headers || {}), + }, + }); + const json = await response.json(); + if (!response.ok()) { + throw json; + } + return json; + } + catch (error) { + // Nonce in invalid, retry again with a renewed nonce. + if (typeof error === 'object' && + error !== null && + Object.prototype.hasOwnProperty.call(error, 'code') && + error.code === 'rest_cookie_invalid_nonce') { + await this.setupRest(); + return this.rest(options); + } + throw error; + } +} +exports.rest = rest; +/** + * Get the maximum batch size for the REST API. + * + * @param {} this RequestUtils. + * @param {} forceRefetch Force revalidate the cached max batch size. + */ +async function getMaxBatchSize(forceRefetch = false) { + if (!forceRefetch && this.maxBatchSize) { + return this.maxBatchSize; + } + const response = await this.rest({ + method: 'OPTIONS', + path: '/batch/v1', + }); + this.maxBatchSize = response.endpoints[0].args.requests.maxItems; + return this.maxBatchSize; +} +exports.getMaxBatchSize = getMaxBatchSize; +async function batchRest(requests) { + const maxBatchSize = await this.getMaxBatchSize(); + if (requests.length > maxBatchSize) { + const chunks = splitRequestsToChunks(requests, maxBatchSize); + const chunkResponses = await Promise.all(chunks.map((chunkRequests) => this.batchRest(chunkRequests))); + return chunkResponses.flat(); + } + const batchResponses = await this.rest({ + method: 'POST', + path: '/batch/v1', + data: { + requests, + validation: 'require-all-validate', + }, + }); + if (batchResponses.failed) { + throw batchResponses; + } + return batchResponses.responses; +} +exports.batchRest = batchRest; +//# sourceMappingURL=rest.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js.map new file mode 100644 index 00000000..1b6a160e --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/rest.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/request-utils/rest.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,kCAAkC;AAClC,+BAA+B;AAG/B;;GAEG;AACH,sCAAwC;AAGxC,SAAS,qBAAqB,CAAE,QAAwB,EAAE,SAAiB;IAC1E,MAAM,GAAG,GAAG,C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AAc,CAAC,IAAI,EAAE,CAAC;KAC7B;IAED,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,IAAI,CAGjC;QACJ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE;YACL,QAAQ;YACR,UAAU,EAAE,sBAAsB;SAClC;KACD,CAAE,CAAC;IAEJ,IAAK,cAAc,CAAC,MAAM,EAAG;QAC5B,MAAM,cAAc,CAAC;KACrB;IAED,OAAO,cAAc,CAAC,SAAS,CAAC;AACjC,CAAC;AAE0C,8BAAS"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js new file mode 100644 index 00000000..d406673c --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js @@ -0,0 +1,45 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.deleteAllTemplates = void 0; +const PATH_MAPPING = { + wp_template: '/wp/v2/templates', + wp_template_part: '/wp/v2/template-parts', +}; +/** + * Delete all the templates of given type. + * + * @param this + * @param type - Template type to delete. + */ +async function deleteAllTemplates(type) { + const path = PATH_MAPPING[type]; + if (!path) { + throw new Error(`Unsupported template type: ${type}.`); + } + const templates = await this.rest({ path }); + for (const template of templates) { + if (!template?.id || !template?.wp_id) { + continue; + } + let response; + try { + response = await this.rest({ + method: 'DELETE', + path: `${path}/${template.id}`, + params: { force: true }, + }); + } + catch (responseError) { + // Disable reason - the error provides valuable feedback about issues with tests. + // eslint-disable-next-line no-console + console.warn(`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`, responseError); + } + if (!response.deleted) { + // Disable reason - the error provides valuable feedback about issues with tests. + // eslint-disable-next-line no-console + console.warn(`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following response`, response); + } + } +} +exports.deleteAllTemplates = deleteAllTemplates; +//# sourceMappingURL=templates.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js.map new file mode 100644 index 00000000..9c2ff826 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/templates.js.map @@ -0,0 +1 @@ +{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/request-utils/templates.ts"],"names":[],"mappings":";;;AAYA,MAAM,YAAY,GAAG;IACpB,WAAW,EAAE,kBAAkB;IAC/B,gBAAgB,EAAE,uBAAuB;CACzC,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,kBAAkB,CAAsB,IAAkB;IACxE,MAAM,IAAI,GAAG,YAAY,CAAE,IAAI,CAAE,CAAC;IAElC,IAAK,CAAE,IAAI,EAAG;QACb,MAAM,IAAI,KAAK,CAAE,8BAA+B,IAAK,GAAG,CAAE,CAAC;KAC3D;IAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAgB,EAAE,IAAI,EAAE,CAAE,CAAC;IAE5D,KAAM,MAAM,QAAQ,IAAI,SAAS,EAAG;QACnC,IAAK,CAAE,QAAQ,EAAE,EAAE,IAAI,CAAE,QAAQ,EAAE,KAAK,EAAG;YAC1C,SAAS;SACT;QAED,IAAI,QAAQ,CAAC;QAEb,IAAI;YACH,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;gBAC3B,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,GAAI,IAAK,IAAK,QAAQ,CAAC,EAAG,EAAE;gBAClC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;aACvB,CAAE,CAAC;SACJ;QAAC,OAAQ,aAAa,EAAG;YACzB,iFAAiF;YACjF,sCAAsC;YACtC,OAAO,CAAC,IAAI,CACX,qDAAsD,QAAQ,CAAC,KAAM,4BAA4B,EACjG,aAAa,CACb,CAAC;SACF;QAED,IAAK,CAAE,QAAQ,CAAC,OAAO,EAAG;YACzB,iFAAiF;YACjF,sCAAsC;YACtC,OAAO,CAAC,IAAI,CACX,qDAAsD,QAAQ,CAAC,KAAM,+BAA+B,EACpG,QAAQ,CACR,CAAC;SACF;KACD;AACF,CAAC;AAEQ,gDAAkB"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js new file mode 100644 index 00000000..f3e9bd1e --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.activateTheme = void 0; +const config_1 = require("../config"); +const THEMES_URL = new URL('/wp-admin/themes.php', config_1.WP_BASE_URL).href; +async function activateTheme(themeSlug) { + let response = await this.request.get(THEMES_URL); + const html = await response.text(); + const matchGroup = html.match(`action=activate&stylesheet=${encodeURIComponent(themeSlug)}&_wpnonce=[a-z0-9]+`); + if (!matchGroup) { + if (html.includes(`data-slug="${themeSlug}"`)) { + // The theme is already activated. + return; + } + throw new Error(`The theme "${themeSlug}" is not installed`); + } + const [activateQuery] = matchGroup; + const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, '&'); + response = await this.request.get(activateLink); + await response.dispose(); +} +exports.activateTheme = activateTheme; +//# sourceMappingURL=themes.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js.map new file mode 100644 index 00000000..68d7646a --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/themes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"themes.js","sourceRoot":"","sources":["../../src/request-utils/themes.ts"],"names":[],"mappings":";;;AAIA,sCAAwC;AAExC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAE,sBAAsB,EAAE,oBAAW,CAAE,CAAC,IAAI,CAAC;AAEvE,KAAK,UAAU,aAAa,CAE3B,SAAiB;IAEjB,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAE,UAAU,CAAE,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAC5B,kCAAmC,kBAAkB,CACpD,SAAS,CACR,yBAAyB,CAC3B,CAAC;IAEF,IAAK,CAAE,UAAU,EAAG;QACnB,IAAK,IAAI,CAAC,QAAQ,CAAE,cAAe,SAAU,GAAG,CAAE,EAAG;YACpD,kCAAkC;YAClC,OAAO;SACP;QAED,MAAM,IAAI,KAAK,CAAE,cAAe,SAAU,oBAAoB,CAAE,CAAC;KACjE;IAED,MAAM,CAAE,aAAa,CAAE,GAAG,UAAU,CAAC;IACrC,MAAM,YAAY,GACjB,UAAU,GAAG,IAAK,aAAc,EAAE,CAAC,OAAO,CAAE,QAAQ,EAAE,GAAG,CAAE,CAAC;IAE7D,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAE,YAAY,CAAE,CAAC;IAElD,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;AAC1B,CAAC;AAEQ,sCAAa"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js new file mode 100644 index 00000000..990e1644 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js @@ -0,0 +1,62 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.addWidgetBlock = exports.deleteAllWidgets = void 0; +/** + * Delete all the widgets in the widgets screen. + * + * @this {import('./index').RequestUtils} + */ +async function deleteAllWidgets() { + const [widgets, sidebars] = await Promise.all([ + this.rest({ path: '/wp/v2/widgets' }), + this.rest({ path: '/wp/v2/sidebars' }), + ]); + await this.batchRest(widgets.map((widget) => ({ + method: 'DELETE', + path: `/wp/v2/widgets/${widget.id}?force=true`, + }))); + // The endpoint doesn't support batch requests yet. + await Promise.all(sidebars.map((sidebar) => this.rest({ + method: 'POST', + path: `/wp/v2/sidebars/${sidebar.id}`, + data: { id: sidebar.id, widgets: [] }, + }))); +} +exports.deleteAllWidgets = deleteAllWidgets; +/** + * Add a widget block to the widget area. + * + * @this {import('./index').RequestUtils} + * @param {string} serializedBlock The serialized content of the inserted block HTML. + * @param {string} widgetAreaId The ID of the widget area. + */ +async function addWidgetBlock(serializedBlock, widgetAreaId) { + const { id: blockId } = await this.rest({ + method: 'POST', + path: '/wp/v2/widgets', + data: { + id_base: 'block', + sidebar: widgetAreaId, + instance: { + raw: { content: serializedBlock }, + }, + }, + }); + const { widgets } = await this.rest({ + path: `/wp/v2/sidebars/${widgetAreaId}`, + }); + const updatedWidgets = new Set(widgets); + // Remove duplicate. + updatedWidgets.delete(blockId); + // Add to last block. + updatedWidgets.add(blockId); + await this.rest({ + method: 'PUT', + path: `/wp/v2/sidebars/${widgetAreaId}`, + data: { + widgets: [...updatedWidgets], + }, + }); +} +exports.addWidgetBlock = addWidgetBlock; +//# sourceMappingURL=widgets.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js.map new file mode 100644 index 00000000..7c645135 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/request-utils/widgets.js.map @@ -0,0 +1 @@ +{"version":3,"file":"widgets.js","sourceRoot":"","sources":["../../src/request-utils/widgets.js"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,KAAK,UAAU,gBAAgB;IACrC,MAAM,CAAE,OAAO,EAAE,QAAQ,CAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAE;QAChD,IAAI,CAAC,IAAI,CAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAE;QACvC,IAAI,CAAC,IAAI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Ac,CAAC,GAAG,CAAE,OAAO,CAAE,CAAC;IAE9B,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,mBAAoB,YAAa,EAAE;QACzC,IAAI,EAAE;YACL,OAAO,EAAE,CAAE,GAAG,cAAc,CAAE;SAC9B;KACD,CAAE,CAAC;AACL,CAAC;AA9BD,wCA8BC"} \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js b/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js new file mode 100644 index 00000000..ae9262cc --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js @@ -0,0 +1,133 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.expect = exports.test = void 0; +/** + * External dependencies + */ +const path = require("path"); +const test_1 = require("@playwright/test"); +Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } }); +/** + * Internal dependencies + */ +const index_1 = require("./index"); +const STORAGE_STATE_PATH = process.env.STORAGE_STATE_PATH || + path.join(process.cwd(), 'artifacts/storage-states/admin.json'); +/** + * Set of console logging types observed to protect against unexpected yet + * handled (i.e. not catastrophic) errors or warnings. Each key corresponds + * to the Playwright ConsoleMessage type, its value the corresponding function + * on the console global object. + */ +const OBSERVED_CONSOLE_MESSAGE_TYPES = ['warn', 'error']; +/** + * Adds a page event handler to emit uncaught exception to process if one of + * the observed console logging types is encountered. + * + * @param message The console message. + */ +function observeConsoleLogging(message) { + const type = message.type(); + if (!OBSERVED_CONSOLE_MESSAGE_TYPES.includes(type)) { + return; + } + const text = message.text(); + // An exception is made for _blanket_ deprecation warnings: Those + // which log regardless of whether a deprecated feature is in use. + if (text.includes('This is a global warning')) { + return; + } + // A chrome advisory warning about SameSite cookies is informational + // about future changes, tracked separately for improvement in core. + // + // See: https://core.trac.wordpress.org/ticket/37000 + // See: https://www.chromestatus.com/feature/5088147346030592 + // See: https://www.chromestatus.com/feature/5633521622188032 + if (text.includes('A cookie associated with a cross-site resource')) { + return; + } + // Viewing posts on the front end can result in this error, which + // has nothing to do with Gutenberg. + if (text.includes('net::ERR_UNKNOWN_URL_SCHEME')) { + return; + } + // TODO: Not implemented yet. + // Network errors are ignored only if we are intentionally testing + // offline mode. + // if ( + // text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) && + // isOfflineMode() + // ) { + // return; + // } + // As of WordPress 5.3.2 in Chrome 79, navigating to the block editor + // (Posts > Add New) will display a console warning about + // non - unique IDs. + // See: https://core.trac.wordpress.org/ticket/23165 + if (text.includes('elements with non-unique id #_wpnonce')) { + return; + } + // Ignore all JQMIGRATE (jQuery migrate) deprecation warnings. + if (text.includes('JQMIGRATE')) { + return; + } + const logFunction = type; + // Disable reason: We intentionally bubble up the console message + // which, unless the test explicitly anticipates the logging via + // @wordpress/jest-console matchers, will cause the intended test + // failure. + // eslint-disable-next-line no-console + console[logFunction](text); +} +const test = test_1.test.extend({ + admin: async ({ page, pageUtils }, use) => { + await use(new index_1.Admin({ page, pageUtils })); + }, + editor: async ({ page }, use) => { + await use(new index_1.Editor({ page })); + }, + page: async ({ page }, use) => { + page.on('console', observeConsoleLogging); + await use(page); + // Clear local storage after each test. + await page.evaluate(() => { + window.localStorage.clear(); + }); + await page.close(); + }, + pageUtils: async ({ page }, use) => { + await use(new index_1.PageUtils({ page })); + }, + requestUtils: [ + async ({}, use, workerInfo) => { + const requestUtils = await index_1.RequestUtils.setup({ + baseURL: workerInfo.project.use.baseURL, + storageStatePath: STORAGE_STATE_PATH, + }); + await Promise.all([ + requestUtils.activateTheme('twentytwentyone'), + requestUtils.deleteAllPosts(), + requestUtils.deleteAllBlocks(), + requestUtils.resetPreferences(), + ]); + await use(requestUtils); + }, + { scope: 'worker' }, + ], + // An automatic fixture to configure snapshot settings globally. + snapshotConfig: [ + async ({}, use, testInfo) => { + // A work-around to remove the default snapshot suffix. + // See https://github.com/microsoft/playwright/issues/11134 + testInfo.snapshotSuffix = ''; + // Normalize snapshots into the same `__snapshots__` folder to minimize + // the file name length on Windows. + // See https://github.com/WordPress/gutenberg/issues/40291 + testInfo.snapshotDir = path.join(path.dirname(testInfo.file), '__snapshots__'); + await use(); + }, + { auto: true }, + ], +}); +exports.test = test; +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js.map b/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js.map new file mode 100644 index 00000000..db520534 --- /dev/null +++ b/tests/e2e-playwright/e2e-test-utils-playwright/build/test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,6BAA6B;AAC7B,2CAAwD;AAoKzC,uFApKQ,aAAM,OAoKR;AAjKrB;;GAEG;AACH,mCAAiE;AAEjE,MAAM,kBAAkB,GACvB,OAAO,CAAC,GAAG,CAAC,kBAAkB;IAC9B,IAAI,CAAC,IAAI,CAAE,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAE,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,8BAA8B,GAAG,CAAE,MAAM,EAAE,OAAO,CAAW,CAAC;AAEpE;;;;;GAKG;AACH,SAAS,qBAAqB,CAAE,OAAuB;IACtD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,IACC,CAAE,8BAA8B,CAAC,QAAQ,CACxC,IAAuD,CACvD,EACA;QACD,OAAO;KACP;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAE5B,iEAAiE;IACjE,kEAAkE;IAClE,IAAK,IAAI,CAAC,QAAQ,CAAE,0BAA0B,CAAE,EAAG;QAClD,OAAO;KACP;IAED,oEAAoE;IACpE,oEAAoE;IACpE,EAAE;IACF,oDAAoD;IACpD,6DAA6D;IAC7D,6DAA6D;IAC7D,IAAK,IAAI,CAAC,QAAQ,CAAE,gDAAgD,CAAE,EAAG;QACxE,O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AAC;QACb,CAAC;QACD,EAAE,IAAI,EAAE,IAAI,EAAE;KACd;CACD,CAAE,CAAC;AAEK,oBAAI"} \ No newline at end of file diff --git a/tests/e2e-playwright/package-lock.json b/tests/e2e-playwright/package-lock.json index 49a19320..a8f4d35f 100644 --- a/tests/e2e-playwright/package-lock.json +++ b/tests/e2e-playwright/package-lock.json @@ -2827,11 +2827,6 @@ "yallist": "^2.1.2" } }, - "prettier": { - "version": "npm:wp-prettier@2.6.2", - "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.6.2.tgz", - "integrity": "sha512-AV33EzqiFJ3fj+mPlKABN59YFPReLkDxQnj067Z3uEOeRQf3g05WprL0RDuqM7UBhSRo9W1rMSC2KvZmjE5UOA==" - }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -4374,6 +4369,11 @@ "domhandler": "^5.0.1" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -8192,6 +8192,11 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==" }, + "prettier": { + "version": "npm:wp-prettier@2.6.2", + "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.6.2.tgz", + "integrity": "sha512-AV33EzqiFJ3fj+mPlKABN59YFPReLkDxQnj067Z3uEOeRQf3g05WprL0RDuqM7UBhSRo9W1rMSC2KvZmjE5UOA==" + }, "prettier-linter-helpers": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", diff --git a/tests/e2e-playwright/specs/08_verify-new-registration.spec.js b/tests/e2e-playwright/specs/08_verify-new-registration.spec.js index c8a36134..7ec32094 100644 --- a/tests/e2e-playwright/specs/08_verify-new-registration.spec.js +++ b/tests/e2e-playwright/specs/08_verify-new-registration.spec.js @@ -7,7 +7,7 @@ const { WP_BASE_URL, WP_USERNAME, WP_PASSWORD -} = require( '@wordpress/e2e-test-utils-playwright/src/config' ); +} = require( '../e2e-test-utils-playwright/src/config' ); test.describe("Verify the new user registration ", () => { @@ -64,10 +64,10 @@ test.describe("Verify the new user registration ", () => { await page.click(".wp_google_login__button"); await page.waitForTimeout(1000); - await page.type('input[type="email"]', process.env.EMAIL); + await page.type('input[type="email"]', process.env.GMAIL_UNAME); await page.click("#identifierNext"); await page.waitForSelector('input[type="password"]', { visible: true }); - await page.type('input[type="password"]', process.env.PASSWORD); + await page.type('input[type="password"]', process.env.GMAIL_PASS); await page.waitForSelector("#passwordNext", { visible: true }); await page.click("#passwordNext"); diff --git a/tests/e2e-playwright/specs/09_logout-login-button-test.spec.js b/tests/e2e-playwright/specs/09_logout-login-button-test.spec.js index 09e303a1..136882ce 100644 --- a/tests/e2e-playwright/specs/09_logout-login-button-test.spec.js +++ b/tests/e2e-playwright/specs/09_logout-login-button-test.spec.js @@ -79,12 +79,12 @@ test.describe("Should be able to logout and login from the added gutenberg block await page.locator( 'role=link[name="Test block"i]' ).first().click(); await page.click(".wp_google_login__button"); - + await page.waitForTimeout(1000); - await page.type('input[type="email"]', process.env.EMAIL); + await page.type('input[type="email"]', process.env.GMAIL_UNAME); await page.click("#identifierNext"); await page.waitForSelector('input[type="password"]', { visible: true }); - await page.type('input[type="password"]',process.env.PASSWORD); + await page.type('input[type="password"]',process.env.GMAIL_PASS); await page.waitForSelector("#passwordNext", { visible: true }); await page.click("#passwordNext");