From 1f6b7403870e60ca7f1f3b26336dcd9188f434d7 Mon Sep 17 00:00:00 2001 From: Aniekan Eshiet Date: Mon, 19 Aug 2024 21:12:36 +0100 Subject: [PATCH] chore(#8181): add mobile send message test (#9353) Co-authored-by: Aniekan Eshiet Co-authored-by: Maria Lorena Rodriguez Viruel --- .../reports/send-message.wdio-spec.js | 64 +++++++++++++++++++ .../default/common/common.wdio.page.js | 17 ++++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/default-mobile/reports/send-message.wdio-spec.js diff --git a/tests/e2e/default-mobile/reports/send-message.wdio-spec.js b/tests/e2e/default-mobile/reports/send-message.wdio-spec.js new file mode 100644 index 00000000000..e8071bb5647 --- /dev/null +++ b/tests/e2e/default-mobile/reports/send-message.wdio-spec.js @@ -0,0 +1,64 @@ +const utils = require('@utils'); +const placeFactory = require('@factories/cht/contacts/place'); +const userFactory = require('@factories/cht/users/users'); +const personFactory = require('@factories/cht/contacts/person'); +const loginPage = require('@page-objects/default/login/login.wdio.page'); +const commonElements = require('@page-objects/default/common/common.wdio.page'); +const reportsPage = require('@page-objects/default/reports/reports.wdio.page'); +const pregnancyFactory = require('@factories/cht/reports/pregnancy'); + +describe('Report - Send message action', () => { + const places = placeFactory.generateHierarchy(); + const healthCenter = places.get('health_center'); + const clinic = places.get('clinic'); + + const onlineUserContact = personFactory.build({ + name: 'OnlineUser', + phone: '+25475525749', + parent: { _id: healthCenter._id, parent: healthCenter.parent } + }); + + const chwContact = personFactory.build({ + _id: 'chw-contact-1', + name: 'CHW Contact', + phone: '+25475525759', + parent: { _id: clinic._id, parent: clinic.parent } + }); + + const onlineUser = userFactory.build({ + place: healthCenter._id, + roles: ['program_officer'], + contact: onlineUserContact + }); + + const person = personFactory.build({ + _id: 'patient1', + phone: '+25475525741', + name: 'patient1', + parent: { _id: clinic._id, parent: clinic.parent } + }); + + const report = pregnancyFactory.build({ + contact: chwContact, + fields: { patient_id: person._id, case_id: 'case-12' } + }); + + before(async () => { + await utils.saveDocs([...places.values(), person, chwContact]); + await utils.saveDocs([report]); + await utils.createUsers([onlineUser]); + await loginPage.login(onlineUser); + }); + + after(async () => await utils.revertSettings(true)); + + it('should display option to send message', async () => { + await commonElements.goToReports(); + const firstReport = await reportsPage.firstReport(); + await reportsPage.openSelectedReport(firstReport); + + expect(await commonElements.isReportActionDisplayed()).to.equal(true); + expect(await commonElements.reportsFastActionFAB().getAttribute('class')) + .to.include('fa-envelope'); + }); +}); diff --git a/tests/page-objects/default/common/common.wdio.page.js b/tests/page-objects/default/common/common.wdio.page.js index 387b8cac210..7772fa56cc0 100644 --- a/tests/page-objects/default/common/common.wdio.page.js +++ b/tests/page-objects/default/common/common.wdio.page.js @@ -29,6 +29,8 @@ const syncSuccess = () => $(`${hamburgerMenuItemSelector}.sync-status .success`) const syncInProgress = () => $('*="Currently syncing"'); const syncRequired = () => $(`${hamburgerMenuItemSelector}.sync-status .required`); const jsonError = async () => (await $('pre')).getText(); +const reportsContentSelector = '#reports-content'; +const reportsFastActionFAB = () => $(`${reportsContentSelector} .fast-action-fab-button mat-icon`); const actionBar = () => $('.detail-actions.right-pane'); const actionBarActions = () => $$('.detail-actions.right-pane span'); @@ -140,6 +142,17 @@ const closeFastActionList = async () => { await (await fastActionListCloseButton()).click(); }; +const isReportActionDisplayed = async () => { + return await browser.waitUntil(async () => { + const exists = await (await reportsFastActionFAB()).isExisting(); + if (exists) { + await (await reportsFastActionFAB()).waitForDisplayed(); + } + + return exists; + }); +}; + const isMessagesListPresent = () => { return isElementByIdPresent('message-list'); }; @@ -528,5 +541,7 @@ module.exports = { goToUrl, getFastActionItemsLabels, getActionBarLabels, - getErrorLog + getErrorLog, + reportsFastActionFAB, + isReportActionDisplayed };