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

Add tests for instant results feature #2851

Merged
merged 25 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
72949ff
Add tests for instant results feature
Jun 21, 2022
59459d1
Change the activation to dashboard and test post name
Jul 14, 2022
b12fb4f
More test cases for instant results
Aug 3, 2022
e8c2d23
Add search widget to test the results
Aug 9, 2022
23bd726
Proepr text to test against the search
Aug 9, 2022
846bdeb
Merge branch 'develop' of github.com:10up/ElasticPress into fix/issue…
Aug 17, 2022
3da23cb
show the same modal after reload
Aug 17, 2022
c62f87e
add delay to test the results
Aug 18, 2022
ff12865
Add more tests for Instant results
Aug 19, 2022
def00fc
Change the filter
Aug 22, 2022
88cc2cd
Proper class names
Aug 22, 2022
92cb69c
Search for a category
Aug 22, 2022
affd195
Search for a post with category
Aug 22, 2022
23edea8
Remove the taxonomy label test for now
Aug 22, 2022
3855004
Merge branch 'develop' of github.com:10up/ElasticPress into fix/issue…
Aug 25, 2022
49dff57
Merge small tests and improve code
Aug 25, 2022
fc68cf5
Add search widget
Aug 25, 2022
227558d
Should be able to enable the feature when in ep.io
Aug 25, 2022
bb47c93
Add wrap for the result
Aug 25, 2022
c768aac
Merge branch 'develop' into fix/issue-2788
felipeelia Sep 16, 2022
a1f7a27
Instant Results e2e tests refactor
felipeelia Sep 16, 2022
7a5cb9c
Fix type comparison
felipeelia Sep 16, 2022
85cacdb
Prevent autosuggest from running on Instant Results search
felipeelia Sep 16, 2022
487796e
Deactivate elasticpress-proxy by default + stop dbdump generation
felipeelia Sep 16, 2022
a2c0906
Wait for request
felipeelia Sep 16, 2022
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
3 changes: 2 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"https://downloads.wordpress.org/plugin/debug-bar.zip",
"https://downloads.wordpress.org/plugin/debug-bar-elasticpress.zip",
"https://downloads.wordpress.org/plugin/wordpress-importer.zip",
"https://downloads.wordpress.org/plugin/woocommerce.zip"
"https://downloads.wordpress.org/plugin/woocommerce.zip",
"10up/elasticpress-proxy#develop"
],
"mappings": {
"wp-content/mu-plugins/unique-index-name.php": "./tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php",
Expand Down
5 changes: 3 additions & 2 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,10 @@ function init() {
*/
const prepareInputForAutosuggest = (input) => {
/**
* Skip facet widget search fields.
* Skip facet widget search fields and instant results.
*/
if (input.classList.contains('facet-search')) {
const ignoredClasses = ['facet-search', 'ep-search-input'];
felipeelia marked this conversation as resolved.
Show resolved Hide resolved
if (ignoredClasses.some((className) => input.classList.contains(className))) {
return;
}

Expand Down
8 changes: 3 additions & 5 deletions bin/setup-cypress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fi

./bin/wp-env-cli tests-wordpress "wp --allow-root import /var/www/html/wp-content/uploads/content-example.xml --authors=create"

./bin/wp-env-cli tests-wordpress "wp --allow-root plugin deactivate woocommerce"
./bin/wp-env-cli tests-wordpress "wp --allow-root plugin deactivate woocommerce elasticpress-proxy"

./bin/wp-env-cli tests-wordpress "wp --allow-root plugin activate debug-bar debug-bar-elasticpress wordpress-importer --network"

Expand All @@ -87,7 +87,5 @@ fi
./bin/wp-env-cli tests-wordpress "wp --allow-root 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
./bin/wp-env-cli tests-wordpress "wp --allow-root db export -" > $SQL_FILENAME

exit 0
# SQL_FILENAME=./bin/$(date +'%F-%H-%M').sql
# npm --silent run env run tests-cli "wp db export -" > $SQL_FILENAME
144 changes: 144 additions & 0 deletions tests/cypress/integration/features/instant-results.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/* global isEpIo */

describe('Instant Results Feature', () => {
/**
* Create a Search widget.
*
* As tests for facets will remove all widgets, we recreate it here.
*/
function createSearchWidget() {
cy.openWidgetsPage();
cy.openBlockInserter();
cy.getBlocksList().should('contain.text', 'Search'); // Checking if it exists give JS time to process the full list.
cy.insertBlock('Search');
cy.intercept('/wp-json/wp/v2/sidebars/*').as('sidebarsRest');
cy.get('.edit-widgets-header__actions button').contains('Update').click();
cy.wait('@sidebarsRest');
}

function maybeEnableProxy() {
if (!isEpIo) {
cy.activatePlugin('elasticpress-proxy');
}
}

before(() => {
createSearchWidget();

// Create some sample posts
cy.publishPost({
title: 'Blog post',
content: 'This is a sample Blog post.',
});
cy.publishPost({
title: 'Test Post',
content: 'This is a sample test post.',
});
});

after(() => {
cy.deactivatePlugin('elasticpress-proxy');
});

/**
* Test that the feature cannot be activated when not in ElasticPress.io nor using a custom PHP proxy.
*/
it("Can't activate the feature if not in ElasticPress.io nor using a custom PHP proxy", () => {
if (isEpIo) {
return;
}

cy.login();
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(
'contain.text',
'To use this feature you need to be an ElasticPress.io customer or implement a custom proxy',
);
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;
});

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();
cy.maybeEnableFeature('instant-results');
maybeEnableProxy();

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');
});
});
5 changes: 5 additions & 0 deletions tests/cypress/support/global-hooks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.indexNames = null;
window.isEpIo = false;

before(() => {
cy.wpCliEval(
Expand All @@ -24,6 +25,10 @@ before(() => {
).then((wpCliResponse) => {
window.indexNames = JSON.parse(wpCliResponse.stdout);
});

cy.wpCli('eval "echo (int) \\ElasticPress\\Utils\\is_epio();"').then((response) => {
window.isEpIo = response.stdout === '1';
});
});

afterEach(() => {
Expand Down