From c311c418563088de38db671503f25a17b55b2bf4 Mon Sep 17 00:00:00 2001 From: felabel Date: Mon, 18 Nov 2024 22:49:18 +0100 Subject: [PATCH 1/7] created automated tests for posts search in data-view --- .../src/app/feed/feed.component.html | 2 +- .../search-form/search-form.component.html | 1 + apps/web-mzima-client/src/env.json | 2 +- e2e-testing/cypress.env.json | 8 ++--- .../e2e/12-data-view/data-view-search.cy.js | 18 ++++++++++ .../DataViewFunctions/DataViewFunctions.js | 34 ++++++++++++++++++- .../cypress/locators/DataViewLocators.js | 3 +- 7 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js 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..ceea133fdd 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'" /> { + cy.visit(Cypress.env('baseUrl')); +}); + +describe('Search and Verify Posts', () => { + 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 specialCharKeyword = '!@#$%^&*'; + 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..7e3b2822b5 100644 --- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js +++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js @@ -5,7 +5,9 @@ const loginFunctions = new LoginFunctions(); class DataViewFunctions { click_data_view_btn() { - cy.get(DataViewLocators.dataViewBtn).click(); + cy.get(DataViewLocators.dataViewBtn) + .should('be.visible') // Ensure the button is visible + .click({ force: true }); // Force the click action cy.url().should('include', '/feed'); } @@ -25,6 +27,36 @@ class DataViewFunctions { .children(DataViewLocators.postItem) .contains('Automated Title Response'); } + search_and_verify_results(keyword) { + this.click_data_view_btn(); + 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) { + const specialCharacterRegex = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?`~]+$/; + if (!specialCharacterRegex.test(keyword)) { + throw new Error('Provided keyword does not contain only special characters'); + } + + this.click_data_view_btn(); + cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true }); + + cy.get(DataViewLocators.postsEmptyMessage).should('be.visible'); + } } export default DataViewFunctions; diff --git a/e2e-testing/cypress/locators/DataViewLocators.js b/e2e-testing/cypress/locators/DataViewLocators.js index f226fe74cf..66bca46ecb 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; From 5b2a98012ab683920446ec53a2979c8585bae3be Mon Sep 17 00:00:00 2001 From: felabel Date: Mon, 18 Nov 2024 22:50:54 +0100 Subject: [PATCH 2/7] created automated tests for posts search in data-view --- .../cypress/functions/DataViewFunctions/DataViewFunctions.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js index 7e3b2822b5..8159adfe80 100644 --- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js +++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js @@ -5,9 +5,7 @@ const loginFunctions = new LoginFunctions(); class DataViewFunctions { click_data_view_btn() { - cy.get(DataViewLocators.dataViewBtn) - .should('be.visible') // Ensure the button is visible - .click({ force: true }); // Force the click action + cy.get(DataViewLocators.dataViewBtn).should('be.visible').click({ force: true }); cy.url().should('include', '/feed'); } @@ -54,7 +52,6 @@ class DataViewFunctions { this.click_data_view_btn(); cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true }); - cy.get(DataViewLocators.postsEmptyMessage).should('be.visible'); } } From 54ea6352b6ccde44ccccbce39ab03aa955a9761e Mon Sep 17 00:00:00 2001 From: felabel Date: Fri, 22 Nov 2024 17:21:57 +0100 Subject: [PATCH 3/7] updated naming convention for data-qa --- .../components/search-form/search-form.component.html | 2 +- apps/web-mzima-client/src/env.json | 2 +- .../cypress/e2e/12-data-view/data-view-search.cy.js | 8 ++++---- e2e-testing/cypress/locators/DataViewLocators.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) 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 ceea133fdd..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,7 +25,7 @@ class="search-form__form-control" [ngModelOptions]="{ standalone: true }" [placeholder]="'global_filter.search' | translate" - [data-qa]="'search-form__search-posts'" + [data-qa]="'search-form-search-posts'" /> { - cy.visit(Cypress.env('baseUrl')); -}); - 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); diff --git a/e2e-testing/cypress/locators/DataViewLocators.js b/e2e-testing/cypress/locators/DataViewLocators.js index 66bca46ecb..4df340f994 100644 --- a/e2e-testing/cypress/locators/DataViewLocators.js +++ b/e2e-testing/cypress/locators/DataViewLocators.js @@ -18,7 +18,7 @@ const DataViewLocators = { publishPostBtn: '[data-qa="btn-publish-post"]', postDetails: '[data-qa="post-details"]', - searchInput: '[data-qa="search-form__search-posts"]', + searchInput: '[data-qa="search-form-search-posts"]', postsEmptyMessage: '[data-qa="posts-empty"]', }; From 82fb7466a36c46d5c6f03af55df5193083e95d03 Mon Sep 17 00:00:00 2001 From: felabel Date: Fri, 22 Nov 2024 17:33:02 +0100 Subject: [PATCH 4/7] reverted the changes in the env files --- apps/web-mzima-client/src/env.json | 4 ++-- e2e-testing/cypress.env.json | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/web-mzima-client/src/env.json b/apps/web-mzima-client/src/env.json index 92e187424a..fbf630addf 100644 --- a/apps/web-mzima-client/src/env.json +++ b/apps/web-mzima-client/src/env.json @@ -1,6 +1,6 @@ { "production": true, - "backend_url": "http://mzima-dev-api.staging.ush.zone/", + "backend_url": "http://localhost:8080/", "api_v3": "api/v3/", "api_v5": "api/v5/", "mapbox_api_key": "pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXUzeHBvMDdndmZ0bmVmOWoyMzN6NiJ9.CX56ZmZJv0aUsxvH5huJBw", @@ -13,4 +13,4 @@ "sentry_dsn": "", "sentry_environment": "", "sentry_debug_mode": false -} +} \ No newline at end of file diff --git a/e2e-testing/cypress.env.json b/e2e-testing/cypress.env.json index bb706a88bd..3b9d310bd5 100644 --- a/e2e-testing/cypress.env.json +++ b/e2e-testing/cypress.env.json @@ -1,9 +1,9 @@ { "baseUrl": "http://localhost:4200/", - "ush_admin_email": "outreachyadmin@ushahidi.com", - "ush_admin_pwd": "outreachyadmin", + "ush_admin_email": "automation_admin@ushahidi.com", + "ush_admin_pwd": "1234567", "ush_admin_name": "Automation User Admin Role", - "ush_user_email": "felicityabel99@gmail.com", - "ush_user_pwd": "12345678", + "ush_user_email": "automation_member@ushahidi.com", + "ush_user_pwd": "1234567", "ush_user_name": "Automation User Member Role" -} +} \ No newline at end of file From 3425eea3e7e53f681aae03e1d6bc1ba235e874fc Mon Sep 17 00:00:00 2001 From: felabel Date: Wed, 27 Nov 2024 16:45:37 +0100 Subject: [PATCH 5/7] updated check conditions --- .../functions/DataViewFunctions/DataViewFunctions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js index 8159adfe80..bc5d52421b 100644 --- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js +++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js @@ -46,13 +46,15 @@ class DataViewFunctions { } search_and_verify_results_with_special_characters(keyword) { const specialCharacterRegex = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?`~]+$/; + // remove if (!specialCharacterRegex.test(keyword)) { throw new Error('Provided keyword does not contain only special characters'); } - this.click_data_view_btn(); cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true }); - cy.get(DataViewLocators.postsEmptyMessage).should('be.visible'); + cy.get(DataViewLocators.postsEmptyMessage) + .should('be.visible') + .and('contain.text', 'No posts match your keyword search'); } } From d92f886e7a746d502aa4163ea610e542f7fe295f Mon Sep 17 00:00:00 2001 From: felabel Date: Wed, 27 Nov 2024 17:01:07 +0100 Subject: [PATCH 6/7] randomly generated special charcters --- .../cypress/e2e/12-data-view/data-view-search.cy.js | 11 ++++++++++- .../functions/DataViewFunctions/DataViewFunctions.js | 5 ----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js b/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js index c5a5d731dd..f022075a42 100644 --- a/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js +++ b/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js @@ -12,7 +12,16 @@ describe('Search and Verify Posts', () => { }); it('should display an empty state when searching with special characters', () => { - const specialCharKeyword = '!@#$%^&*'; + 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 bc5d52421b..397947d237 100644 --- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js +++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js @@ -45,11 +45,6 @@ class DataViewFunctions { }); } search_and_verify_results_with_special_characters(keyword) { - const specialCharacterRegex = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?`~]+$/; - // remove - if (!specialCharacterRegex.test(keyword)) { - throw new Error('Provided keyword does not contain only special characters'); - } this.click_data_view_btn(); cy.get(DataViewLocators.searchInput).clear({ force: true }).type(keyword, { force: true }); cy.get(DataViewLocators.postsEmptyMessage) From f398b90b3b56ed7bba12feed1cefc9a9fa4afe3b Mon Sep 17 00:00:00 2001 From: felabel Date: Thu, 5 Dec 2024 15:18:32 +0100 Subject: [PATCH 7/7] added the post creation step to the daview search test --- .../e2e/12-data-view/data-view-search.cy.js | 7 +++ .../DataViewFunctions/DataViewFunctions.js | 51 ++++++++++++------- .../locators/PostsLocators/PostLocators.js | 3 +- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js b/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js index f022075a42..467ac0b71a 100644 --- a/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js +++ b/e2e-testing/cypress/e2e/12-data-view/data-view-search.cy.js @@ -1,8 +1,15 @@ import DataViewFunctions from '../../functions/DataViewFunctions/DataViewFunctions'; +import LoginFunctions from '../../functions/LoginFunctions'; + const dataViewFunctions = new DataViewFunctions(); +import PostFunctions from '../../functions/PostsFunctions/PostFunctions'; describe('Search and Verify Posts', () => { + const loginFunctions = new LoginFunctions(); + const postFunctions = new PostFunctions(); + beforeEach(() => { + loginFunctions.login_as_admin(); cy.visit(Cypress.env('baseUrl')); }); diff --git a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js index 397947d237..7e96f40024 100644 --- a/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js +++ b/e2e-testing/cypress/functions/DataViewFunctions/DataViewFunctions.js @@ -1,38 +1,51 @@ +/// + 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).should('be.visible').click({ force: true }); cy.url().should('include', '/feed'); } - - verify_post_appears_for_user() { - 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 - this.click_data_view_btn(); - cy.get(DataViewLocators.postPreview) - .children(DataViewLocators.postItem) - .contains('Automated Title Response'); - } 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(); 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) => { 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"]',