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 14 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
178 changes: 178 additions & 0 deletions tests/cypress/integration/features/instant-results.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
describe('Instant Results Feature', () => {
/**
* Create a Search widget.
*/
function createSearchWidget() {
cy.openWidgetsPage();

cy.get('.edit-widgets-header-toolbar__inserter-toggle').click();
cy.get('.block-editor-inserter__panel-content [class*="search/default"]').click({
force: true,
});

cy.get('.edit-widgets-header__actions .components-button.is-primary').click();
cy.get('body').should('contain.text', 'Widgets saved.');
}
felipeelia marked this conversation as resolved.
Show resolved Hide resolved

before(() => {
cy.wpCli('eval "echo ElasticPress\\Utils\\get_host();"').then((epHost) => {
// Nothing needs to be done if EP.io.
if (epHost.stdout.match(/elasticpress\.io/)) {
return;
}
cy.activatePlugin('elasticpress-proxy', 'dashboard');
});
felipeelia marked this conversation as resolved.
Show resolved Hide resolved
// Add search widget that will be used for the tests.
createSearchWidget();
});

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

it("Can't activate the feature If not in ElasticPress.io nor using a custom PHP proxy", () => {
cy.login();

cy.wpCli('eval "echo ElasticPress\\Utils\\get_host();"').then((epHost) => {
// Nothing needs to be done if EP.io.
if (epHost.stdout.match(/elasticpress\.io/)) {
return;
}
cy.deactivatePlugin('elasticpress-proxy', 'dashboard');
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');
cy.activatePlugin('elasticpress-proxy', 'dashboard');
});
});

it('Can see a warning if using cusotom proxy', () => {
cy.login();
cy.wpCli('eval "echo ElasticPress\\Utils\\get_host();"').then((epHost) => {
// Nothing needs to be done if EP.io.
if (epHost.stdout.match(/elasticpress\.io/)) {
return;
}
cy.visitAdminPage('admin.php?page=elasticpress');
cy.get('.ep-feature-instant-results .settings-button').click();
cy.get('.requirements-status-notice').should(
'contain.text',
'You are using a custom proxy. Make sure you implement all security measures needed',
);
cy.get('.ep-feature-instant-results .input-wrap').should('not.have.class', 'disabled');
});
});
felipeelia marked this conversation as resolved.
Show resolved Hide resolved

it('Can activate the feature and sync automatically', () => {
cy.login();

cy.visitAdminPage('admin.php?page=elasticpress');
cy.get('.ep-feature-instant-results .settings-button').click();
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');
});

it('Can see instant results list', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('blog');
cy.get('.wp-block-search__button')
.click()
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'blog');
});
});

it('Can display the number of results', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('blog');
cy.get('.wp-block-search__button')
.click()
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'blog');
cy.get('.ep-search-results__title').contains(/\d+/);
});
});

it('Can show the modal in the same state after a reload', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('blog');
cy.get('.wp-block-search__button')
.click()
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'blog');
});
cy.reload();
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'blog');
});

it('Can update the results after changing the search term', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('blog');
cy.get('.wp-block-search__button')
.click()
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'blog');
});
cy.get('#ep-instant-results .ep-search-input')
.clearThenType('test')
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'test');
});
});

it('Can update the URL after changing the filters', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('test');
cy.get('.wp-block-search__button')
.click()
.then(() => {
cy.get('.ep-search-modal').should('be.visible').should('contain.text', 'test');
});
cy.get('.ep-search-sidebar #ep-search-post-type-post')
.click()
.then(() => {
cy.url().should('include', 'ep-post_type=post');
});
});

it('Can click outside when instant results are shown', () => {
cy.login();
cy.maybeEnableFeature('instant-results');

cy.visit('/');
cy.get('.wp-block-search__input').type('blog');
cy.get('.wp-block-search__button').click();
cy.get('.ep-search-modal').should('be.visible');

cy.get('#wpadminbar li#wp-admin-bar-debug-bar').click();
cy.get('#querylist').should('be.visible');
});
});