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') }} 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..1b34308ecd --- /dev/null +++ b/tests/cypress/config.js @@ -0,0 +1,38 @@ +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, + e2e: { + 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) { + 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(); + + return config; + }, + specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}', + supportFile: 'tests/cypress/support/index.js', + }, +}); 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 99% rename from tests/cypress/integration/dashboard-sync.spec.js rename to tests/cypress/integration/dashboard-sync.cy.js index ade809e279..e36741cfc6 100644 --- a/tests/cypress/integration/dashboard-sync.spec.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/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 69% rename from tests/cypress/integration/features/comments.spec.js rename to tests/cypress/integration/features/comments.cy.js index cc004e5788..eeed4bc2ce 100644 --- a/tests/cypress/integration/features/comments.spec.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,16 @@ 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.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}`); + }); // trash the review cy.visitAdminPage( @@ -152,16 +146,15 @@ 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.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}`); + }); // trash the comment cy.visitAdminPage('edit-comments.php?comment_status=approved'); diff --git a/tests/cypress/integration/features/custom-results.spec.js b/tests/cypress/integration/features/custom-results.cy.js similarity index 63% rename from tests/cypress/integration/features/custom-results.spec.js rename to tests/cypress/integration/features/custom-results.cy.js index d572f72892..ba2efa84d7 100644 --- a/tests/cypress/integration/features/custom-results.spec.js +++ b/tests/cypress/integration/features/custom-results.cy.js @@ -31,24 +31,29 @@ 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) => { + expect(post[0].innerText).to.equal(searchResult[index]); + }, + ); + }); }); }); @@ -76,21 +81,23 @@ 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.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); - cy.get('#publish').click(); - cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - - 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: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); + }) + .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) => { + expect(post[0].innerText).to.equal(searchResult[index]); + }, + ); + }); }); }); 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 84% rename from tests/cypress/integration/features/search/weighting.spec.js rename to tests/cypress/integration/features/search/weighting.cy.js index d93dbf5d7d..ac6157523c 100644 --- a/tests/cypress/integration/features/search/weighting.spec.js +++ b/tests/cypress/integration/features/search/weighting.cy.js @@ -2,23 +2,25 @@ describe('Post Search Feature - Weighting Functionality', () => { 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', + 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').click(); + cy.get('#post-post_title-enabled').uncheck(); cy.get('#submit').click(); - cy.visit('/?s=Test+ElasticPress+1'); + cy.visit('/?s=supercustomtitle'); cy.get('.hentry').should('not.exist'); // 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(); }); 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.cy.js b/tests/cypress/integration/features/woocommerce.cy.js new file mode 100644 index 0000000000..438c268467 --- /dev/null +++ b/tests/cypress/integration/features/woocommerce.cy.js @@ -0,0 +1,241 @@ +describe('WooCommerce Feature', () => { + const userData = { + username: 'testuser', + email: 'testuser@example.com', + firstName: 'John', + lastName: 'Doe', + address: '123 Main St', + city: 'Culver City', + postCode: '90230', + phoneNumber: '1234567890', + }; + + before(() => { + cy.deactivatePlugin('woocommerce', 'wpCli'); + }); + + after(() => { + cy.deactivatePlugin('woocommerce', 'wpCli'); + }); + + it('Can auto-activate the feature', () => { + cy.login(); + + cy.activatePlugin('woocommerce'); + + cy.visitAdminPage('admin.php?page=elasticpress'); + cy.get('.ep-feature-woocommerce').should('have.class', 'feature-active'); + }); + + it('Can automatically start a sync if activate the feature', () => { + cy.login(); + + cy.maybeDisableFeature('woocommerce'); + + cy.visitAdminPage('admin.php?page=elasticpress'); + cy.get('.ep-feature-woocommerce .settings-button').click(); + cy.get('.ep-feature-woocommerce [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-woocommerce .button-primary').click(); + cy.on('window:confirm', () => { + return true; + }); + + cy.get('.ep-sync-panel').last().as('syncPanel'); + cy.get('@syncPanel').find('.components-form-toggle').click(); + cy.get('@syncPanel') + .find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') }) + .should('contain.text', 'Mapping sent') + .should('contain.text', 'Sync complete'); + + cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'woocommerce'); + }); + + it('Can fetch products from Elasticsearch in product rivers and category archives', () => { + cy.login(); + + cy.maybeEnableFeature('woocommerce'); + + cy.visit('/shop/?filter_size=small'); + cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( + 'contain.text', + 'Query Response Code: HTTP 200', + ); + + 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 Search Product by Variation SKU', () => { + cy.login(); + cy.activatePlugin('woocommerce', 'wpCli'); + cy.maybeEnableFeature('woocommerce'); + + cy.updateWeighting({ + product: { + 'meta._variations_skus.value': { + weight: 1, + enabled: true, + }, + }, + }).then(() => { + cy.wpCli('elasticpress index --setup --yes').then(() => { + /** + * Give Elasticsearch some time. Apparently, if the visit happens right after the index, it won't find anything. + * + */ + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(2000); + cy.visit('/?s=awesome-aluminum-shoes-variation-sku'); + cy.contains( + '.site-content article:nth-of-type(1) h2', + 'Awesome Aluminum Shoes', + ).should('exist'); + }); + }); + }); + + 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}`, + ); + }); + }); +}); diff --git a/tests/cypress/integration/features/woocommerce.spec.js b/tests/cypress/integration/features/woocommerce.spec.js deleted file mode 100644 index 64668e18f4..0000000000 --- a/tests/cypress/integration/features/woocommerce.spec.js +++ /dev/null @@ -1,256 +0,0 @@ -describe('WooCommerce Feature', () => { - const userData = { - username: 'testuser', - email: 'testuser@example.com', - firstName: 'John', - lastName: 'Doe', - address: '123 Main St', - city: 'Culver City', - postCode: '90230', - phoneNumber: '1234567890', - }; - - before(() => { - cy.deactivatePlugin('woocommerce', 'wpCli'); - }); - - after(() => { - cy.deactivatePlugin('woocommerce', 'wpCli'); - }); - - it('Can auto-activate the feature', () => { - cy.login(); - - cy.activatePlugin('woocommerce'); - - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.ep-feature-woocommerce').should('have.class', 'feature-active'); - }); - - it('Can automatically start a sync if activate the feature', () => { - cy.login(); - - cy.maybeDisableFeature('woocommerce'); - - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.ep-feature-woocommerce .settings-button').click(); - cy.get('.ep-feature-woocommerce [name="settings[active]"][value="1"]').click(); - cy.get('.ep-feature-woocommerce .button-primary').click(); - cy.on('window:confirm', () => { - return true; - }); - - cy.get('.ep-sync-panel').last().as('syncPanel'); - cy.get('@syncPanel').find('.components-form-toggle').click(); - cy.get('@syncPanel') - .find('.ep-sync-messages', { timeout: Cypress.config('elasticPressIndexTimeout') }) - .should('contain.text', 'Mapping sent') - .should('contain.text', 'Sync complete'); - - 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', () => { - cy.login(); - - cy.maybeEnableFeature('woocommerce'); - - cy.visit('/shop/?filter_size=small'); - 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.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.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', () => { - cy.login(); - cy.activatePlugin('woocommerce', 'wpCli'); - cy.maybeEnableFeature('woocommerce'); - - cy.updateWeighting({ - product: { - 'meta._variations_skus.value': { - weight: 1, - enabled: true, - }, - }, - }).then(() => { - cy.wpCli('elasticpress index --setup --yes').then(() => { - /** - * Give Elasticsearch some time. Apparently, if the visit happens right after the index, it won't find anything. - * - */ - // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.wait(2000); - cy.visit('/?s=awesome-aluminum-shoes-variation-sku'); - cy.contains( - '.site-content article:nth-of-type(1) h2', - 'Awesome Aluminum Shoes', - ).should('exist'); - }); - }); - }); -}); 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 99% rename from tests/cypress/integration/wp-cli.spec.js rename to tests/cypress/integration/wp-cli.cy.js index 93eb048e46..53feec7fbd 100644 --- a/tests/cypress/integration/wp-cli.spec.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', () => { 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; -}; 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) => {