Skip to content

Commit

Permalink
Merge pull request #2615 from 10up/tests/fix-for-4.0.0
Browse files Browse the repository at this point in the history
Adjust Cypress tests for 4.0.0
  • Loading branch information
felipeelia authored Feb 25, 2022
2 parents ec9e96a + 986b33a commit a1fad57
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 101 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions bin/setup-cypress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
}

Expand Down
93 changes: 44 additions & 49 deletions tests/cypress/integration/dashboard-sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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();
});
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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();

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/integration/features/autosuggest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/integration/features/documents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions tests/cypress/integration/features/protected-content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
8 changes: 4 additions & 4 deletions tests/cypress/integration/features/related-posts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down
17 changes: 10 additions & 7 deletions tests/cypress/integration/features/search/search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -64,15 +67,15 @@ 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.
const yesterday = new Date(+new Date() - 86400000)
.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}'`,
);

/**
Expand All @@ -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)')
Expand All @@ -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',
Expand Down
11 changes: 5 additions & 6 deletions tests/cypress/integration/features/woocommerce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
12 changes: 5 additions & 7 deletions tests/cypress/integration/indexables/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Loading

0 comments on commit a1fad57

Please sign in to comment.