diff --git a/apps/web-mzima-client/src/app/feed/feed.component.html b/apps/web-mzima-client/src/app/feed/feed.component.html
index 5f98cfa5be..52fea53c11 100644
--- a/apps/web-mzima-client/src/app/feed/feed.component.html
+++ b/apps/web-mzima-client/src/app/feed/feed.component.html
@@ -212,7 +212,7 @@
[attr.data-qa]="'posts'"
>
-
+
diff --git a/apps/web-mzima-client/src/app/shared/components/search-form/search-form.component.html b/apps/web-mzima-client/src/app/shared/components/search-form/search-form.component.html
index 90c778ef5b..a4751a5b6a 100644
--- a/apps/web-mzima-client/src/app/shared/components/search-form/search-form.component.html
+++ b/apps/web-mzima-client/src/app/shared/components/search-form/search-form.component.html
@@ -25,6 +25,7 @@
class="search-form__form-control"
[ngModelOptions]="{ standalone: true }"
[placeholder]="'global_filter.search' | translate"
+ [data-qa]="'search-form-search-posts'"
/>
{
+ const loginFunctions = new LoginFunctions();
+ const postFunctions = new PostFunctions();
+
+ beforeEach(() => {
+ loginFunctions.login_as_admin();
+ cy.visit(Cypress.env('baseUrl'));
+ });
+
+ it('should display posts with the keyword in title or description', () => {
+ const searchKeyword = 'election';
+ dataViewFunctions.search_and_verify_results(searchKeyword);
+ });
+
+ it('should display an empty state when searching with special characters', () => {
+ const generateSpecialCharacterKeyword = () => {
+ const specialChars = '!@#$%^&*()_+-=[]{};\':"\\|,.<>/?`~';
+ let keyword = '';
+ const length = Math.floor(Math.random() * 10) + 1;
+ for (let i = 0; i < length; i++) {
+ keyword += specialChars[Math.floor(Math.random() * specialChars.length)];
+ }
+ return keyword;
+ };
+ const specialCharKeyword = generateSpecialCharacterKeyword();
+ dataViewFunctions.search_and_verify_results_with_special_characters(specialCharKeyword);
+ });
+});
diff --git a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js
index 79e2b17070..7e96f40024 100644
--- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js
+++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js
@@ -1,29 +1,68 @@
+///
+
import DataViewLocators from '../../locators/DataViewLocators';
import LoginFunctions from '../LoginFunctions';
+import PostLocators from '../../locators/PostsLocators/PostLocators';
const loginFunctions = new LoginFunctions();
class DataViewFunctions {
+ constructor() {
+ this.postTitle = `The elections`;
+ this.postDescription = 'This is a post about the ongoing elections';
+ }
+ open_post_creation_form() {
+ cy.get(PostLocators.addPostBtn).click();
+ cy.get(PostLocators.srvyItemBtn2).click();
+ }
+ type_post_title(title) {
+ cy.get(PostLocators.titleField).eq(0).type(title).should('have.value', title);
+ }
+
+ type_post_description(description) {
+ cy.get(PostLocators.descField).type(description).should('have.value', description);
+ }
+ fill_required_form_fields() {
+ this.type_post_title(this.postTitle);
+ this.type_post_description(this.postDescription);
+ }
+
+ complete_add_post_steps() {
+ cy.get(PostLocators.submitBtn).should('not.be.disabled');
+ cy.get(PostLocators.submitBtn).click();
+ cy.get(PostLocators.successButton).click();
+ }
+
click_data_view_btn() {
- cy.get(DataViewLocators.dataViewBtn).click();
+ cy.get(DataViewLocators.dataViewBtn).should('be.visible').click({ force: true });
cy.url().should('include', '/feed');
}
-
- verify_post_appears_for_user() {
+ search_and_verify_results(keyword) {
+ this.open_post_creation_form();
+ this.fill_required_form_fields();
+ this.complete_add_post_steps();
this.click_data_view_btn();
- //check post appears for admin user
- cy.get(DataViewLocators.postPreview)
- .children(DataViewLocators.postItem)
- .contains('Automated Title Response')
- .click();
- cy.get(DataViewLocators.postMenuDots).eq(0).click();
- cy.get(DataViewLocators.publishPostBtn).click();
- loginFunctions.logout();
- //check post appears for non logged in user
+ cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true });
+ // Wait for the API request to fetch results
+ cy.intercept('GET', '**/api/v5/posts/stats*').as('searchResults');
+ cy.wait('@searchResults');
+ // Verify that results contain the keyword in the title or description
+ cy.get(DataViewLocators.postPreview).within(() => {
+ cy.get(DataViewLocators.postItem).each(($post) => {
+ cy.wrap($post)
+ .invoke('text')
+ .then((text) => {
+ expect(text.toLowerCase()).to.include(keyword.toLowerCase());
+ });
+ });
+ });
+ }
+ search_and_verify_results_with_special_characters(keyword) {
this.click_data_view_btn();
- cy.get(DataViewLocators.postPreview)
- .children(DataViewLocators.postItem)
- .contains('Automated Title Response');
+ cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true });
+ cy.get(DataViewLocators.postsEmptyMessage)
+ .should('be.visible')
+ .and('contain.text', 'No posts match your keyword search');
}
}
diff --git a/e2e-testing/cypress/locators/DataViewLocators.js b/e2e-testing/cypress/locators/DataViewLocators.js
index f226fe74cf..4df340f994 100644
--- a/e2e-testing/cypress/locators/DataViewLocators.js
+++ b/e2e-testing/cypress/locators/DataViewLocators.js
@@ -18,7 +18,8 @@ const DataViewLocators = {
publishPostBtn: '[data-qa="btn-publish-post"]',
postDetails: '[data-qa="post-details"]',
-
+ searchInput: '[data-qa="search-form-search-posts"]',
+ postsEmptyMessage: '[data-qa="posts-empty"]',
};
export default DataViewLocators;
diff --git a/e2e-testing/cypress/locators/PostsLocators/PostLocators.js b/e2e-testing/cypress/locators/PostsLocators/PostLocators.js
index be6bf4d1f6..55281dd8a4 100644
--- a/e2e-testing/cypress/locators/PostsLocators/PostLocators.js
+++ b/e2e-testing/cypress/locators/PostsLocators/PostLocators.js
@@ -2,6 +2,7 @@ const PostLocators = {
dataViewBtn: '[data-qa="btn-data"]',
addPostBtn: '[data-qa="submit-post-button"]',
srvyItemBtn: '[data-qa="add-post-modal-surveys-item125"]',
+ srvyItemBtn2: '[data-qa="add-post-modal-surveys-item766"]',
successButton: '[data-qa="btn-confirm-success"]',
submitBtn: '[data-qa="btn-post-item-submit"]',
postPreview: '[data-qa="post-preview"]',
@@ -29,6 +30,7 @@ const PostLocators = {
checkboxFieldOption3: '[data-qa="checkboxes-field-f3"]',
relatedPostField: '[data-qa="related-post-field"]',
embedVideoField: '[data-qa="embed-video field"]',
+ selectFieldForSearch: '[data-qa="nature-of-this-incident-bombings"]',
//status items
publishPostBtn: '[data-qa="btn-publish-post"]',
@@ -36,7 +38,6 @@ const PostLocators = {
underReviewPostBtn: '[data-qa="btn-underReview-post"]',
archivePostBtn: '[data-qa="btn-archive-post"]',
-
//field menu items
postMenuDots: '[data-qa="post-menu"]',
deletePostBtn: '[data-qa="btn-delete-post"]',