Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize some calls in e2e tests #3085

Merged
merged 9 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/setup-cypress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
67 changes: 12 additions & 55 deletions tests/cypress/integration/dashboard-sync.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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.
Expand Down Expand Up @@ -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();
});
});
2 changes: 1 addition & 1 deletion tests/cypress/integration/features/autosuggest.cy.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/integration/features/documents.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
);
Expand All @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/cypress/integration/features/facets.cy.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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' );
}
`,
Expand Down
Loading