Skip to content

Commit

Permalink
Synonyms: tests for alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Mar 17, 2022
1 parent 92463db commit e486deb
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions tests/cypress/integration/features/search/synonyms.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
describe('Post Search Feature - Synonyms Functionality', () => {
const word1 = 'authenticity';
const word2 = 'credibility';

before(() => {
cy.wpCli("wp post list --post_type='ep-synonym' --format=ids", true).then(
(wpCliResponse) => {
Expand All @@ -20,39 +23,66 @@ describe('Post Search Feature - Synonyms Functionality', () => {

const postsData = [
{
title: 'Testing Synonyms - Shoes',
title: `Testing Synonyms - ${word1}`,
},
{
title: 'Testing Synonyms - Sneakers',
title: `Testing Synonyms - ${word2}`,
},
];
postsData.forEach((postData) => {
cy.publishPost(postData);
});
});
it('Can create, search, and delete synonyms sets', () => {
beforeEach(() => {
cy.login();

});
it('Can create, search, and delete synonyms sets', () => {
// Add the set
cy.visitAdminPage('admin.php?page=elasticpress-synonyms');
cy.get('.synonym-sets-editor .synonym__remove').click();
cy.contains('.synonym-sets-editor .button', 'Add Set').as('addset').click();
cy.get('.synonym-sets-editor .ep-synonyms__linked-multi-input').type(
'sneakers{enter}shoes{enter}',
);
cy.get('.synonym-sets-editor').within(() => {
cy.get('.synonym__remove').click();
cy.contains('.button', 'Add Set').as('addset').click();
cy.get('.ep-synonyms__linked-multi-input').type(`${word1}{enter}${word2}{enter}`);
});
cy.get('#synonym-root .button-primary').click();

// Check if it works
cy.visit('/?s=sneakers');
cy.contains('.site-content article h2', 'Shoes').should('exist');
cy.visit(`/?s=${word2}`);
cy.contains('.site-content article h2', word1).should('exist');

// Remove the set
cy.visitAdminPage('admin.php?page=elasticpress-synonyms');
cy.get('.synonym-sets-editor .synonym__remove').click();
cy.get('#synonym-root .button-primary').click();

// Check if it works
cy.visit('/?s=sneakers');
cy.contains('.site-content article h2', 'Shoes').should('not.exist');
cy.visit(`/?s=${word2}`);
cy.contains('.site-content article h2', word1).should('not.exist');
});
it('Can create, search, and delete synonyms alternatives', () => {
// Add the set
cy.visitAdminPage('admin.php?page=elasticpress-synonyms');
cy.get('.synonym-alternatives-editor').within(() => {
cy.get('.synonym__remove').click();
cy.contains('.button', 'Add Alternative').as('addset').click();
cy.get('.ep-synonyms__input').type(word1);
cy.get('.ep-synonyms__linked-multi-input').type(`${word2}{enter}`);
});
cy.get('#synonym-root .button-primary').click();

// Check if it works
cy.visit(`/?s=${word1}`);
cy.contains('.site-content article h2', word2).should('exist');
cy.visit(`/?s=${word2}`);
cy.contains('.site-content article h2', word1).should('not.exist');

// Remove the set
cy.visitAdminPage('admin.php?page=elasticpress-synonyms');
cy.get('.synonym-alternatives-editor .synonym__remove').click();
cy.get('#synonym-root .button-primary').click();

// Check if it works
cy.visit(`/?s=${word1}`);
cy.contains('.site-content article h2', word2).should('not.exist');
});
});

0 comments on commit e486deb

Please sign in to comment.