diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml index 71b683ff66..c21283c14d 100644 --- a/.github/workflows/cypress-tests.yml +++ b/.github/workflows/cypress-tests.yml @@ -14,6 +14,7 @@ on: pull_request: branches: - develop + - '[0-9].[0-9x]*' # Version branches: 4.x.x, 4.1.x, 5.x jobs: cypress_local: diff --git a/bin/setup-cypress-env.sh b/bin/setup-cypress-env.sh index 436a793f79..59df0a096f 100755 --- a/bin/setup-cypress-env.sh +++ b/bin/setup-cypress-env.sh @@ -60,8 +60,10 @@ if [ ! -z $EP_INDEX_PREFIX ]; then fi npm run env run tests-cli "wp core multisite-convert" -npm run env run tests-cli "wp user create wpsnapshots wpsnapshots@example.test --role=administrator --user_pass=password" -npm run env run tests-cli "wp super-admin add wpsnapshots" + +# Not sure why, wp-env makes it http://localhost:8889/:8889 +npm run env run tests-cli "option set home 'http://localhost:8889'" +npm run env run tests-cli "option set siteurl 'http://localhost:8889'" npm run env run tests-cli "wp theme enable twentytwentyone --network --activate" @@ -76,7 +78,7 @@ npm run env run tests-cli "wp plugin activate ${PLUGIN_NAME}" npm run env run tests-cli "wp elasticpress index --setup --yes --show-errors" npm run env run tests-cli "wp option set posts_per_page 5" -npm run env run tests-cli "wp user meta update wpsnapshots edit_post_per_page 5" +npm run env run tests-cli "wp user meta update admin edit_post_per_page 5" # Generate a SQL file that can be imported later to make things faster SQL_FILENAME=./bin/$(date +'%F-%H-%M').sql diff --git a/includes/classes/Command.php b/includes/classes/Command.php index e676ca2dea..507eb23add 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -918,7 +918,7 @@ private function connect_check() { */ private function index_occurring() { if ( Utils\is_indexing() ) { - WP_CLI::error( esc_html__( 'An index is already occuring. Try again later.', 'elasticpress' ) ); + WP_CLI::error( esc_html__( 'An index is already occurring. Try again later.', 'elasticpress' ) ); } } diff --git a/tests/cypress/integration/dashboard-sync.spec.js b/tests/cypress/integration/dashboard-sync.spec.js index abdb7f833b..c28d7daba3 100644 --- a/tests/cypress/integration/dashboard-sync.spec.js +++ b/tests/cypress/integration/dashboard-sync.spec.js @@ -18,11 +18,10 @@ describe('Dashboard Sync', () => { } function resumeAndWait() { - cy.get('.resume-sync').click(); - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.get('.ep-delete-data-and-sync .resume-sync').click(); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); } before(() => { @@ -33,23 +32,15 @@ describe('Dashboard Sync', () => { if (cy.state('test').state === 'failed') { cy.deactivatePlugin('elasticpress', 'wpCli', 'network'); cy.wpCli('wp elasticpress clear-index', true); - cy.visitAdminPage('admin.php?page=elasticpress-settings'); - cy.get('body').then(($body) => { - const $cancelSyncButton = $body.find('.cancel-sync'); - if ($cancelSyncButton.length) { - $cancelSyncButton.click(); - } - }); } }); it('Can index content and see indexes names in the Health Screen', () => { - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.start-sync').click(); - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); canSeeIndexesNames(); }); @@ -63,12 +54,11 @@ describe('Dashboard Sync', () => { 'We could not find any data for your Elasticsearch indices.', ); - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.start-sync').click(); - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); cy.visitAdminPage('admin.php?page=elasticpress-health'); cy.get('.wrap').should( @@ -94,12 +84,11 @@ describe('Dashboard Sync', () => { 'We could not find any data for your Elasticsearch indices.', ); - cy.visitAdminPage('network/admin.php?page=elasticpress'); - cy.get('.start-sync').click(); - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.visitAdminPage('network/admin.php?page=elasticpress-sync'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); cy.visitAdminPage('network/admin.php?page=elasticpress-health'); cy.get('.wrap').should( @@ -126,19 +115,22 @@ describe('Dashboard Sync', () => { }); it('Can pause the dashboard sync if left the page', () => { - setPerIndexCycle(10); + setPerIndexCycle(20); - cy.visitAdminPage('admin.php?page=elasticpress'); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.intercept('POST', '/wp-admin/admin-ajax.php').as('ajaxRequest'); - cy.get('.start-sync').click(); + cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - cy.get('.pause-sync').should('be.visible'); + cy.get('.ep-delete-data-and-sync .pause-sync').should('be.visible'); cy.visitAdminPage('index.php'); - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.sync-status').should('contain.text', 'Sync paused'); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info').should( + 'contain.text', + 'Sync in progress', + ); resumeAndWait(); @@ -148,39 +140,42 @@ describe('Dashboard Sync', () => { }); it("Can't activate features during a sync", () => { - setPerIndexCycle(10); + setPerIndexCycle(20); - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.intercept('POST', '/wp-admin/admin-ajax.php').as('ajaxRequest'); - cy.get('.start-sync').click(); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - cy.get('.pause-sync').should('be.visible'); - cy.get('.pause-sync').click(); + cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.error-overlay').should('have.class', 'syncing'); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); resumeAndWait(); + + cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.error-overlay').should('not.have.class', 'syncing'); setPerIndexCycle(); }); it("Can't index via WP-CLI if indexing via Dashboard", () => { - setPerIndexCycle(10); + setPerIndexCycle(20); - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.intercept('POST', '/wp-admin/admin-ajax.php').as('ajaxRequest'); - cy.get('.start-sync').click(); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); + cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); + cy.get('.ep-delete-data-and-sync__button-delete').click(); cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - cy.get('.pause-sync').should('be.visible'); - cy.get('.pause-sync').click(); + cy.get('.ep-delete-data-and-sync .pause-sync').should('be.visible'); + cy.get('.ep-delete-data-and-sync .pause-sync').click(); cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); cy.wpCli('wp elasticpress index', true) .its('stderr') .should('contain', 'An index is already occurring'); + cy.visitAdminPage('admin.php?page=elasticpress-sync'); resumeAndWait(); setPerIndexCycle(); diff --git a/tests/cypress/integration/features/autosuggest.spec.js b/tests/cypress/integration/features/autosuggest.spec.js index 48112f0f07..1fdaaec97a 100644 --- a/tests/cypress/integration/features/autosuggest.spec.js +++ b/tests/cypress/integration/features/autosuggest.spec.js @@ -17,7 +17,7 @@ describe('Autosuggest Feature', () => { cy.get('.ep-autosuggest').should(($autosuggestList) => { // eslint-disable-next-line no-unused-expressions expect($autosuggestList).to.be.visible; - expect($autosuggestList[0].innerText).to.be.eq('Markup: HTML Tags and Formatting'); + expect($autosuggestList[0].innerText).to.contains('Markup: HTML Tags and Formatting'); }); }); diff --git a/tests/cypress/integration/features/documents.spec.js b/tests/cypress/integration/features/documents.spec.js index ba0bbf0b63..ccb72c4608 100644 --- a/tests/cypress/integration/features/documents.spec.js +++ b/tests/cypress/integration/features/documents.spec.js @@ -2,8 +2,8 @@ describe('Documents Feature', () => { function enableDocumentsFeature() { cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-documents .settings-button').click(); - cy.get('#feature_active_documents_enabled').click(); - cy.get('a.save-settings[data-feature="documents"]').click(); + cy.get('.ep-feature-documents [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-documents .button-primary').click(); } function uploadFile(fileName, mimeType) { diff --git a/tests/cypress/integration/features/protected-content.spec.js b/tests/cypress/integration/features/protected-content.spec.js index 593987706d..9f5e88437b 100644 --- a/tests/cypress/integration/features/protected-content.spec.js +++ b/tests/cypress/integration/features/protected-content.spec.js @@ -4,16 +4,15 @@ describe('Protected Content Feature', () => { cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-protected_content .settings-button').click(); - cy.get('#feature_active_protected_content_enabled').click(); - cy.get('a.save-settings[data-feature="protected_content"]').click(); + cy.get('.ep-feature-protected_content [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-protected_content .button-primary').click(); cy.on('window:confirm', () => { return true; }); - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'protected_content'); }); diff --git a/tests/cypress/integration/features/related-posts.spec.js b/tests/cypress/integration/features/related-posts.spec.js index f0a75f14f5..d129193f99 100644 --- a/tests/cypress/integration/features/related-posts.spec.js +++ b/tests/cypress/integration/features/related-posts.spec.js @@ -17,8 +17,8 @@ describe('Related Posts Feature', () => { // Disable the feature. cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-related_posts .settings-button').click(); - cy.get('#feature_active_related_posts_disabled').click(); - cy.get('a.save-settings[data-feature="related_posts"]').click(); + cy.get('.ep-feature-related_posts [name="settings[active]"][value="0"]').click(); + cy.get('.ep-feature-related_posts .button-primary').click(); openWidgetsPage(); @@ -30,8 +30,8 @@ describe('Related Posts Feature', () => { // Re-enable the feature. cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-related_posts .settings-button').click(); - cy.get('#feature_active_related_posts_enabled').click(); - cy.get('a.save-settings[data-feature="related_posts"]').click(); + cy.get('.ep-feature-related_posts [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-related_posts .button-primary').click(); openWidgetsPage(); diff --git a/tests/cypress/integration/features/search/search.spec.js b/tests/cypress/integration/features/search/search.spec.js index e95ecee342..90db47c8e6 100644 --- a/tests/cypress/integration/features/search/search.spec.js +++ b/tests/cypress/integration/features/search/search.spec.js @@ -44,6 +44,9 @@ describe('Post Search Feature', () => { it('Can see newer matches showing higher', () => { cy.login(); + const attempt = Cypress._.get(cy.state('runnable'), '_currentRetry', 0); + const postTitle = `Duplicated post Attempt #${attempt}`; + /** * Given the fact that score will only decay for posts older than 7 days by default, we * create two posts with 1 month of difference. Using WP-CLI here to make it easier to set a date. @@ -64,7 +67,7 @@ describe('Post Search Feature', () => { .toLocaleString('en-CA', dateFormat) .replace(',', ''); cy.wpCli( - `post create --post_title='Duplicated post' --post_content='10up loves elasticpress' --post_author=1 --post_status='publish' --post_date='${oneMonthAgo}'`, + `post create --post_title='${postTitle}' --post_content='Lorem ipsum veritas dolor ${attempt}' --post_author=1 --post_status='publish' --post_date='${oneMonthAgo}'`, ); // To avoid any problems with timezones, let's just create it as yesterday. @@ -72,7 +75,7 @@ describe('Post Search Feature', () => { .toLocaleString('en-CA', dateFormat) .replace(',', ''); cy.wpCli( - `post create --post_title='Duplicated post' --post_content='10up loves elasticpress' --post_author=1 --post_status='publish' --post_date='${yesterday}'`, + `post create --post_title='${postTitle}' --post_content='Lorem ipsum veritas dolor ${attempt}' --post_author=1 --post_status='publish' --post_date='${yesterday}'`, ); /** @@ -83,9 +86,9 @@ describe('Post Search Feature', () => { // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(2000); - cy.visit('/?s=duplicated+post'); - cy.contains('.site-content article:nth-of-type(1) h2', 'Duplicated post').should('exist'); - cy.contains('.site-content article:nth-of-type(2) h2', 'Duplicated post').should('exist'); + cy.visit(`/?s=duplicated+post+attempt+${attempt}`); + cy.contains('.site-content article:nth-of-type(1) h2', postTitle).should('exist'); + cy.contains('.site-content article:nth-of-type(2) h2', postTitle).should('exist'); // Comparing post IDs but the HTML id generated by the theme. cy.get('.site-content article:nth-of-type(1)') @@ -105,8 +108,8 @@ describe('Post Search Feature', () => { cy.login(); cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-search .settings-button').click(); - cy.get('#highlighting_enabled').click(); - cy.get('a.save-settings[data-feature="search"]').click(); + cy.get('.ep-feature-search [name="settings[highlight_excerpt]"][value="1"]').click(); + cy.get('.ep-feature-search .button-primary').click(); cy.publishPost({ title: 'test highlight color', diff --git a/tests/cypress/integration/features/woocommerce.spec.js b/tests/cypress/integration/features/woocommerce.spec.js index ac1088768b..4a6b85296d 100644 --- a/tests/cypress/integration/features/woocommerce.spec.js +++ b/tests/cypress/integration/features/woocommerce.spec.js @@ -19,16 +19,15 @@ describe('WooCommerce Feature', () => { cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-woocommerce .settings-button').click(); - cy.get('#feature_active_woocommerce_enabled').click(); - cy.get('a.save-settings[data-feature="woocommerce"]').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('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'woocommerce'); }); diff --git a/tests/cypress/integration/indexables/user.spec.js b/tests/cypress/integration/indexables/user.spec.js index 96fd931c3c..1e33486084 100644 --- a/tests/cypress/integration/indexables/user.spec.js +++ b/tests/cypress/integration/indexables/user.spec.js @@ -38,17 +38,15 @@ describe('User Indexable', () => { cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-users .settings-button').click(); - cy.get('#feature_active_users_enabled').click(); - cy.get('a.save-settings[data-feature="users"]').click(); + cy.get('.ep-feature-users [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-users .button-primary').click(); cy.on('window:confirm', () => { return true; }); - // Give it up to a minute to sync. - cy.get('.sync-status', { timeout: Cypress.config('elasticPressIndexTimeout') }).should( - 'contain.text', - 'Sync complete', - ); + cy.get('.ep-delete-data-and-sync .ep-sync-box__progress-info', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync completed'); cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'users'); }); diff --git a/tests/cypress/integration/wp-cli.spec.js b/tests/cypress/integration/wp-cli.spec.js index cc282dc468..29316cc4dc 100644 --- a/tests/cypress/integration/wp-cli.spec.js +++ b/tests/cypress/integration/wp-cli.spec.js @@ -54,8 +54,8 @@ describe('WP-CLI Commands', () => { cy.wpCli('wp elasticpress index --per-page=20') .its('stdout') .should('contain', 'Indexing posts') - .should('contain', 'Processed 20/') - .should('contain', 'Processed 40/') + .should('contain', '20 of') + .should('contain', '40 of') .should('contain', 'Number of posts indexed'); }); @@ -63,10 +63,10 @@ describe('WP-CLI Commands', () => { cy.wpCli('wp elasticpress index --nobulk') .its('stdout') .should('contain', 'Indexing posts') - .should('contain', 'Processed 1/') - .should('contain', 'Processed 2/') - .should('contain', 'Processed 3/') - .should('contain', 'Processed 4/') + .should('contain', '1 of') + .should('contain', '2 of') + .should('contain', '3 of') + .should('contain', '4 of') .should('contain', 'Number of posts indexed'); }); @@ -74,8 +74,9 @@ describe('WP-CLI Commands', () => { // eslint-disable-next-line jest/valid-expect-in-promise cy.wpCli('wp elasticpress index --offset=10').then((wpCliResponse) => { expect(wpCliResponse.stdout).to.contains('Indexing posts'); + expect(wpCliResponse.stdout).to.contains('Skipping 10'); - const match1 = wpCliResponse.stdout.match(/Processed (\d+)\/(?\d+)./); + const match1 = wpCliResponse.stdout.match(/(\d+) of (?\d+)./); const match2 = wpCliResponse.stdout.match( /Number of posts indexed: (?\d+)/, ); diff --git a/tests/cypress/plugins/index.js b/tests/cypress/plugins/index.js index 2a4100bf8d..0669859dc8 100644 --- a/tests/cypress/plugins/index.js +++ b/tests/cypress/plugins/index.js @@ -15,6 +15,8 @@ const { readConfig } = require('@wordpress/env/lib/config'); /** + * Dynamically set some configs. + * * @type {Cypress.PluginConfig} */ // eslint-disable-next-line no-unused-vars diff --git a/tests/cypress/wordpress-files/test-docs/content-example.xml b/tests/cypress/wordpress-files/test-docs/content-example.xml index 1e84472061..0028ee0e64 100644 --- a/tests/cypress/wordpress-files/test-docs/content-example.xml +++ b/tests/cypress/wordpress-files/test-docs/content-example.xml @@ -36,7 +36,7 @@ http://ep-wpa-snapshot.test 1 - 12 + 12 1 @@ -3871,7 +3871,7 @@ woocommerce-placeholder http://ep-wpa-snapshot.test/woocommerce-placeholder/ Fri, 17 Apr 2020 06:01:55 +0000 - + http://ep-wpa-snapshot.test/wp-content/uploads/2020/04/woocommerce-placeholder.png @@ -4827,7 +4827,7 @@ http://ep-wpa-snapshot.test/?post_type=ep-synonym&p=2002 - + http://ep-wpa-snapshot.test/?post_type=ep-synonym&p=2002 Test http://ep-wpa-snapshot.test/?p=1996 Wed, 17 Feb 2021 15:43:13 +0000 - + http://ep-wpa-snapshot.test/?p=1996 @@ -14509,7 +14509,7 @@ Officia odio sint et veritatis consequatur ut. Ut numquam aspernatur consequatur Test http://ep-wpa-snapshot.test/blog/2021/02/17/test/ Wed, 17 Feb 2021 15:43:57 +0000 - + http://ep-wpa-snapshot.test/?p=1998 @@ -14532,7 +14532,7 @@ Officia odio sint et veritatis consequatur ut. Ut numquam aspernatur consequatur Test 2 http://ep-wpa-snapshot.test/blog/2021/02/17/test-2/ Wed, 17 Feb 2021 15:47:35 +0000 - + http://ep-wpa-snapshot.test/?p=2000 @@ -32477,7 +32477,7 @@ Incidunt repellendus voluptatem laudantium et aut delectus rem. Et velit ullam o - + @@ -32517,7 +32517,7 @@ Incidunt repellendus voluptatem laudantium et aut delectus rem. Et velit ullam o - +