From 2374d112bd964ee767da25f07f32ba779095f649 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 26 Oct 2022 16:35:43 -0300 Subject: [PATCH 1/9] Optimize some calls --- tests/cypress/support/commands.js | 15 +++++++++------ tests/cypress/support/global-hooks.js | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index ff3019ab7..0e716b4e7 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -122,7 +122,6 @@ Cypress.Commands.add('publishPost', (postData, viewPost) => { const welcomeGuide = $body.find( '.edit-post-welcome-guide .components-modal__header button', ); - cy.log(welcomeGuide); if (welcomeGuide.length) { welcomeGuide.click(); } @@ -324,12 +323,16 @@ Cypress.Commands.add('createClassicWidget', (widgetId, settings) => { }); Cypress.Commands.add('emptyWidgets', () => { - cy.wpCli('widget reset --all'); - cy.wpCli('widget list wp_inactive_widgets --format=ids').then((wpCliResponse) => { - if (wpCliResponse.stdout) { - cy.wpCli(`widget delete ${wpCliResponse.stdout}`); + cy.wpCliEval( + ` + WP_CLI::runcommand('widget reset --all'); + + $inactive_widgets = WP_CLI::runcommand('widget list wp_inactive_widgets --format=ids', [ 'return' => true ] ); + if ( $inactive_widgets ) { + WP_CLI::runcommand("widget delete {$inactive_widgets}" ); } - }); + `, + ); }); // Command to drag and drop React DnD element. Original code from: https://github.com/cypress-io/cypress/issues/3942#issuecomment-485648100 diff --git a/tests/cypress/support/global-hooks.js b/tests/cypress/support/global-hooks.js index 5af31d636..d36287f35 100644 --- a/tests/cypress/support/global-hooks.js +++ b/tests/cypress/support/global-hooks.js @@ -8,8 +8,10 @@ before(() => { \\ElasticPress\\IndexHelper::factory()->clear_index_meta(); $features = json_decode( '${JSON.stringify(cy.elasticPress.defaultFeatures)}', true ); - - if ( ! \\ElasticPress\\Utils\\is_epio() ) { + + $is_epio = (int) \\ElasticPress\\Utils\\is_epio(); + + if ( ! $is_epio ) { $host = \\ElasticPress\\Utils\\get_host(); $host = str_replace( '172.17.0.1', 'localhost', $host ); $index_name = \\ElasticPress\\Indexables::factory()->get( 'post' )->get_index_name(); @@ -20,14 +22,14 @@ before(() => { update_option( 'ep_feature_settings', $features ); - WP_CLI::runcommand('elasticpress get-indices'); + $index_names = WP_CLI::runcommand('elasticpress get-indices', [ 'return' => true ] ); + + echo wp_json_encode( [ 'indexNames' => $index_names, 'isEpIo' => $is_epio ] ); `, ).then((wpCliResponse) => { - window.indexNames = JSON.parse(wpCliResponse.stdout); - }); - - cy.wpCli('eval "echo (int) \\ElasticPress\\Utils\\is_epio();"').then((response) => { - window.isEpIo = response.stdout === '1'; + const wpCliRespObj = JSON.parse(wpCliResponse.stdout); + window.indexNames = wpCliRespObj.indexNames; + window.isEpIo = wpCliRespObj.isEpIo === '1'; }); }); From c16af4b8fe9def73132e7af744a735f7dd0bb8c5 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 26 Oct 2022 17:11:07 -0300 Subject: [PATCH 2/9] Optimize related-posts tests --- .../integration/features/related-posts.cy.js | 72 ++++++++++++------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/tests/cypress/integration/features/related-posts.cy.js b/tests/cypress/integration/features/related-posts.cy.js index aabadcf51..2e69433d3 100644 --- a/tests/cypress/integration/features/related-posts.cy.js +++ b/tests/cypress/integration/features/related-posts.cy.js @@ -13,13 +13,15 @@ describe('Related Posts Feature', () => { */ beforeEach(() => { cy.emptyWidgets(); - cy.deactivatePlugin('classic-widgets', 'wpCli'); - cy.wpCli('post list --s="Test related posts" --ep_integrate=false --format=ids').then( - (wpCliResponse) => { - if (wpCliResponse.stdout) { - cy.wpCli(`post delete ${wpCliResponse.stdout} --force`); - } - }, + cy.wpCliEval( + ` + WP_CLI::runcommand( 'plugin deactivate classic-widgets', [ 'return' => true ] ); + + $posts_ids = WP_CLI::runcommand( 'post list --s="Test related posts" --ep_integrate=false --format=ids', [ 'return' => true ] ); + if ( $posts_ids ) { + WP_CLI::runcommand( "post delete {$posts_ids} --force" ); + } + `, ); }); @@ -30,12 +32,24 @@ describe('Related Posts Feature', () => { /** * Create some posts that will be related. */ - for (let i = 0; i < 4; i++) { - cy.publishPost({ - title: `Test related posts block #${i + 1}`, - content: 'Inceptos tristique class ac eleifend leo.', - }); - } + cy.wpCliEval( + ` + for ( $i = 1; $i <= 4; $i++ ) { + wp_insert_post( + [ + 'post_title' => "Test related posts block #{$i}", + 'post_content' => 'Inceptos tristique class ac eleifend leo', + 'post_status' => 'publish', + ] + ); + } + `, + ); + + cy.publishPost({ + title: `Test related posts block #5`, + content: 'Inceptos tristique class ac eleifend leo.', + }); /** * On the last post insert a Related Posts block. @@ -116,17 +130,27 @@ describe('Related Posts Feature', () => { /** * Create some posts that will be related and view the last post. */ - for (let i = 0; i < 4; i++) { - const viewPost = i === 3; - - cy.publishPost( - { - title: `Test related posts widget #${i + 1}`, - content: 'Inceptos tristique class ac eleifend leo.', - }, - viewPost, - ); - } + cy.wpCliEval( + ` + for ( $i = 1; $i <= 2; $i++ ) { + wp_insert_post( + [ + 'post_title' => "Test related posts widget #{$i}", + 'post_content' => 'Inceptos tristique class ac eleifend leo', + 'post_status' => 'publish', + ] + ); + } + `, + ); + + cy.publishPost( + { + title: `Test related posts widget #3`, + content: 'Inceptos tristique class ac eleifend leo.', + }, + true, + ); /** * Verify the widget has the expected output on the front-end based on From ada3de4df2a6420c13efdcb032f3af216502f5cf Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 26 Oct 2022 17:16:20 -0300 Subject: [PATCH 3/9] Decode indices before using it --- tests/cypress/support/global-hooks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/support/global-hooks.js b/tests/cypress/support/global-hooks.js index d36287f35..21f5bf7ee 100644 --- a/tests/cypress/support/global-hooks.js +++ b/tests/cypress/support/global-hooks.js @@ -24,7 +24,7 @@ before(() => { $index_names = WP_CLI::runcommand('elasticpress get-indices', [ 'return' => true ] ); - echo wp_json_encode( [ 'indexNames' => $index_names, 'isEpIo' => $is_epio ] ); + echo wp_json_encode( [ 'indexNames' => json_decode( $index_names ), 'isEpIo' => $is_epio ] ); `, ).then((wpCliResponse) => { const wpCliRespObj = JSON.parse(wpCliResponse.stdout); From 205d2c3512f2d8836c466c305cbff44893516196 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 27 Oct 2022 08:49:45 -0300 Subject: [PATCH 4/9] Optimize Instant results e2e tests --- .../features/instant-results.cy.js | 295 +++++++++--------- 1 file changed, 148 insertions(+), 147 deletions(-) diff --git a/tests/cypress/integration/features/instant-results.cy.js b/tests/cypress/integration/features/instant-results.cy.js index e0a297846..0ceccf28a 100644 --- a/tests/cypress/integration/features/instant-results.cy.js +++ b/tests/cypress/integration/features/instant-results.cy.js @@ -16,13 +16,8 @@ describe('Instant Results Feature', () => { cy.wait('@sidebarsRest'); } - function maybeEnableProxy() { - if (!isEpIo) { - cy.activatePlugin('elasticpress-proxy'); - } - } - before(() => { + cy.login(); createSearchWidget(); // Create some sample posts @@ -37,9 +32,10 @@ describe('Instant Results Feature', () => { }); beforeEach(() => { - cy.deactivatePlugin('elasticpress-proxy'); - cy.deactivatePlugin('custom-instant-results-template', 'wpCli'); - cy.deactivatePlugin('open-instant-results-with-buttons', 'wpCli'); + cy.deactivatePlugin( + 'custom-instant-results-template open-instant-results-with-buttons', + 'wpCli', + ); }); /** @@ -50,8 +46,9 @@ describe('Instant Results Feature', () => { return; } - cy.login(); + // Make sure the proxy is deactivated. cy.deactivatePlugin('elasticpress-proxy'); + cy.visitAdminPage('admin.php?page=elasticpress'); cy.get('.ep-feature-instant-results .settings-button').click(); cy.get('.requirements-status-notice').should( @@ -61,154 +58,158 @@ describe('Instant Results Feature', () => { cy.get('.ep-feature-instant-results .input-wrap').should('have.class', 'disabled'); }); - /** - * Test that the feature can be activated and it can sync automatically. - * Also, it can show a warning when using a custom PHP proxy - */ - it('Can activate the feature and sync automatically', () => { - cy.login(); - - // Can see the warning if using custom proxy - maybeEnableProxy(); - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.ep-feature-instant-results .settings-button').click(); - - cy.get('.ep-feature-instant-results .input-wrap').should('not.have.class', 'disabled'); - cy.get('.requirements-status-notice').should( - isEpIo ? 'not.contain.text' : 'contain.text', - 'You are using a custom proxy. Make sure you implement all security measures needed', - ); - - cy.get('.ep-feature-instant-results [name="settings[active]"][value="1"]').click(); - cy.get('.ep-feature-instant-results .button-primary').click(); - cy.on('window:confirm', () => { - return true; + describe('Instant Results Available', () => { + before(() => { + if (!isEpIo) { + cy.activatePlugin('elasticpress-proxy'); + } }); - cy.get('.ep-sync-progress strong', { - timeout: Cypress.config('elasticPressIndexTimeout'), - }).should('contain.text', 'Sync complete'); - - cy.wpCli('elasticpress list-features').its('stdout').should('contain', 'instant-results'); - }); - - /** - * Test that the instant results list is visible - * It can display the number of test results - * It can show the modal in the same state after a reload - * Can change the URL when search term is changed - */ - it('Can see instant results elements, URL changes, reload, and update after changing search term', () => { - cy.login(); - - maybeEnableProxy(); - cy.maybeEnableFeature('instant-results'); - - cy.intercept('*search=blog*').as('apiRequest'); - - cy.visit('/'); - - cy.get('.wp-block-search').last().as('searchBlock'); - - cy.get('@searchBlock').find('.wp-block-search__input').type('blog'); - cy.get('@searchBlock').find('.wp-block-search__button').click(); - cy.get('.ep-search-modal').as('searchModal').should('be.visible'); // Should be visible immediatly - cy.url().should('include', 'search=blog'); - - cy.wait('@apiRequest'); - cy.get('@searchModal').should('contain.text', 'blog'); - // Show the number of results - cy.get('@searchModal').find('.ep-search-results__title').contains(/\d+/); - - cy.get('.ep-search-sidebar #ep-search-post-type-post') - .click() - .then(() => { - cy.url().should('include', 'ep-post_type=post'); - }); - - // Show the modal in the same state after a reload - cy.reload(); - cy.wait('@apiRequest'); - cy.get('@searchModal').should('be.visible').should('contain.text', 'blog'); - - // Update the results when search term is changed - cy.get('@searchModal') - .find('.ep-search-input') - .clearThenType('test') - .then(() => { - cy.wait('@apiRequest'); - cy.get('@searchModal').should('be.visible').should('contain.text', 'test'); - cy.url().should('include', 'search=test'); - }); - - cy.get('#wpadminbar li#wp-admin-bar-debug-bar').click(); - cy.get('#querylist').should('be.visible'); - }); - - it('Is possible to manually open Instant Results with a plugin', () => { /** - * Activate test plugin with JavaScript. + * Test that the feature can be activated and it can sync automatically. + * Also, it can show a warning when using a custom PHP proxy */ - maybeEnableProxy(); - cy.maybeEnableFeature('instant-results'); - cy.activatePlugin('open-instant-results-with-buttons', 'wpCli'); - - /** - * Create a post with a Buttons block. - */ - cy.publishPost({ - title: `Test openModal()`, - content: 'Testing openModal()', - }); - - cy.openBlockInserter(); - cy.insertBlock('Buttons'); - cy.get('.wp-block-button__link').type('Search "Block"'); + it('Can activate the feature and sync automatically', () => { + // Can see the warning if using custom proxy + cy.visitAdminPage('admin.php?page=elasticpress'); + cy.get('.ep-feature-instant-results .settings-button').click(); + + cy.get('.ep-feature-instant-results .input-wrap').should('not.have.class', 'disabled'); + cy.get('.requirements-status-notice').should( + isEpIo ? 'not.contain.text' : 'contain.text', + 'You are using a custom proxy. Make sure you implement all security measures needed', + ); + + cy.get('.ep-feature-instant-results [name="settings[active]"][value="1"]').click(); + cy.get('.ep-feature-instant-results .button-primary').click(); + cy.on('window:confirm', () => { + return true; + }); - /** - * Update the post and visit the front end. - */ - cy.get('.editor-post-publish-button__button').click(); - cy.get('.components-snackbar__action').click(); + cy.get('.ep-sync-progress strong', { + timeout: Cypress.config('elasticPressIndexTimeout'), + }).should('contain.text', 'Sync complete'); - /** - * Click the button. - */ - cy.intercept('*search=block*').as('apiRequest'); - cy.get('.wp-block-button__link').click(); + cy.wpCli('elasticpress list-features') + .its('stdout') + .should('contain', 'instant-results'); + }); /** - * Instant Results should be open and populated with out search term. + * Test that the instant results list is visible + * It can display the number of test results + * It can show the modal in the same state after a reload + * Can change the URL when search term is changed */ - cy.wait('@apiRequest'); - cy.get('.ep-search-modal').as('searchModal').should('be.visible'); - cy.get('@searchModal').find('.ep-search-input').should('have.value', 'block'); - cy.get('@searchModal').find('.ep-search-results__title').should('contain.text', 'block'); - }); + it('Can see instant results elements, URL changes, reload, and update after changing search term', () => { + cy.maybeEnableFeature('instant-results'); + + cy.intercept('*search=blog*').as('apiRequest'); + + cy.visit('/'); + + cy.get('.wp-block-search').last().as('searchBlock'); + + cy.get('@searchBlock').find('.wp-block-search__input').type('blog'); + cy.get('@searchBlock').find('.wp-block-search__button').click(); + cy.get('.ep-search-modal').as('searchModal').should('be.visible'); // Should be visible immediatly + cy.url().should('include', 'search=blog'); + + cy.wait('@apiRequest'); + cy.get('@searchModal').should('contain.text', 'blog'); + // Show the number of results + cy.get('@searchModal').find('.ep-search-results__title').contains(/\d+/); + + cy.get('.ep-search-sidebar #ep-search-post-type-post') + .click() + .then(() => { + cy.url().should('include', 'ep-post_type=post'); + }); + + // Show the modal in the same state after a reload + cy.reload(); + cy.wait('@apiRequest'); + cy.get('@searchModal').should('be.visible').should('contain.text', 'blog'); + + // Update the results when search term is changed + cy.get('@searchModal') + .find('.ep-search-input') + .clearThenType('test') + .then(() => { + cy.wait('@apiRequest'); + cy.get('@searchModal').should('be.visible').should('contain.text', 'test'); + cy.url().should('include', 'search=test'); + }); + + cy.get('#wpadminbar li#wp-admin-bar-debug-bar').click(); + cy.get('#querylist').should('be.visible'); + }); - it('Can filter the result template', () => { - /** - * Activate test plugin with filter. - */ - maybeEnableProxy(); - cy.maybeEnableFeature('instant-results'); - cy.activatePlugin('custom-instant-results-template', 'wpCli'); + it('Is possible to manually open Instant Results with a plugin', () => { + /** + * Activate test plugin with JavaScript. + */ + cy.maybeEnableFeature('instant-results'); + cy.activatePlugin('open-instant-results-with-buttons', 'wpCli'); + + /** + * Create a post with a Buttons block. + */ + cy.publishPost({ + title: `Test openModal()`, + content: 'Testing openModal()', + }); - /** - * Perform a search. - */ - cy.intercept('*search=blog*').as('apiRequest'); - cy.visit('/'); - cy.get('.wp-block-search').last().as('searchBlock'); - cy.get('@searchBlock').find('input[type="search"]').type('blog'); - cy.get('@searchBlock').find('button').click(); - cy.get('.ep-search-modal').should('be.visible'); - cy.wait('@apiRequest'); + cy.openBlockInserter(); + cy.insertBlock('Buttons'); + cy.get('.wp-block-button__link').type('Search "Block"'); + + /** + * Update the post and visit the front end. + */ + cy.get('.editor-post-publish-button__button').click(); + cy.get('.components-snackbar__action').click(); + + /** + * Click the button. + */ + cy.intercept('*search=block*').as('apiRequest'); + cy.get('.wp-block-button__link').click(); + + /** + * Instant Results should be open and populated with our search term. + */ + cy.wait('@apiRequest'); + cy.get('.ep-search-modal').as('searchModal').should('be.visible'); + cy.get('@searchModal').find('.ep-search-input').should('have.value', 'block'); + cy.get('@searchModal') + .find('.ep-search-results__title') + .should('contain.text', 'block'); + }); - /** - * Results should use the filtered template with a custom class. - */ - cy.get('.my-custom-result').should('exist'); - cy.get('.ep-search-result').should('not.exist'); + it('Can filter the result template', () => { + /** + * Activate test plugin with filter. + */ + cy.maybeEnableFeature('instant-results'); + cy.activatePlugin('custom-instant-results-template', 'wpCli'); + + /** + * Perform a search. + */ + cy.intercept('*search=blog*').as('apiRequest'); + cy.visit('/'); + cy.get('.wp-block-search').last().as('searchBlock'); + cy.get('@searchBlock').find('input[type="search"]').type('blog'); + cy.get('@searchBlock').find('button').click(); + cy.get('.ep-search-modal').should('be.visible'); + cy.wait('@apiRequest'); + + /** + * Results should use the filtered template with a custom class. + */ + cy.get('.my-custom-result').should('exist'); + cy.get('.ep-search-result').should('not.exist'); + }); }); }); From 0ceeb3586427dca0bd701b5f88e72e3014e0e492 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 27 Oct 2022 08:49:54 -0300 Subject: [PATCH 5/9] Use int instead of string --- tests/cypress/support/global-hooks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/support/global-hooks.js b/tests/cypress/support/global-hooks.js index 21f5bf7ee..2d7f829a0 100644 --- a/tests/cypress/support/global-hooks.js +++ b/tests/cypress/support/global-hooks.js @@ -29,7 +29,7 @@ before(() => { ).then((wpCliResponse) => { const wpCliRespObj = JSON.parse(wpCliResponse.stdout); window.indexNames = wpCliRespObj.indexNames; - window.isEpIo = wpCliRespObj.isEpIo === '1'; + window.isEpIo = wpCliRespObj.isEpIo === 1; }); }); From 93a2967055d8ba2c6c68b10ae1d142894ed5e8be Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Thu, 27 Oct 2022 09:16:05 -0300 Subject: [PATCH 6/9] Update WP-CLI command --- bin/setup-cypress-env.sh | 2 +- tests/cypress/integration/features/autosuggest.cy.js | 2 +- tests/cypress/integration/features/documents.cy.js | 4 ++-- tests/cypress/integration/features/facets.cy.js | 6 +++--- tests/cypress/integration/features/protected-content.cy.js | 4 ++-- tests/cypress/integration/features/search/search.cy.js | 2 +- tests/cypress/integration/features/search/synonyms.cy.js | 2 +- tests/cypress/integration/features/woocommerce.cy.js | 4 ++-- tests/cypress/integration/indexables/user.cy.js | 6 +++--- tests/cypress/integration/wp-basic.cy.js | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/setup-cypress-env.sh b/bin/setup-cypress-env.sh index 7d056655a..de5d5364a 100755 --- a/bin/setup-cypress-env.sh +++ b/bin/setup-cypress-env.sh @@ -81,7 +81,7 @@ fi ./bin/wp-env-cli tests-wordpress "wp --allow-root plugin activate ${PLUGIN_NAME}" -./bin/wp-env-cli tests-wordpress "wp --allow-root elasticpress index --setup --yes --show-errors" +./bin/wp-env-cli tests-wordpress "wp --allow-root elasticpress sync --setup --yes --show-errors" ./bin/wp-env-cli tests-wordpress "wp --allow-root option set posts_per_page 5" ./bin/wp-env-cli tests-wordpress "wp --allow-root user meta update admin edit_post_per_page 5" diff --git a/tests/cypress/integration/features/autosuggest.cy.js b/tests/cypress/integration/features/autosuggest.cy.js index 1fdaaec97..9628934e9 100644 --- a/tests/cypress/integration/features/autosuggest.cy.js +++ b/tests/cypress/integration/features/autosuggest.cy.js @@ -1,6 +1,6 @@ describe('Autosuggest Feature', () => { before(() => { - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); }); it('Can see autosuggest list', () => { diff --git a/tests/cypress/integration/features/documents.cy.js b/tests/cypress/integration/features/documents.cy.js index ccb72c460..103989dc3 100644 --- a/tests/cypress/integration/features/documents.cy.js +++ b/tests/cypress/integration/features/documents.cy.js @@ -31,7 +31,7 @@ describe('Documents Feature', () => { } before(() => { - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.exec( 'npm run env run tests-wordpress "chown -R www-data:www-data /var/www/html/wp-content/uploads"', ); @@ -47,7 +47,7 @@ describe('Documents Feature', () => { cy.get('body').should('contain.text', 'pdf-file'); // Check if the file is still searchable after a reindex. - cy.wpCli('elasticpress index --setup --yes --show-errors').then(() => { + cy.wpCli('elasticpress sync --setup --yes --show-errors').then(() => { /** * Give Elasticsearch some time. Apparently, if the visit happens right after the index, it won't find anything. * diff --git a/tests/cypress/integration/features/facets.cy.js b/tests/cypress/integration/features/facets.cy.js index 3d15c8e56..8a8c6f2ab 100644 --- a/tests/cypress/integration/features/facets.cy.js +++ b/tests/cypress/integration/features/facets.cy.js @@ -1,11 +1,11 @@ describe('Facets Feature', () => { /** - * Ensure the feature is active, perform an index, and remove test posts + * Ensure the feature is active, perform a sync, and remove test posts * before running tests. */ before(() => { cy.maybeEnableFeature('facets'); - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.wpCli('post list --s="A new" --ep_integrate=false --format=ids').then( (wpCliResponse) => { if (wpCliResponse.stdout) { @@ -254,7 +254,7 @@ describe('Facets Feature', () => { ); if ( $movie_id ) { wp_set_object_terms( $movie_id, 'action', 'genre' ); - WP_CLI::runcommand( 'elasticpress index --include=' . $movie_id ); + WP_CLI::runcommand( 'elasticpress sync --include=' . $movie_id ); WP_CLI::runcommand( 'rewrite flush' ); } `, diff --git a/tests/cypress/integration/features/protected-content.cy.js b/tests/cypress/integration/features/protected-content.cy.js index 2cc731220..36c3a840e 100644 --- a/tests/cypress/integration/features/protected-content.cy.js +++ b/tests/cypress/integration/features/protected-content.cy.js @@ -41,7 +41,7 @@ describe('Protected Content Feature', () => { } }); - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.publishPost({ title: 'Test ElasticPress Draft', @@ -64,7 +64,7 @@ describe('Protected Content Feature', () => { } }); - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.createAutosavePost(); diff --git a/tests/cypress/integration/features/search/search.cy.js b/tests/cypress/integration/features/search/search.cy.js index 90db47c8e..5bf50d048 100644 --- a/tests/cypress/integration/features/search/search.cy.js +++ b/tests/cypress/integration/features/search/search.cy.js @@ -1,6 +1,6 @@ describe('Post Search Feature', () => { before(() => { - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); }); it('Can use Elasticsearch for the default WP search', () => { diff --git a/tests/cypress/integration/features/search/synonyms.cy.js b/tests/cypress/integration/features/search/synonyms.cy.js index ccae21a04..c10723775 100644 --- a/tests/cypress/integration/features/search/synonyms.cy.js +++ b/tests/cypress/integration/features/search/synonyms.cy.js @@ -138,7 +138,7 @@ describe('Post Search Feature - Synonyms Functionality', () => { cy.get('#ep-synonym-input').clearThenType('foo => bar{enter}list,of,words'); cy.get('#synonym-root .button-primary').click(); - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.visitAdminPage('admin.php?page=elasticpress-synonyms'); cy.get('#ep-synonym-input') diff --git a/tests/cypress/integration/features/woocommerce.cy.js b/tests/cypress/integration/features/woocommerce.cy.js index 438c26846..038be6550 100644 --- a/tests/cypress/integration/features/woocommerce.cy.js +++ b/tests/cypress/integration/features/woocommerce.cy.js @@ -81,7 +81,7 @@ describe('WooCommerce Feature', () => { }, }, }).then(() => { - cy.wpCli('elasticpress index --setup --yes').then(() => { + cy.wpCli('elasticpress sync --setup --yes').then(() => { /** * Give Elasticsearch some time. Apparently, if the visit happens right after the index, it won't find anything. * @@ -110,7 +110,7 @@ describe('WooCommerce Feature', () => { * Orders */ // this is required to sync the orders to Elasticsearch. - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); cy.visitAdminPage('edit.php?post_type=shop_order'); cy.get('#debug-menu-target-EP_Debug_Bar_ElasticPress .ep-query-debug').should( diff --git a/tests/cypress/integration/indexables/user.cy.js b/tests/cypress/integration/indexables/user.cy.js index 14abd65b9..f74350d1d 100644 --- a/tests/cypress/integration/indexables/user.cy.js +++ b/tests/cypress/integration/indexables/user.cy.js @@ -9,7 +9,7 @@ describe('User Indexable', () => { cy.wpCli(`wp user get ${newUserData.userLogin} --field=ID`, true).then((wpCliResponse) => { if (wpCliResponse.code === 0) { cy.wpCli(`wp user delete ${newUserData.userLogin} --yes --network`); - cy.wpCli('wp elasticpress index --setup --yes'); + cy.wpCli('wp elasticpress sync --setup --yes'); } }); @@ -66,7 +66,7 @@ describe('User Indexable', () => { cy.get('.query-results').should('contain.text', '"user_email": "testuser@example.com"'); // Test if the user is still found a reindex. - cy.wpCli('wp elasticpress index --setup --yes'); + cy.wpCli('wp elasticpress sync --setup --yes'); searchUser(); @@ -118,7 +118,7 @@ describe('User Indexable', () => { cy.wpCli(`wp user get ${newUserData.userLogin} --field=ID`, true).then((wpCliResponse) => { if (wpCliResponse.code === 0) { cy.wpCli(`wp user delete ${newUserData.userLogin} --yes --network`); - cy.wpCli('wp elasticpress index --setup --yes'); + cy.wpCli('wp elasticpress sync --setup --yes'); } }); diff --git a/tests/cypress/integration/wp-basic.cy.js b/tests/cypress/integration/wp-basic.cy.js index bb7361861..c1c4d982c 100644 --- a/tests/cypress/integration/wp-basic.cy.js +++ b/tests/cypress/integration/wp-basic.cy.js @@ -1,6 +1,6 @@ describe('WordPress basic actions', () => { before(() => { - cy.wpCli('elasticpress index --setup --yes'); + cy.wpCli('elasticpress sync --setup --yes'); }); it('Has tag', () => { From 2bd55ae3c51cc9f424a64c0cf08791ff8785178a Mon Sep 17 00:00:00 2001 From: Felipe Elia <felipe.elia@gmail.com> Date: Thu, 27 Oct 2022 09:54:01 -0300 Subject: [PATCH 7/9] Login for each test --- tests/cypress/integration/features/instant-results.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/integration/features/instant-results.cy.js b/tests/cypress/integration/features/instant-results.cy.js index 0ceccf28a..6e675ed9d 100644 --- a/tests/cypress/integration/features/instant-results.cy.js +++ b/tests/cypress/integration/features/instant-results.cy.js @@ -17,7 +17,6 @@ describe('Instant Results Feature', () => { } before(() => { - cy.login(); createSearchWidget(); // Create some sample posts @@ -36,6 +35,7 @@ describe('Instant Results Feature', () => { 'custom-instant-results-template open-instant-results-with-buttons', 'wpCli', ); + cy.login(); }); /** From 7ba1a7ca3b3c6f66a6e3d7c428e05ac6fd26abee Mon Sep 17 00:00:00 2001 From: Felipe Elia <felipe.elia@gmail.com> Date: Thu, 27 Oct 2022 10:55:59 -0300 Subject: [PATCH 8/9] Optimize dashboard e2e test --- .../cypress/integration/dashboard-sync.cy.js | 67 ++++--------------- 1 file changed, 12 insertions(+), 55 deletions(-) diff --git a/tests/cypress/integration/dashboard-sync.cy.js b/tests/cypress/integration/dashboard-sync.cy.js index 6e21420c0..b7b7f4017 100644 --- a/tests/cypress/integration/dashboard-sync.cy.js +++ b/tests/cypress/integration/dashboard-sync.cy.js @@ -79,16 +79,6 @@ describe('Dashboard Sync', () => { .should('contain.text', 'If you are still having issues with your search results'); }); - it('Can index content and see indexes names in the Health Screen', () => { - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.get('.ep-sync-button--delete').click(); - cy.get('.ep-sync-progress strong', { - timeout: Cypress.config('elasticPressIndexTimeout'), - }).should('contain.text', 'Sync complete'); - - canSeeIndexesNames(); - }); - it('Can sync via Dashboard when activated in single site', () => { cy.wpCli('wp elasticpress delete-index --yes'); @@ -114,8 +104,6 @@ describe('Dashboard Sync', () => { }); it('Can sync via Dashboard when activated in multisite', () => { - cy.wpCli('wp elasticpress delete-index --yes'); - cy.activatePlugin('elasticpress', 'wpCli', 'network'); // Sync and remove, so EP doesn't think it is a fresh install. @@ -154,71 +142,40 @@ describe('Dashboard Sync', () => { cy.deactivatePlugin('elasticpress', 'wpCli', 'network'); cy.activatePlugin('elasticpress', 'wpCli'); - - cy.wpCli('wp elasticpress sync --setup --yes'); }); - it('Can pause the dashboard sync if left the page', () => { + it('Can pause the dashboard sync, can not activate a feature during sync nor perform a sync via WP-CLI', () => { setPerIndexCycle(20); cy.visitAdminPage('admin.php?page=elasticpress-sync'); + // Start sync via dashboard and pause it cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); cy.get('.ep-sync-button--delete').click(); cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); cy.get('.ep-sync-button--pause').should('be.visible'); - cy.visitAdminPage('index.php'); + // Can not activate a feature. + cy.visitAdminPage('admin.php?page=elasticpress'); + cy.get('.error-overlay').should('have.class', 'syncing'); + + // Can not start a sync via WP-CLI + cy.wpCli('wp elasticpress sync', true) + .its('stderr') + .should('contain', 'An index is already occurring'); + // Check if it is paused cy.visitAdminPage('admin.php?page=elasticpress-sync'); cy.get('.ep-sync-button--resume').should('be.visible'); cy.get('.ep-sync-progress strong').should('contain.text', 'Sync paused'); resumeAndWait(); - - setPerIndexCycle(); - canSeeIndexesNames(); - }); - - it("Can't activate features during a sync", () => { - setPerIndexCycle(20); - - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); - cy.get('.ep-sync-button--delete').click(); - cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - - cy.visitAdminPage('admin.php?page=elasticpress'); - cy.get('.error-overlay').should('have.class', 'syncing'); - - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - resumeAndWait(); + // Features should be accessible again 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(20); - - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - cy.intercept('POST', '/wp-admin/admin-ajax.php*').as('ajaxRequest'); - cy.get('.ep-sync-button--delete').click(); - cy.wait('@ajaxRequest').its('response.statusCode').should('eq', 200); - - cy.get('.ep-sync-button--pause').should('be.visible'); - cy.get('.ep-sync-button--pause').click(); - - cy.wpCli('wp elasticpress sync', true) - .its('stderr') - .should('contain', 'An index is already occurring'); - - cy.visitAdminPage('admin.php?page=elasticpress-sync'); - resumeAndWait(); - - setPerIndexCycle(); - }); }); From f6ffb9cbe7ca5e2d768399ebdad7a667f0e9ea5f Mon Sep 17 00:00:00 2001 From: Felipe Elia <felipe.elia@gmail.com> Date: Thu, 27 Oct 2022 13:56:15 -0300 Subject: [PATCH 9/9] Trigger GH actions