From 812662fbfc7adff9c9c87d2744b8e000e97bf17f Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 18 Oct 2022 15:12:32 -0300 Subject: [PATCH 01/20] Update Cypress (v9 => v10) --- package-lock.json | 30 ++++++++------ package.json | 6 +-- tests/cypress/config.js | 41 +++++++++++++++++++ tests/cypress/config.json | 15 ------- ...oard-sync.spec.js => dashboard-sync.cy.js} | 0 ...{autosuggest.spec.js => autosuggest.cy.js} | 0 .../{comments.spec.js => comments.cy.js} | 0 ...m-results.spec.js => custom-results.cy.js} | 0 .../{documents.spec.js => documents.cy.js} | 0 .../features/{facets.spec.js => facets.cy.js} | 0 ...-results.spec.js => instant-results.cy.js} | 0 ...ontent.spec.js => protected-content.cy.js} | 0 ...ated-posts.spec.js => related-posts.cy.js} | 0 .../search/{search.spec.js => search.cy.js} | 0 .../{synonyms.spec.js => synonyms.cy.js} | 0 .../{weighting.spec.js => weighting.cy.js} | 0 .../features/{terms.spec.js => terms.cy.js} | 0 ...{woocommerce.spec.js => woocommerce.cy.js} | 0 .../{general.spec.js => general.cy.js} | 0 .../indexables/{user.spec.js => user.cy.js} | 0 .../{wp-basic.spec.js => wp-basic.cy.js} | 0 .../{wp-cli.spec.js => wp-cli.cy.js} | 0 22 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 tests/cypress/config.js delete mode 100644 tests/cypress/config.json rename tests/cypress/integration/{dashboard-sync.spec.js => dashboard-sync.cy.js} (100%) rename tests/cypress/integration/features/{autosuggest.spec.js => autosuggest.cy.js} (100%) rename tests/cypress/integration/features/{comments.spec.js => comments.cy.js} (100%) rename tests/cypress/integration/features/{custom-results.spec.js => custom-results.cy.js} (100%) rename tests/cypress/integration/features/{documents.spec.js => documents.cy.js} (100%) rename tests/cypress/integration/features/{facets.spec.js => facets.cy.js} (100%) rename tests/cypress/integration/features/{instant-results.spec.js => instant-results.cy.js} (100%) rename tests/cypress/integration/features/{protected-content.spec.js => protected-content.cy.js} (100%) rename tests/cypress/integration/features/{related-posts.spec.js => related-posts.cy.js} (100%) rename tests/cypress/integration/features/search/{search.spec.js => search.cy.js} (100%) rename tests/cypress/integration/features/search/{synonyms.spec.js => synonyms.cy.js} (100%) rename tests/cypress/integration/features/search/{weighting.spec.js => weighting.cy.js} (100%) rename tests/cypress/integration/features/{terms.spec.js => terms.cy.js} (100%) rename tests/cypress/integration/features/{woocommerce.spec.js => woocommerce.cy.js} (100%) rename tests/cypress/integration/{general.spec.js => general.cy.js} (100%) rename tests/cypress/integration/indexables/{user.spec.js => user.cy.js} (100%) rename tests/cypress/integration/{wp-basic.spec.js => wp-basic.cy.js} (100%) rename tests/cypress/integration/{wp-cli.spec.js => wp-cli.cy.js} (100%) diff --git a/package-lock.json b/package-lock.json index fe67b2f0db..b6157698c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@wordpress/env": "^5.0.0", "10up-toolkit": "^3.0.0", "classnames": "^2.3.1", - "cypress": "^9.5.0", + "cypress": "^10.10.0", "cypress-file-upload": "^5.0.8", "eslint-plugin-cypress": "^2.12.1", "jsdoc": "^3.6.10", @@ -6461,10 +6461,11 @@ "license": "MIT" }, "node_modules/cypress": { - "version": "9.5.1", + "version": "10.10.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-10.10.0.tgz", + "integrity": "sha512-bU8r44x1NIYAUNNXt3CwJpLOVth7HUv2hUhYCxZmgZ1IugowDvuHNpevnoZRQx1KKOEisLvIJW+Xen5Pjn41pg==", "dev": true, "hasInstallScript": true, - "license": "MIT", "dependencies": { "@cypress/request": "^2.88.10", "@cypress/xvfb": "^1.2.4", @@ -6485,7 +6486,7 @@ "dayjs": "^1.10.4", "debug": "^4.3.2", "enquirer": "^2.3.6", - "eventemitter2": "^6.4.3", + "eventemitter2": "6.4.7", "execa": "4.1.0", "executable": "^4.1.1", "extract-zip": "2.0.1", @@ -6498,7 +6499,7 @@ "listr2": "^3.8.3", "lodash": "^4.17.21", "log-symbols": "^4.0.0", - "minimist": "^1.2.5", + "minimist": "^1.2.6", "ospath": "^1.2.2", "pretty-bytes": "^5.6.0", "proxy-from-env": "1.0.0", @@ -8046,9 +8047,10 @@ } }, "node_modules/eventemitter2": { - "version": "6.4.5", - "dev": true, - "license": "MIT" + "version": "6.4.7", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.7.tgz", + "integrity": "sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==", + "dev": true }, "node_modules/eventemitter3": { "version": "4.0.7", @@ -22981,7 +22983,9 @@ "version": "3.0.11" }, "cypress": { - "version": "9.5.1", + "version": "10.10.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-10.10.0.tgz", + "integrity": "sha512-bU8r44x1NIYAUNNXt3CwJpLOVth7HUv2hUhYCxZmgZ1IugowDvuHNpevnoZRQx1KKOEisLvIJW+Xen5Pjn41pg==", "dev": true, "requires": { "@cypress/request": "^2.88.10", @@ -23003,7 +23007,7 @@ "dayjs": "^1.10.4", "debug": "^4.3.2", "enquirer": "^2.3.6", - "eventemitter2": "^6.4.3", + "eventemitter2": "6.4.7", "execa": "4.1.0", "executable": "^4.1.1", "extract-zip": "2.0.1", @@ -23016,7 +23020,7 @@ "listr2": "^3.8.3", "lodash": "^4.17.21", "log-symbols": "^4.0.0", - "minimist": "^1.2.5", + "minimist": "^1.2.6", "ospath": "^1.2.2", "pretty-bytes": "^5.6.0", "proxy-from-env": "1.0.0", @@ -23996,7 +24000,9 @@ "dev": true }, "eventemitter2": { - "version": "6.4.5", + "version": "6.4.7", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.7.tgz", + "integrity": "sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==", "dev": true }, "eventemitter3": { diff --git a/package.json b/package.json index c282ef001d..02631643bb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@wordpress/env": "^5.0.0", "10up-toolkit": "^3.0.0", "classnames": "^2.3.1", - "cypress": "^9.5.0", + "cypress": "^10.10.0", "cypress-file-upload": "^5.0.8", "eslint-plugin-cypress": "^2.12.1", "jsdoc": "^3.6.10", @@ -32,8 +32,8 @@ "env:start": "wp-env start && npm run env:install-tests-cli && cd bin/es-docker/ && docker-compose up -d", "env:stop": "wp-env stop && cd bin/es-docker/ && docker-compose down", "cypress:setup": "./bin/setup-cypress-env.sh", - "cypress:open": "cypress open --config-file tests/cypress/config.json", - "cypress:run": "cypress run --config-file tests/cypress/config.json" + "cypress:open": "cypress open --config-file tests/cypress/config.js", + "cypress:run": "cypress run --config-file tests/cypress/config.js" }, "author": "10up", "repository": { diff --git a/tests/cypress/config.js b/tests/cypress/config.js new file mode 100644 index 0000000000..2b41459d18 --- /dev/null +++ b/tests/cypress/config.js @@ -0,0 +1,41 @@ +const { defineConfig } = require('cypress'); + +module.exports = defineConfig({ + fixturesFolder: 'tests/cypress/fixtures', + screenshotsFolder: 'tests/cypress/screenshots', + videosFolder: 'tests/cypress/videos', + downloadsFolder: 'tests/cypress/downloads', + video: false, + retries: { + runMode: 1, + }, + elasticPressIndexTimeout: 100000, + pluginName: 'plugins', + e2e: { + // We've imported your old cypress plugins here. + // You may want to clean this up later by importing these. + async setupNodeEvents(on, config) { + const path = require('path'); + const { readConfig } = require('@wordpress/env/lib/config'); + const wpEnvConfig = await readConfig('wp-env'); + + if (wpEnvConfig) { + const port = wpEnvConfig.env.tests.port || null; + + if (port) { + config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL; + } + } + + // Account for ElasticPress and elasticpress usages. + config.pluginName = path.resolve(`${process.cwd()}../../../`).split('/').pop(); + + console.log(config); + + return config; + }, + specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', + supportFile: 'tests/cypress/support/index.js', + baseUrl: 'http://localhost:8889/', + }, +}); diff --git a/tests/cypress/config.json b/tests/cypress/config.json deleted file mode 100644 index 3116a52581..0000000000 --- a/tests/cypress/config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "fixturesFolder": "tests/cypress/fixtures", - "integrationFolder": "tests/cypress/integration", - "pluginsFile": "tests/cypress/plugins/index.js", - "screenshotsFolder": "tests/cypress/screenshots", - "videosFolder": "tests/cypress/videos", - "downloadsFolder": "tests/cypress/downloads", - "supportFile": "tests/cypress/support/index.js", - "video": false, - - "retries": { - "runMode": 1 - }, - "elasticPressIndexTimeout": 100000 -} diff --git a/tests/cypress/integration/dashboard-sync.spec.js b/tests/cypress/integration/dashboard-sync.cy.js similarity index 100% rename from tests/cypress/integration/dashboard-sync.spec.js rename to tests/cypress/integration/dashboard-sync.cy.js diff --git a/tests/cypress/integration/features/autosuggest.spec.js b/tests/cypress/integration/features/autosuggest.cy.js similarity index 100% rename from tests/cypress/integration/features/autosuggest.spec.js rename to tests/cypress/integration/features/autosuggest.cy.js diff --git a/tests/cypress/integration/features/comments.spec.js b/tests/cypress/integration/features/comments.cy.js similarity index 100% rename from tests/cypress/integration/features/comments.spec.js rename to tests/cypress/integration/features/comments.cy.js diff --git a/tests/cypress/integration/features/custom-results.spec.js b/tests/cypress/integration/features/custom-results.cy.js similarity index 100% rename from tests/cypress/integration/features/custom-results.spec.js rename to tests/cypress/integration/features/custom-results.cy.js diff --git a/tests/cypress/integration/features/documents.spec.js b/tests/cypress/integration/features/documents.cy.js similarity index 100% rename from tests/cypress/integration/features/documents.spec.js rename to tests/cypress/integration/features/documents.cy.js diff --git a/tests/cypress/integration/features/facets.spec.js b/tests/cypress/integration/features/facets.cy.js similarity index 100% rename from tests/cypress/integration/features/facets.spec.js rename to tests/cypress/integration/features/facets.cy.js diff --git a/tests/cypress/integration/features/instant-results.spec.js b/tests/cypress/integration/features/instant-results.cy.js similarity index 100% rename from tests/cypress/integration/features/instant-results.spec.js rename to tests/cypress/integration/features/instant-results.cy.js diff --git a/tests/cypress/integration/features/protected-content.spec.js b/tests/cypress/integration/features/protected-content.cy.js similarity index 100% rename from tests/cypress/integration/features/protected-content.spec.js rename to tests/cypress/integration/features/protected-content.cy.js diff --git a/tests/cypress/integration/features/related-posts.spec.js b/tests/cypress/integration/features/related-posts.cy.js similarity index 100% rename from tests/cypress/integration/features/related-posts.spec.js rename to tests/cypress/integration/features/related-posts.cy.js diff --git a/tests/cypress/integration/features/search/search.spec.js b/tests/cypress/integration/features/search/search.cy.js similarity index 100% rename from tests/cypress/integration/features/search/search.spec.js rename to tests/cypress/integration/features/search/search.cy.js diff --git a/tests/cypress/integration/features/search/synonyms.spec.js b/tests/cypress/integration/features/search/synonyms.cy.js similarity index 100% rename from tests/cypress/integration/features/search/synonyms.spec.js rename to tests/cypress/integration/features/search/synonyms.cy.js diff --git a/tests/cypress/integration/features/search/weighting.spec.js b/tests/cypress/integration/features/search/weighting.cy.js similarity index 100% rename from tests/cypress/integration/features/search/weighting.spec.js rename to tests/cypress/integration/features/search/weighting.cy.js diff --git a/tests/cypress/integration/features/terms.spec.js b/tests/cypress/integration/features/terms.cy.js similarity index 100% rename from tests/cypress/integration/features/terms.spec.js rename to tests/cypress/integration/features/terms.cy.js diff --git a/tests/cypress/integration/features/woocommerce.spec.js b/tests/cypress/integration/features/woocommerce.cy.js similarity index 100% rename from tests/cypress/integration/features/woocommerce.spec.js rename to tests/cypress/integration/features/woocommerce.cy.js diff --git a/tests/cypress/integration/general.spec.js b/tests/cypress/integration/general.cy.js similarity index 100% rename from tests/cypress/integration/general.spec.js rename to tests/cypress/integration/general.cy.js diff --git a/tests/cypress/integration/indexables/user.spec.js b/tests/cypress/integration/indexables/user.cy.js similarity index 100% rename from tests/cypress/integration/indexables/user.spec.js rename to tests/cypress/integration/indexables/user.cy.js diff --git a/tests/cypress/integration/wp-basic.spec.js b/tests/cypress/integration/wp-basic.cy.js similarity index 100% rename from tests/cypress/integration/wp-basic.spec.js rename to tests/cypress/integration/wp-basic.cy.js diff --git a/tests/cypress/integration/wp-cli.spec.js b/tests/cypress/integration/wp-cli.cy.js similarity index 100% rename from tests/cypress/integration/wp-cli.spec.js rename to tests/cypress/integration/wp-cli.cy.js From 354c0b55ad8128b9576d9fbc31214f2532afbf53 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 18 Oct 2022 15:19:38 -0300 Subject: [PATCH 02/20] Fix lint problems --- tests/cypress/config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cypress/config.js b/tests/cypress/config.js index 2b41459d18..5f5c83cae9 100644 --- a/tests/cypress/config.js +++ b/tests/cypress/config.js @@ -15,8 +15,11 @@ module.exports = defineConfig({ // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. async setupNodeEvents(on, config) { + /* eslint-disable global-require */ const path = require('path'); const { readConfig } = require('@wordpress/env/lib/config'); + /* eslint-enable global-require */ + const wpEnvConfig = await readConfig('wp-env'); if (wpEnvConfig) { @@ -30,8 +33,6 @@ module.exports = defineConfig({ // Account for ElasticPress and elasticpress usages. config.pluginName = path.resolve(`${process.cwd()}../../../`).split('/').pop(); - console.log(config); - return config; }, specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', From ea2a56a9a03c7352dbdab0d10fdceb6f06b6282e Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 18 Oct 2022 16:09:45 -0300 Subject: [PATCH 03/20] Make sure we activate the plugin in the single site --- tests/cypress/integration/dashboard-sync.cy.js | 1 + tests/cypress/integration/wp-cli.cy.js | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/cypress/integration/dashboard-sync.cy.js b/tests/cypress/integration/dashboard-sync.cy.js index ade809e279..e36741cfc6 100644 --- a/tests/cypress/integration/dashboard-sync.cy.js +++ b/tests/cypress/integration/dashboard-sync.cy.js @@ -31,6 +31,7 @@ describe('Dashboard Sync', () => { afterEach(() => { if (cy.state('test').state === 'failed') { cy.deactivatePlugin('elasticpress', 'wpCli', 'network'); + cy.activatePlugin('elasticpress', 'wpCli'); cy.wpCli('wp elasticpress clear-index', true); } }); diff --git a/tests/cypress/integration/wp-cli.cy.js b/tests/cypress/integration/wp-cli.cy.js index 93eb048e46..53feec7fbd 100644 --- a/tests/cypress/integration/wp-cli.cy.js +++ b/tests/cypress/integration/wp-cli.cy.js @@ -240,6 +240,7 @@ describe('WP-CLI Commands', () => { after(() => { cy.deactivatePlugin('elasticpress', 'wpCli', 'network'); + cy.activatePlugin('elasticpress', 'wpCli'); }); it('Can index all blogs in network if user specifies --network-wide argument', () => { From 913375257922384c83da38fdbd03ac7680c0e5fe Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 18 Oct 2022 16:59:18 -0300 Subject: [PATCH 04/20] Update action versions to fix some warnings --- .github/workflows/cypress-tests.yml | 8 ++++---- .github/workflows/lint.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml index 4b1747b383..ceac7b19d2 100644 --- a/.github/workflows/cypress-tests.yml +++ b/.github/workflows/cypress-tests.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v3 - name: Prepare npm cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.NODE_CACHE }} key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} @@ -54,7 +54,7 @@ jobs: run: npm run cypress:run - name: Make artifacts available - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: cypress-artifact @@ -77,7 +77,7 @@ jobs: uses: actions/checkout@v3 - name: Prepare npm cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.NODE_CACHE }} key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} @@ -107,7 +107,7 @@ jobs: run: npm run cypress:run - name: Make artifacts available - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: cypress-artifact-epio diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 179b3f51d4..60c9e398c8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -29,7 +29,7 @@ jobs: sudo npm config set cache "${{ env.NODE_CACHE }}" --global - name: Prepare npm cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.NODE_CACHE }} key: npm-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }} @@ -63,7 +63,7 @@ jobs: composer config -g cache-dir "${{ env.COMPOSER_CACHE }}" - name: Prepare composer cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.COMPOSER_CACHE }} key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf2384c9e0..a17e0f6840 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,7 +45,7 @@ jobs: composer config -g cache-dir "${{ env.COMPOSER_CACHE }}" - name: Prepare composer cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.COMPOSER_CACHE }} key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} @@ -98,7 +98,7 @@ jobs: composer config -g cache-dir "${{ env.COMPOSER_CACHE }}" - name: Prepare composer cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.COMPOSER_CACHE }} key: composer-${{ env.COMPOSER_VERSION }}-${{ hashFiles('**/composer.lock') }} From 42e8f6e5a0ad1d15cd88d0aaf31359dd956c3375 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 11:46:05 -0300 Subject: [PATCH 05/20] Give ES time to update its documents --- tests/cypress/integration/features/custom-results.cy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/cypress/integration/features/custom-results.cy.js b/tests/cypress/integration/features/custom-results.cy.js index d572f72892..7866f57a44 100644 --- a/tests/cypress/integration/features/custom-results.cy.js +++ b/tests/cypress/integration/features/custom-results.cy.js @@ -82,9 +82,13 @@ describe('Custom Results', () => { .then((text) => searchResult.push(text)); }); - cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); cy.get('#publish').click(); - cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); + + /** + * Give Elasticsearch some time to update the posts. + */ + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); cy.visit(`?s=${searchTerm}`); From 7ef9369adb2285b7193ac3e71765e048c479a598 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 11:56:07 -0300 Subject: [PATCH 06/20] An attempt to make sure the setting is saved --- .../features/search/weighting.cy.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index d93dbf5d7d..b715110464 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -10,16 +10,24 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.get('.hentry').should('contain.text', 'Test ElasticPress 1'); cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled').click(); - cy.get('#submit').click(); - - cy.visit('/?s=Test+ElasticPress+1'); - cy.get('.hentry').should('not.exist'); + cy.get('#post-post_title-enabled') + .click() + .then(() => { + cy.get('#submit') + .click() + .then(() => { + cy.visit('/?s=Test+ElasticPress+1'); + cy.get('.hentry').should('not.exist'); + }); + }); // Reset setting. cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled').click(); - cy.get('#submit').click(); + cy.get('#post-post_title-enabled') + .click() + .then(() => { + cy.get('#submit').click(); + }); }); it('Can increase post_title weighting and influence search results', () => { From f3b960136bc1bb5ac5114d6cd288bee762dd42a9 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 12:27:53 -0300 Subject: [PATCH 07/20] Take a screenshot of the weighting dashboard --- .../features/search/weighting.cy.js | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index b715110464..45f6ebcd6c 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -10,24 +10,17 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.get('.hentry').should('contain.text', 'Test ElasticPress 1'); cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled') - .click() - .then(() => { - cy.get('#submit') - .click() - .then(() => { - cy.visit('/?s=Test+ElasticPress+1'); - cy.get('.hentry').should('not.exist'); - }); - }); + cy.get('#post-post_title-enabled').click(); + cy.screenshot(); + cy.get('#submit').click(); + + cy.visit('/?s=Test+ElasticPress+1'); + cy.get('.hentry').should('not.exist'); // Reset setting. cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled') - .click() - .then(() => { - cy.get('#submit').click(); - }); + cy.get('#post-post_title-enabled').click(); + cy.get('#submit').click(); }); it('Can increase post_title weighting and influence search results', () => { From c525777df641b6944b13a7bb670f69c2139d2132 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 13:41:31 -0300 Subject: [PATCH 08/20] Check if checkbox is not checked and takes screenshot again --- tests/cypress/integration/features/search/weighting.cy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index 45f6ebcd6c..9d3fee0476 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -11,9 +11,11 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.visitAdminPage('admin.php?page=elasticpress-weighting'); cy.get('#post-post_title-enabled').click(); - cy.screenshot(); cy.get('#submit').click(); + cy.get('#post-post_title-enabled').should('be.checked'); + cy.screenshot(); + cy.visit('/?s=Test+ElasticPress+1'); cy.get('.hentry').should('not.exist'); From 56c18ede37b59a81e24b205dbc6a930c39095a5e Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 13:59:14 -0300 Subject: [PATCH 09/20] Fix logic of checkbox check and make sure we start with the right weighting config --- tests/cypress/integration/features/search/weighting.cy.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index 9d3fee0476..55849fbe1c 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -1,4 +1,8 @@ describe('Post Search Feature - Weighting Functionality', () => { + before(() => { + cy.updateWeighting(); + }); + it("Can't find a post by title if title is not marked as searchable", () => { cy.login(); @@ -13,7 +17,7 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.get('#post-post_title-enabled').click(); cy.get('#submit').click(); - cy.get('#post-post_title-enabled').should('be.checked'); + cy.get('#post-post_title-enabled').should('not.be.checked'); cy.screenshot(); cy.visit('/?s=Test+ElasticPress+1'); From 52002572614c33e5ee202114d78c514e21e83d43 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 15:14:47 -0300 Subject: [PATCH 10/20] check() vs click() --- .../integration/features/search/weighting.cy.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index 55849fbe1c..0a5b51d9f2 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -1,11 +1,9 @@ describe('Post Search Feature - Weighting Functionality', () => { - before(() => { - cy.updateWeighting(); - }); - it("Can't find a post by title if title is not marked as searchable", () => { cy.login(); + cy.updateWeighting(); + cy.publishPost({ title: 'Test ElasticPress 1', }); @@ -14,7 +12,7 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.get('.hentry').should('contain.text', 'Test ElasticPress 1'); cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled').click(); + cy.get('#post-post_title-enabled').uncheck(); cy.get('#submit').click(); cy.get('#post-post_title-enabled').should('not.be.checked'); @@ -25,7 +23,7 @@ describe('Post Search Feature - Weighting Functionality', () => { // Reset setting. cy.visitAdminPage('admin.php?page=elasticpress-weighting'); - cy.get('#post-post_title-enabled').click(); + cy.get('#post-post_title-enabled').check(); cy.get('#submit').click(); }); From a6d45d5e9e279e0b736705b977eabba126d518ab Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 16:54:29 -0300 Subject: [PATCH 11/20] Optimize comments tests e2e --- .../integration/features/comments.cy.js | 63 ++++++++----------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/tests/cypress/integration/features/comments.cy.js b/tests/cypress/integration/features/comments.cy.js index cc004e5788..88d3c9b857 100644 --- a/tests/cypress/integration/features/comments.cy.js +++ b/tests/cypress/integration/features/comments.cy.js @@ -58,34 +58,26 @@ describe('Comments Feature', () => { cy.get('#submit').click(); // start sync and test results. - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.get('.ep-sync-button--sync').click(); - cy.get('.ep-sync-panel').first().as('syncPanel'); - cy.get('@syncPanel').find('.components-form-toggle').click(); - cy.get('@syncPanel') - .find('.ep-sync-messages', { - timeout: Cypress.config('elasticPressIndexTimeout'), - }) - .should('contain.text', `Number of comments indexed: ${defaultApprovedComments}`); + cy.wpCli('wp elasticpress index') + .its('stdout') + .should('contain', `Number of comments indexed: ${defaultApprovedComments}`); // approve the comment cy.visitAdminPage('edit-comments.php?comment_status=moderated'); cy.get('.approve a').first().click({ force: true }); - // start sync and test results. - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.get('.ep-sync-button--sync').click(); - cy.get('.ep-sync-panel').first().as('syncPanel'); - cy.get('@syncPanel').find('.components-form-toggle').click(); - cy.get('@syncPanel') - .find('.ep-sync-messages', { - timeout: Cypress.config('elasticPressIndexTimeout'), - }) - .should('contain.text', `Number of comments indexed: ${defaultApprovedComments + 1}`); + // Check the number of comments. + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments + 1}`); // trash the comment cy.visitAdminPage('edit-comments.php?comment_status=approved'); cy.get('.column-comment .trash a').first().click({ force: true }); + + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments}`); }); it('Can see ElasticPress - Comment widget in dashboard', () => { @@ -114,14 +106,14 @@ describe('Comments Feature', () => { cy.get('#comment').type('This is a test review'); cy.get('#submit').click(); - // start sync and test results. - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.get('.ep-sync-button--sync').click(); - cy.get('.ep-sync-panel').first().as('syncPanel'); - cy.get('@syncPanel').find('.components-form-toggle').click(); - cy.get('@syncPanel') - .find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') }) - .should('contain.text', `Number of comments indexed: ${defaultApprovedComments + 1}`); + // Check if the new comment was indexed + cy.wpCli('wp elasticpress request localhost8889-comment-1-beb0d86b8d9c/_refresh').then( + () => { + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments + 1}`); + }, + ); // trash the review cy.visitAdminPage( @@ -152,16 +144,13 @@ describe('Comments Feature', () => { cy.get('#comment').type('This is a anonymous comment'); cy.get('#submit').click(); - // start sync and test results. - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.get('.ep-sync-button--sync').click(); - cy.get('.ep-sync-panel').first().as('syncPanel'); - cy.get('@syncPanel').find('.components-form-toggle').click(); - cy.get('@syncPanel') - .find('.ep-sync-messages', { - timeout: Cypress.config('elasticPressIndexTimeout'), - }) - .should('contain.text', `Number of comments indexed: ${defaultApprovedComments + 1}`); + cy.wpCli('wp elasticpress request localhost8889-comment-1-beb0d86b8d9c/_refresh').then( + () => { + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments + 1}`); + }, + ); // trash the comment cy.visitAdminPage('edit-comments.php?comment_status=approved'); From dbe8988c997ec8da588300313e31d2419b1cff03 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 17:25:05 -0300 Subject: [PATCH 12/20] Remove references to plugins --- tests/cypress/config.js | 4 ---- tests/cypress/plugins/index.js | 38 ---------------------------------- 2 files changed, 42 deletions(-) delete mode 100644 tests/cypress/plugins/index.js diff --git a/tests/cypress/config.js b/tests/cypress/config.js index 5f5c83cae9..1b34308ecd 100644 --- a/tests/cypress/config.js +++ b/tests/cypress/config.js @@ -10,10 +10,7 @@ module.exports = defineConfig({ runMode: 1, }, elasticPressIndexTimeout: 100000, - pluginName: 'plugins', e2e: { - // We've imported your old cypress plugins here. - // You may want to clean this up later by importing these. async setupNodeEvents(on, config) { /* eslint-disable global-require */ const path = require('path'); @@ -37,6 +34,5 @@ module.exports = defineConfig({ }, specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', supportFile: 'tests/cypress/support/index.js', - baseUrl: 'http://localhost:8889/', }, }); diff --git a/tests/cypress/plugins/index.js b/tests/cypress/plugins/index.js deleted file mode 100644 index c16b03bd15..0000000000 --- a/tests/cypress/plugins/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/// -// *********************************************************** -// This example plugins/index.js can be used to load plugins -// -// You can change the location of this file or turn off loading -// the plugins file with the 'pluginsFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/plugins-guide -// *********************************************************** - -// This function is called when a project is opened or re-opened (e.g. due to -// the project's config changing) - -const { readConfig } = require('@wordpress/env/lib/config'); - -/** - * Dynamically set some configs. - * - * @type {Cypress.PluginConfig} - */ -// eslint-disable-next-line no-unused-vars -module.exports = async (on, config) => { - const wpEnvConfig = await readConfig('wp-env'); - - if (wpEnvConfig) { - const port = wpEnvConfig.env.tests.port || null; - - if (port) { - config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL; - } - } - - // Account for ElasticPress and elasticpress usages. - config.pluginName = process.cwd().split('/').pop(); - - return config; -}; From b4d78fbc4cf568d70ac1a3fdbaf25affba9fa4b0 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 17:25:16 -0300 Subject: [PATCH 13/20] refresh indices the right way --- .../integration/features/comments.cy.js | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/cypress/integration/features/comments.cy.js b/tests/cypress/integration/features/comments.cy.js index 88d3c9b857..36508f9cd0 100644 --- a/tests/cypress/integration/features/comments.cy.js +++ b/tests/cypress/integration/features/comments.cy.js @@ -107,13 +107,11 @@ describe('Comments Feature', () => { cy.get('#submit').click(); // Check if the new comment was indexed - cy.wpCli('wp elasticpress request localhost8889-comment-1-beb0d86b8d9c/_refresh').then( - () => { - cy.wpCli('wp elasticpress stats') - .its('stdout') - .should('contain', `Documents: ${defaultApprovedComments + 1}`); - }, - ); + cy.wpCliEval('\\ElasticPress\\Elasticsearch::factory()->refresh_indices();').then(() => { + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments + 1}`); + }); // trash the review cy.visitAdminPage( @@ -144,13 +142,11 @@ describe('Comments Feature', () => { cy.get('#comment').type('This is a anonymous comment'); cy.get('#submit').click(); - cy.wpCli('wp elasticpress request localhost8889-comment-1-beb0d86b8d9c/_refresh').then( - () => { - cy.wpCli('wp elasticpress stats') - .its('stdout') - .should('contain', `Documents: ${defaultApprovedComments + 1}`); - }, - ); + cy.wpCliEval('\\ElasticPress\\Elasticsearch::factory()->refresh_indices();').then(() => { + cy.wpCli('wp elasticpress stats') + .its('stdout') + .should('contain', `Documents: ${defaultApprovedComments + 1}`); + }); // trash the comment cy.visitAdminPage('edit-comments.php?comment_status=approved'); From 484421c414baf1efec2a2e21d5c27900deb8114c Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 17:41:48 -0300 Subject: [PATCH 14/20] Narrow the target of post title --- .../integration/features/search/weighting.cy.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/cypress/integration/features/search/weighting.cy.js b/tests/cypress/integration/features/search/weighting.cy.js index 0a5b51d9f2..ac6157523c 100644 --- a/tests/cypress/integration/features/search/weighting.cy.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -5,20 +5,17 @@ describe('Post Search Feature - Weighting Functionality', () => { cy.updateWeighting(); cy.publishPost({ - title: 'Test ElasticPress 1', + title: 'supercustomtitle', }); - cy.visit('/?s=Test+ElasticPress+1'); - cy.get('.hentry').should('contain.text', 'Test ElasticPress 1'); + cy.visit('/?s=supercustomtitle'); + cy.get('.hentry').should('contain.text', 'supercustomtitle'); cy.visitAdminPage('admin.php?page=elasticpress-weighting'); cy.get('#post-post_title-enabled').uncheck(); cy.get('#submit').click(); - cy.get('#post-post_title-enabled').should('not.be.checked'); - cy.screenshot(); - - cy.visit('/?s=Test+ElasticPress+1'); + cy.visit('/?s=supercustomtitle'); cy.get('.hentry').should('not.exist'); // Reset setting. From 7583434227dded4ce5f634539477d405834fe826 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 19:31:44 -0300 Subject: [PATCH 15/20] Adjust custom results tests --- .../integration/features/custom-results.cy.js | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/tests/cypress/integration/features/custom-results.cy.js b/tests/cypress/integration/features/custom-results.cy.js index 7866f57a44..943dc67fcc 100644 --- a/tests/cypress/integration/features/custom-results.cy.js +++ b/tests/cypress/integration/features/custom-results.cy.js @@ -31,24 +31,33 @@ describe('Custom Results', () => { cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); // change the position of the post + // eslint-disable-next-line jest/valid-expect-in-promise cy.dragAndDrop( '.pointers .pointer:first-of-type .dashicons-menu', '.pointers .pointer:last-of-type .dashicons-menu', ).then(() => { // save the posts positions in a list - cy.get('.pointers .pointer .title').each((post) => { - cy.wrap(post) - .invoke('text') - .then((text) => searchResult.push(text)); - }); - cy.get('#publish').click(); - }); - - cy.visit(`?s=${searchTerm}`); - - // verify the result of the search is in the same position. - cy.get('article .entry-title').each((post, index) => { - cy.wrap(post).invoke('text').should('eq', searchResult[index]); + cy.get('.pointers .pointer .title') + .each((post) => { + searchResult.push(post[0].innerText); + }) + .then(() => { + expect(searchResult.length).to.be.gt(0); + cy.get('#publish').click(); + + cy.visit(`?s=${searchTerm}`); + + // verify the result of the search is in the same position. + cy.get(`article:nth-child(-n+${searchResult.length}) .entry-title`).each( + (post, index) => { + cy.writeFile( + `tests/cypress/logs/testing-${index}.log`, + post[0].innerText, + ); + expect(post[0].innerText).to.equal(searchResult[index]); + }, + ); + }); }); }); @@ -76,25 +85,24 @@ describe('Custom Results', () => { cy.get('.pointer-result:first-of-type .dashicons-plus.add-pointer').click(); // save the posts positions in a list - cy.get('.pointers .pointer .title').each((post) => { - cy.wrap(post) - .invoke('text') - .then((text) => searchResult.push(text)); - }); - - cy.get('#publish').click(); - - /** - * Give Elasticsearch some time to update the posts. - */ - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - - cy.visit(`?s=${searchTerm}`); - - // verify the result of the search is in the same position. - cy.get('article .entry-title').each((post, index) => { - cy.wrap(post).invoke('text').should('eq', searchResult[index]); - }); + // eslint-disable-next-line jest/valid-expect-in-promise + cy.get('.pointers .pointer .title') + .each((post) => { + searchResult.push(post[0].innerText); + }) + .then(() => { + expect(searchResult.length).to.be.gt(0); + cy.get('#publish').click(); + + cy.visit(`?s=${searchTerm}`); + + // verify the result of the search is in the same position. + cy.get(`article:nth-child(-n+${searchResult.length}) .entry-title`).each( + (post, index) => { + cy.writeFile(`tests/cypress/logs/testing-${index}.log`, post[0].innerText); + expect(post[0].innerText).to.equal(searchResult[index]); + }, + ); + }); }); }); From 34bbd0c63f34af7a8d8852158daf184fc348f7bc Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 19:50:07 -0300 Subject: [PATCH 16/20] Optimize maybeEnableFeature and maybeDisableFeature --- tests/cypress/support/commands.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 5c409c61d8..ff3019ab7b 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -216,19 +216,11 @@ Cypress.Commands.add('updateWeighting', (newWeightingValues = null) => { }); Cypress.Commands.add('maybeEnableFeature', (featureName) => { - cy.wpCli('elasticpress list-features').then((wpCliResponse) => { - if (!wpCliResponse.stdout.match(new RegExp(featureName, 'g'))) { - cy.wpCli(`elasticpress activate-feature ${featureName}`); - } - }); + cy.wpCli(`elasticpress activate-feature ${featureName}`, true); }); Cypress.Commands.add('maybeDisableFeature', (featureName) => { - cy.wpCli('elasticpress list-features').then((wpCliResponse) => { - if (wpCliResponse.stdout.match(new RegExp(featureName, 'g'))) { - cy.wpCli(`elasticpress deactivate-feature ${featureName}`); - } - }); + cy.wpCli(`elasticpress deactivate-feature ${featureName}`, true); }); Cypress.Commands.add('getTotal', (totalNumber) => { From 23d85a96aa7c6e5ce98d65632366941412042536 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 19:50:23 -0300 Subject: [PATCH 17/20] Optimize WooCommerce e2e tests --- .../integration/features/woocommerce.cy.js | 303 +++++++++--------- 1 file changed, 144 insertions(+), 159 deletions(-) diff --git a/tests/cypress/integration/features/woocommerce.cy.js b/tests/cypress/integration/features/woocommerce.cy.js index 64668e18f4..438c268467 100644 --- a/tests/cypress/integration/features/woocommerce.cy.js +++ b/tests/cypress/integration/features/woocommerce.cy.js @@ -50,48 +50,7 @@ describe('WooCommerce Feature', () => { cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'woocommerce'); }); - it('Can fetch orders from Elasticsearch', () => { - cy.login(); - - cy.maybeEnableFeature('protected_content'); - cy.maybeEnableFeature('woocommerce'); - - // this is required to sync the orders to Elasticsearch. - cy.wpCli('elasticpress index --setup --yes'); - - cy.visitAdminPage('edit.php?post_type=shop_order'); - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( - 'contain.text', - 'Query Response Code: HTTP 200', - ); - }); - - it('Can fetch products from Elasticsearch in WP Dashboard', () => { - cy.login(); - - cy.maybeEnableFeature('protected_content'); - cy.maybeEnableFeature('woocommerce'); - - cy.visitAdminPage('edit.php?post_type=product'); - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( - 'contain.text', - 'Query Response Code: HTTP 200', - ); - }); - - it('Can fetch products from Elasticsearch in product category archives', () => { - cy.login(); - - cy.maybeEnableFeature('woocommerce'); - - cy.visit('/product-category/uncategorized'); - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( - 'contain.text', - 'Query Response Code: HTTP 200', - ); - }); - - it('Can fetch products from Elasticsearch in product rivers', () => { + it('Can fetch products from Elasticsearch in product rivers and category archives', () => { cy.login(); cy.maybeEnableFeature('woocommerce'); @@ -101,128 +60,12 @@ describe('WooCommerce Feature', () => { 'contain.text', 'Query Response Code: HTTP 200', ); - }); - - it('Can not display other users orders on the My Account Order page', () => { - cy.login(); - - cy.activatePlugin('woocommerce'); - cy.activatePlugin('enable-debug-bar'); - - cy.maybeEnableFeature('protected_content'); - cy.maybeEnableFeature('woocommerce'); - - // enable payment gateway. - cy.visitAdminPage('admin.php?page=wc-settings&tab=checkout§ion=cod'); - cy.get('#woocommerce_cod_enabled').check(); - cy.get('.button-primary.woocommerce-save-button').click(); - - cy.logout(); - - // create new user. - cy.createUser({ - username: userData.username, - email: userData.email, - login: true, - }); - - // add product to cart. - cy.visit('product/fantastic-silk-knife'); - cy.get('.single_add_to_cart_button').click(); - - // checkout and place order. - cy.visit('checkout'); - cy.get('#billing_first_name').type(userData.firstName); - cy.get('#billing_last_name').type(userData.lastName); - cy.get('#billing_address_1').type(userData.address); - cy.get('#billing_city').type(userData.city); - cy.get('#billing_postcode').type(userData.postCode); - cy.get('#billing_phone').type(userData.phoneNumber); - cy.get('#place_order').click(); - - // ensure order is placed. - cy.url().should('include', '/checkout/order-received'); - - /** - * Give Elasticsearch some time to process the new posts. - * - */ - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - - // ensure order is visible to user. - cy.visit('my-account/orders'); - cy.get('.woocommerce-orders-table tbody tr').should('have.length', 1); - - // Test orderby parameter set to `date` in query. - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug') - .should('contain.text', 'shop_order') - .should('contain.text', "'orderby' => 'date'"); - - cy.logout(); - - cy.createUser({ - username: 'buyer', - email: 'buyer@example.com', - login: true, - }); - - // ensure no order is show. - cy.visit('my-account/orders'); - cy.get('.woocommerce-orders-table tbody tr').should('have.length', 0); - - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug') - .should('contain.text', 'shop_order') - .should('contain.text', 'Query Response Code: HTTP 200'); - }); - - it('Can search orders from ElasticPress in WP Dashboard', () => { - cy.login(); - - cy.activatePlugin('woocommerce'); - cy.maybeEnableFeature('protected_content'); - cy.maybeEnableFeature('woocommerce'); - - cy.visitAdminPage('edit.php?post_type=shop_order'); - - // search order by user's name. - cy.get('#post-search-input') - .clear() - .type(`${userData.firstName} ${userData.lastName}{enter}`); - - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( - 'contain.text', - 'Query Response Code: HTTP 200', - ); - - cy.get('.order_number .order-view').should( - 'contain.text', - `${userData.firstName} ${userData.lastName}`, - ); - - // search order by user's address. - cy.get('#post-search-input').clear().type(`${userData.address}{enter}`); - cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( - 'contain.text', - 'Query Response Code: HTTP 200', - ); - - cy.get('.order_number .order-view').should( - 'contain.text', - `${userData.firstName} ${userData.lastName}`, - ); - // search order by product. - cy.get('#post-search-input').clear().type(`fantastic-silk-knife{enter}`); + cy.visit('/product-category/uncategorized'); cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( 'contain.text', 'Query Response Code: HTTP 200', ); - - cy.get('.order_number .order-view').should( - 'contain.text', - `${userData.firstName} ${userData.lastName}`, - ); }); it('Can Search Product by Variation SKU', () => { @@ -253,4 +96,146 @@ describe('WooCommerce Feature', () => { }); }); }); + + context('Dashboard', () => { + before(() => { + cy.login(); + cy.maybeEnableFeature('protected_content'); + cy.maybeEnableFeature('woocommerce'); + cy.activatePlugin('woocommerce'); + }); + + it('Can fetch orders and products from Elasticsearch', () => { + /** + * Orders + */ + // this is required to sync the orders to Elasticsearch. + cy.wpCli('elasticpress index --setup --yes'); + + cy.visitAdminPage('edit.php?post_type=shop_order'); + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + + /** + * Products + */ + cy.visitAdminPage('edit.php?post_type=product'); + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + }); + + it('Can not display other users orders on the My Account Order page', () => { + cy.activatePlugin('enable-debug-bar'); + + // enable payment gateway. + cy.visitAdminPage('admin.php?page=wc-settings&tab=checkout§ion=cod'); + cy.get('#woocommerce_cod_enabled').check(); + cy.get('.button-primary.woocommerce-save-button').click(); + + cy.logout(); + + // create new user. + cy.createUser({ + username: userData.username, + email: userData.email, + login: true, + }); + + // add product to cart. + cy.visit('product/fantastic-silk-knife'); + cy.get('.single_add_to_cart_button').click(); + + // checkout and place order. + cy.visit('checkout'); + cy.get('#billing_first_name').type(userData.firstName); + cy.get('#billing_last_name').type(userData.lastName); + cy.get('#billing_address_1').type(userData.address); + cy.get('#billing_city').type(userData.city); + cy.get('#billing_postcode').type(userData.postCode); + cy.get('#billing_phone').type(userData.phoneNumber); + cy.get('#place_order').click(); + + // ensure order is placed. + cy.url().should('include', '/checkout/order-received'); + + /** + * Give Elasticsearch some time to process the new posts. + * + */ + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + + // ensure order is visible to user. + cy.visit('my-account/orders'); + cy.get('.woocommerce-orders-table tbody tr').should('have.length', 1); + + // Test orderby parameter set to `date` in query. + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug') + .should('contain.text', 'shop_order') + .should('contain.text', "'orderby' => 'date'"); + + cy.logout(); + + cy.createUser({ + username: 'buyer', + email: 'buyer@example.com', + login: true, + }); + + // ensure no order is show. + cy.visit('my-account/orders'); + cy.get('.woocommerce-orders-table tbody tr').should('have.length', 0); + + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug') + .should('contain.text', 'shop_order') + .should('contain.text', 'Query Response Code: HTTP 200'); + }); + + it('Can search orders from ElasticPress in WP Dashboard', () => { + cy.visitAdminPage('edit.php?post_type=shop_order'); + + // search order by user's name. + cy.get('#post-search-input') + .clear() + .type(`${userData.firstName} ${userData.lastName}{enter}`); + + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + + cy.get('.order_number .order-view').should( + 'contain.text', + `${userData.firstName} ${userData.lastName}`, + ); + + // search order by user's address. + cy.get('#post-search-input').clear().type(`${userData.address}{enter}`); + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + + cy.get('.order_number .order-view').should( + 'contain.text', + `${userData.firstName} ${userData.lastName}`, + ); + + // search order by product. + cy.get('#post-search-input').clear().type(`fantastic-silk-knife{enter}`); + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + + cy.get('.order_number .order-view').should( + 'contain.text', + `${userData.firstName} ${userData.lastName}`, + ); + }); + }); }); From 78763dc2df13cf673ce3e11f43cf9b9ff55202c9 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 19 Oct 2022 19:58:57 -0300 Subject: [PATCH 18/20] Remove log file tests --- tests/cypress/integration/features/custom-results.cy.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/cypress/integration/features/custom-results.cy.js b/tests/cypress/integration/features/custom-results.cy.js index 943dc67fcc..534bb21e9a 100644 --- a/tests/cypress/integration/features/custom-results.cy.js +++ b/tests/cypress/integration/features/custom-results.cy.js @@ -50,10 +50,6 @@ describe('Custom Results', () => { // verify the result of the search is in the same position. cy.get(`article:nth-child(-n+${searchResult.length}) .entry-title`).each( (post, index) => { - cy.writeFile( - `tests/cypress/logs/testing-${index}.log`, - post[0].innerText, - ); expect(post[0].innerText).to.equal(searchResult[index]); }, ); @@ -99,7 +95,6 @@ describe('Custom Results', () => { // verify the result of the search is in the same position. cy.get(`article:nth-child(-n+${searchResult.length}) .entry-title`).each( (post, index) => { - cy.writeFile(`tests/cypress/logs/testing-${index}.log`, post[0].innerText); expect(post[0].innerText).to.equal(searchResult[index]); }, ); From f8f349a090540e9bbcf3cce8d52a1a29dad959bd Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 20 Oct 2022 08:59:06 -0300 Subject: [PATCH 19/20] Only get the first page --- tests/cypress/integration/features/custom-results.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/integration/features/custom-results.cy.js b/tests/cypress/integration/features/custom-results.cy.js index 534bb21e9a..ba2efa84d7 100644 --- a/tests/cypress/integration/features/custom-results.cy.js +++ b/tests/cypress/integration/features/custom-results.cy.js @@ -82,7 +82,7 @@ describe('Custom Results', () => { // save the posts positions in a list // eslint-disable-next-line jest/valid-expect-in-promise - cy.get('.pointers .pointer .title') + cy.get('.pointers .pointer:nth-child(-n+5) .title') // 5 being the number of posts per page, as we will check only the first page. .each((post) => { searchResult.push(post[0].innerText); }) From 8236727c4a804572c701ea653c3d4acc9cca1d6b Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 20 Oct 2022 09:58:56 -0300 Subject: [PATCH 20/20] Refresh specific index Otherwise it fails in EP.io --- tests/cypress/integration/features/comments.cy.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/cypress/integration/features/comments.cy.js b/tests/cypress/integration/features/comments.cy.js index 36508f9cd0..eeed4bc2ce 100644 --- a/tests/cypress/integration/features/comments.cy.js +++ b/tests/cypress/integration/features/comments.cy.js @@ -107,7 +107,11 @@ describe('Comments Feature', () => { cy.get('#submit').click(); // Check if the new comment was indexed - cy.wpCliEval('\\ElasticPress\\Elasticsearch::factory()->refresh_indices();').then(() => { + cy.wpCliEval( + ` + $comments_index = \\ElasticPress\\Indexables::factory()->get( "comment" )->get_index_name(); + WP_CLI::runcommand("elasticpress request {$comments_index}/_refresh --method=POST");`, + ).then(() => { cy.wpCli('wp elasticpress stats') .its('stdout') .should('contain', `Documents: ${defaultApprovedComments + 1}`); @@ -142,7 +146,11 @@ describe('Comments Feature', () => { cy.get('#comment').type('This is a anonymous comment'); cy.get('#submit').click(); - cy.wpCliEval('\\ElasticPress\\Elasticsearch::factory()->refresh_indices();').then(() => { + cy.wpCliEval( + ` + $comments_index = \\ElasticPress\\Indexables::factory()->get( "comment" )->get_index_name(); + WP_CLI::runcommand("elasticpress request {$comments_index}/_refresh --method=POST");`, + ).then(() => { cy.wpCli('wp elasticpress stats') .its('stdout') .should('contain', `Documents: ${defaultApprovedComments + 1}`);