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

Dataview search e2e Tests #1468

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
2 changes: 1 addition & 1 deletion apps/web-mzima-client/src/app/feed/feed.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ <h3 class="menu-title">{{ 'app.mark_as' | translate }}</h3>
[attr.data-qa]="'posts'"
>
<!-- No posts -->
<span *ngIf="!posts.length" class="posts-empty">
<span *ngIf="!posts.length" class="posts-empty" data-qa="posts-empty">
<ng-container *ngIf="isDefaultFilters">
<!-- No posts 1a: When there are no posts at all in the deployment or there no posts because none can be viewed by a user due to the permissions they have -->
<ng-container *ngIf="!userIsSearchingPostsByKeyword">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class="search-form__form-control"
[ngModelOptions]="{ standalone: true }"
[placeholder]="'global_filter.search' | translate"
[data-qa]="'search-form-search-posts'"
/>
<mzima-client-button
matSuffix
Expand Down
2 changes: 1 addition & 1 deletion apps/web-mzima-client/src/env.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not make any changes to the env file that is outside the e2e-testing folder

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the changes

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"sentry_dsn": "",
"sentry_environment": "",
"sentry_debug_mode": false
}
}
2 changes: 1 addition & 1 deletion e2e-testing/cypress.env.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you undo the changes in the Cypress env

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"ush_user_email": "[email protected]",
"ush_user_pwd": "1234567",
"ush_user_name": "Automation User Member Role"
}
}
27 changes: 27 additions & 0 deletions e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import DataViewFunctions from '../../functions/DataViewFunctions/DataViewFunctions';
const dataViewFunctions = new DataViewFunctions();

describe('Search and Verify Posts', () => {
beforeEach(() => {
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const loginFunctions = new LoginFunctions();

class DataViewFunctions {
click_data_view_btn() {
cy.get(DataViewLocators.dataViewBtn).click();
cy.get(DataViewLocators.dataViewBtn).should('be.visible').click({ force: true });
cy.url().should('include', '/feed');
}

Expand All @@ -25,6 +25,32 @@ class DataViewFunctions {
.children(DataViewLocators.postItem)
.contains('Automated Title Response');
}
search_and_verify_results(keyword) {
this.click_data_view_btn();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before searching for the keyword, could you add a post with the keyword so that the post exists that you are searching for.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean to create a new post in the test block? because there are posts with the election keyword before now...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An update has been made for this, kindly review @shakirandagire

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.searchInput).clear({ force: true }).type(keyword, { force: true });
cy.get(DataViewLocators.postsEmptyMessage)
.should('be.visible')
.and('contain.text', 'No posts match your keyword search');
}
}

export default DataViewFunctions;
3 changes: 2 additions & 1 deletion e2e-testing/cypress/locators/DataViewLocators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading