From 61c9dc28dc815b68243b3091e3342723d44e9bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20L=C3=A9piz=20Soto?= <94494491+tatilepizs@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:43:55 -0600 Subject: [PATCH] chore(#8700): clean up and organize e2e tests folders /service-worker, /sms, /targets, /tasks (#9450) --- .../old-navigation.wdio-spec.js | 2 +- .../service-worker.wdio-spec.js | 149 ++++----- .../default/sms/africas-talking.wdio-spec.js | 14 +- tests/e2e/default/sms/export.wdio-spec.js | 12 +- tests/e2e/default/sms/gateway.wdio-spec.js | 28 +- .../default/sms/link-to-patient.wdio-spec.js | 41 +-- .../sms/messages-sender-data.wdio-spec.js | 47 +-- tests/e2e/default/sms/rapidpro.wdio-spec.js | 26 +- .../e2e/default/sms/send-message.wdio-spec.js | 13 +- .../targets/target-aggregates.wdio-spec.js | 3 - .../e2e/default/tasks/due-dates.wdio-spec.js | 80 ++--- .../tasks/tasks-breadcrumbs.wdio-spec.js | 67 ++-- .../default/tasks/tasks-group.wdio-spec.js | 296 ++++++++---------- tests/e2e/default/tasks/tasks.wdio-spec.js | 34 +- .../default/sms/messages.wdio.page.js | 18 +- .../targets/target-aggregates.wdio.page.js | 20 +- .../default/tasks/tasks.wdio.page.js | 42 +-- 17 files changed, 375 insertions(+), 517 deletions(-) diff --git a/tests/e2e/default/old-navigation/old-navigation.wdio-spec.js b/tests/e2e/default/old-navigation/old-navigation.wdio-spec.js index ae392cdd0b5..dc7aee37ad5 100644 --- a/tests/e2e/default/old-navigation/old-navigation.wdio-spec.js +++ b/tests/e2e/default/old-navigation/old-navigation.wdio-spec.js @@ -54,7 +54,7 @@ describe('Old Navigation', () => { it('should navigate to the Messages section and open a sent message', async () => { const message = 'Navigations test'; await oldNavigationPage.goToMessages(); - await messagesPage.sendMessage(message, person.name, person.phone ); + await messagesPage.sendMessageDesktop(message, person.name, person.phone ); await messagesPage.openMessage(person._id); const { name, phone } = await messagesPage.getMessageHeader(); diff --git a/tests/e2e/default/service-worker/service-worker.wdio-spec.js b/tests/e2e/default/service-worker/service-worker.wdio-spec.js index 2a34ff7ceb4..812f64bb782 100644 --- a/tests/e2e/default/service-worker/service-worker.wdio-spec.js +++ b/tests/e2e/default/service-worker/service-worker.wdio-spec.js @@ -1,98 +1,86 @@ -const { expect } = require('chai'); const URL = require('url'); const utils = require('@utils'); const loginPage = require('@page-objects/default/login/login.wdio.page'); const commonPage = require('@page-objects/default/common/common.wdio.page'); +const placeFactory = require('@factories/cht/contacts/place'); +const userFactory = require('@factories/cht/users/users'); -// global caches fetch Response navigator -const getCachedRequests = async (raw) => { - const cacheDetails = await browser.executeAsync(async (callback) => { +describe('Service worker cache', () => { + const DEFAULT_TRANSLATIONS = { + 'sync.now': 'Sync now', + 'sidebar_menu.title': 'Menu', + 'sync.status.not_required': 'All reports synced', + }; + + // global caches fetch Response navigator + const getCachedRequests = async (raw) => { + const cacheDetails = await browser.executeAsync(async (callback) => { + const cacheNames = await caches.keys(); + const cache = await caches.open(cacheNames[0]); + const cachedRequests = await cache.keys(); + const cachedRequestSummary = cachedRequests.map(req => ({ url: req.url })); + callback({ + name: cacheNames[0], + requests: cachedRequestSummary, + }); + }); + + if (raw) { + return cacheDetails; + } + + const urls = cacheDetails.requests.map(request => URL.parse(request.url).pathname); + urls.sort(); + return { name: cacheDetails.name, urls }; + }; + + const stubAllCachedRequests = () => browser.executeAsync(async (callback) => { const cacheNames = await caches.keys(); const cache = await caches.open(cacheNames[0]); const cachedRequests = await cache.keys(); - const cachedRequestSummary = cachedRequests.map(req => ({ url: req.url })); + await Promise.all(cachedRequests.map(request => cache.put(request, new Response('cache')))); + callback(); + }); + + const doFetch = (path, headers) => browser.executeAsync(async (innerPath, innerHeaders, callback) => { + const result = await fetch(innerPath, { headers: innerHeaders }); callback({ - name: cacheNames[0], - requests: cachedRequestSummary, + body: await result.text(), + ok: result.ok, + status: result.status, }); - }); + }, path, headers); - if (raw) { - return cacheDetails; - } - - const urls = cacheDetails.requests.map(request => URL.parse(request.url).pathname); - urls.sort(); - return { name: cacheDetails.name, urls }; -}; - -const stubAllCachedRequests = () => browser.executeAsync(async (callback) => { - const cacheNames = await caches.keys(); - const cache = await caches.open(cacheNames[0]); - const cachedRequests = await cache.keys(); - await Promise.all(cachedRequests.map(request => cache.put(request, new Response('cache')))); - callback(); -}); + const unregisterServiceWorkerAndWipeAllCaches = () => browser.executeAsync(async (callback) => { + const registrations = await navigator.serviceWorker.getRegistrations(); + registrations.forEach(registration => registration.unregister()); -const doFetch = (path, headers) => browser.executeAsync(async (innerPath, innerHeaders, callback) => { - const result = await fetch(innerPath, { headers: innerHeaders }); - callback({ - body: await result.text(), - ok: result.ok, - status: result.status, - }); -}, path, headers); + const cacheNames = await caches.keys(); + for (const name of cacheNames) { + await caches.delete(name); + } -const unregisterServiceWorkerAndWipeAllCaches = () => browser.executeAsync(async (callback) => { - const registrations = await navigator.serviceWorker.getRegistrations(); - registrations.forEach(registration => registration.unregister()); + callback(); + }); - const cacheNames = await caches.keys(); - for (const name of cacheNames) { - await caches.delete(name); - } + const district = placeFactory.generateHierarchy(['district_hospital']).get('district_hospital'); + const chw = userFactory.build({ place: district._id }); - callback(); -}); + const login = async () => { + await browser.throttle('online'); + await loginPage.login(chw); + await commonPage.waitForPageLoaded(); + }; -const district = { - _id: 'fixture:district', - type: 'district_hospital', - name: 'District', - place_id: 'district', - reported_date: new Date().getTime(), -}; - -const chw = { - username: 'bob', - password: 'medic.123', - place: 'fixture:district', - contact: { _id: 'fixture:user:bob', name: 'Bob' }, - roles: ['chw'], -}; - -const login = async () => { - await browser.throttle('online'); - await loginPage.login(chw); - await commonPage.waitForPageLoaded(); -}; - -const isLoggedIn = async () => { - const tab = await commonPage.messagesTab(); - return await tab.isExisting(); -}; - -const loginIfNeeded = async () => { - if (!await isLoggedIn()) { - await login(); - } -}; + const isLoggedIn = async () => { + const tab = await commonPage.messagesTab(); + return await tab.isExisting(); + }; -describe('Service worker cache', () => { - const DEFAULT_TRANSLATIONS = { - 'sync.now': 'Sync now', - 'sidebar_menu.title': 'Menu', - 'sync.status.not_required': 'All reports synced', + const loginIfNeeded = async () => { + if (!await isLoggedIn()) { + await login(); + } }; before(async () => { @@ -105,8 +93,9 @@ describe('Service worker cache', () => { await loginIfNeeded(); }); - afterEach(async () => { - await utils.revertSettings(true); + after(async () => { + await utils.deleteUsers([chw]); + await utils.revertDb([/^form:/], true); }); it('confirm initial list of cached resources', async () => { diff --git a/tests/e2e/default/sms/africas-talking.wdio-spec.js b/tests/e2e/default/sms/africas-talking.wdio-spec.js index 5f9bf4415c0..303fbd992d5 100644 --- a/tests/e2e/default/sms/africas-talking.wdio-spec.js +++ b/tests/e2e/default/sms/africas-talking.wdio-spec.js @@ -6,13 +6,13 @@ const loginPage = require('@page-objects//default/login/login.wdio.page'); const reportsPage = require('@page-objects/default/reports/reports.wdio.page'); const smsPregnancy = require('@factories/cht/reports/sms-pregnancy'); -const CREDENTIAL_PASS = 'yabbadabbadoo'; -const CREDENTIAL_KEY = 'africastalking.com:incoming'; +describe('Africas Talking api', () => { + const CREDENTIAL_PASS = 'yabbadabbadoo'; + const CREDENTIAL_KEY = 'africastalking.com:incoming'; -describe('africas talking api', () => { before( () => utils.saveCredentials(CREDENTIAL_KEY, CREDENTIAL_PASS) ); - describe('- gateway submits new WT sms messages', () => { + describe('Gateway submits new WT sms messages', () => { const submitSms = body => { const content = querystring.stringify(body); return utils.request({ @@ -32,7 +32,7 @@ describe('africas talking api', () => { await loginPage.cookieLogin(); }); - it('- shows content', async () => { + it('should shows content', async () => { const rawNumber = '+64271234567'; const message = 'Hello'; @@ -55,7 +55,7 @@ describe('africas talking api', () => { }); - describe('- gateway submits WT sms status updates', () => { + describe('Gateway submits WT sms status updates', () => { let savedDoc; let testReport; @@ -92,7 +92,7 @@ describe('africas talking api', () => { afterEach(() => utils.deleteDoc(savedDoc)); - it('- shows content', async () => { + it('should shows content', async () => { await commonPage.goToReports(); const firstReport = await reportsPage.leftPanelSelectors.firstReport(); const firstReportInfo = await reportsPage.getListReportInfo(firstReport); diff --git a/tests/e2e/default/sms/export.wdio-spec.js b/tests/e2e/default/sms/export.wdio-spec.js index 0e55e8f364b..930e5e0fe16 100644 --- a/tests/e2e/default/sms/export.wdio-spec.js +++ b/tests/e2e/default/sms/export.wdio-spec.js @@ -1,5 +1,5 @@ const moment = require('moment'); - +const utils = require('@utils'); const messagesPage = require('@page-objects/default/sms/messages.wdio.page'); const userFactory = require('@factories/cht/users/users'); const placeFactory = require('@factories/cht/contacts/place'); @@ -7,7 +7,6 @@ const personFactory = require('@factories/cht/contacts/person'); const commonElements = require('@page-objects/default/common/common.wdio.page'); const loginPage = require('@page-objects/default/login/login.wdio.page'); const fileDownloadUtils = require('@utils/file-download'); -const utils = require('@utils'); describe('Export Messages', () => { const places = placeFactory.generateHierarchy(); @@ -28,8 +27,13 @@ describe('Export Messages', () => { await commonElements.goToMessages(); }); - it('Should download export file', async () => { - await messagesPage.sendMessage('It is working!', patient.phone, patient.name); + after(async () => { + await utils.deleteUsers([onlineUser]); + await utils.revertDb([/^form:/], true); + }); + + it('should download export file', async () => { + await messagesPage.sendMessageDesktop('It is working!', patient.phone, patient.name); await messagesPage.exportMessages(); const files = await fileDownloadUtils.waitForDownload(`messages-${today.format('YYYYMMDD')}`); diff --git a/tests/e2e/default/sms/gateway.wdio-spec.js b/tests/e2e/default/sms/gateway.wdio-spec.js index 4346d1f2e43..b6c1efabdbc 100644 --- a/tests/e2e/default/sms/gateway.wdio-spec.js +++ b/tests/e2e/default/sms/gateway.wdio-spec.js @@ -5,21 +5,21 @@ const commonElements = require('@page-objects/default/common/common.wdio.page'); const loginPage = require('@page-objects/default/login/login.wdio.page'); const smsPregnancy = require('@factories/cht/reports/sms-pregnancy'); -const pollSmsApi = body => { - return utils.request({ - method: 'POST', - path: '/api/sms', - body: body - }); -}; - describe('sms-gateway api', () => { + const pollSmsApi = body => { + return utils.request({ + method: 'POST', + path: '/api/sms', + body: body + }); + }; + before(async () => { await loginPage.cookieLogin(); await commonElements.waitForPageLoaded(); }); - describe('- gateway submits new WT sms messages', () => { + describe('Gateway submits new WT sms messages', () => { beforeEach(async () => { const body = { messages: [ @@ -33,7 +33,7 @@ describe('sms-gateway api', () => { await pollSmsApi(body); }); - it('shows content', async () => { + it('should shows content', async () => { //LHS const phone = '+64271234567'; const msg = 'hello'; @@ -53,7 +53,7 @@ describe('sms-gateway api', () => { }); }); - describe('- gateway submits WT sms status updates', () => { + describe('Gateway submits WT sms status updates', () => { let savedDoc; beforeEach(async () => { @@ -74,7 +74,7 @@ describe('sms-gateway api', () => { await pollSmsApi(body); }); - it('- shows content', async () => { + it('should shows content', async () => { await reportsPage.goToReportById(savedDoc); @@ -90,7 +90,7 @@ describe('sms-gateway api', () => { }); }); - describe('- api returns list of pending WO messages', () => { + describe('api returns list of pending WO messages', () => { let savedDoc; let response; let reportWithTwoMessagesToSend; @@ -109,7 +109,7 @@ describe('sms-gateway api', () => { response = await pollSmsApi({}); }); - it('- returns list and updates state', async () => { + it('should returns list and updates state', async () => { const scheduledTaskMessage = reportWithTwoMessagesToSend.scheduled_tasks[0].messages[0]; const taskMessage = reportWithTwoMessagesToSend.tasks[0].messages[0]; expect(response.messages.length).to.equal(2); diff --git a/tests/e2e/default/sms/link-to-patient.wdio-spec.js b/tests/e2e/default/sms/link-to-patient.wdio-spec.js index 79b7a0fdda1..6f864970532 100644 --- a/tests/e2e/default/sms/link-to-patient.wdio-spec.js +++ b/tests/e2e/default/sms/link-to-patient.wdio-spec.js @@ -7,40 +7,31 @@ const commonPage = require('@page-objects/default/common/common.wdio.page'); const contactPage = require('@page-objects/default/contacts/contacts.wdio.page'); const sentinelUtils = require('@utils/sentinel'); -const formId = 'CASEID'; -const formTitle = 'Case Id Form'; - -const places = placeFactory.generateHierarchy(); -const hcId = places.get('health_center')._id; - -const user = userFactory.build({ place: hcId }); - -const forms = { - CASEID: { - meta: { code: formId, icon: 'icon-healthcare', translation_key: formTitle }, - fields: {} - } -}; - -const registrations = [{ - form: formId, events: [{ name: 'on_create', trigger: 'add_case' }] -}]; - -const transitions = { - self_report: true -}; +describe('Link SMS to patient without passing id', () => { + const formId = 'CASEID'; + const formTitle = 'Case Id Form'; -const self_report = [{ form: formId }]; + const places = placeFactory.generateHierarchy(); + const hcId = places.get('health_center')._id; + const user = userFactory.build({ place: hcId }); -const docs = [...places.values(), user]; + const forms = { CASEID: { meta: { code: formId, icon: 'icon-healthcare', translation_key: formTitle }, fields: {} } }; + const registrations = [{ form: formId, events: [{ name: 'on_create', trigger: 'add_case' }] }]; + const transitions = { self_report: true }; + const self_report = [{ form: formId }]; + const docs = [...places.values(), user]; -describe('Link SMS to patient without passing id', () => { before(async () => { await utils.saveDocs(docs); await utils.updateSettings({ forms, registrations, transitions, self_report }, { ignoreReload: true }); await loginPage.cookieLogin(); }); + after(async () => { + await utils.revertSettings(true); + await utils.revertDb([/^form:/], true); + }); + it('Send SMS without patient_id and report created under person', async () => { await utils.createUsers([user]); await sentinelUtils.waitForSentinel(); diff --git a/tests/e2e/default/sms/messages-sender-data.wdio-spec.js b/tests/e2e/default/sms/messages-sender-data.wdio-spec.js index 393b2050c8f..e610a647144 100644 --- a/tests/e2e/default/sms/messages-sender-data.wdio-spec.js +++ b/tests/e2e/default/sms/messages-sender-data.wdio-spec.js @@ -16,45 +16,28 @@ describe('Message Tab - Sender Data', () => { const healthCenter2 = placeFactory.place().build({ name: 'health_center_2', type: 'health_center', - parent: { _id: districtHospital._id }, + parent: { _id: districtHospital._id } }); - const offlineUserContact = { - _id: 'fixture:user:user1', - name: 'OfflineUser', - phone: '+12068881234', - place: healthCenter1._id, - type: 'person', - parent: { _id: healthCenter1._id, parent: healthCenter1.parent }, - }; - const onlineUserContact = { - _id: 'fixture:user:user2', - name: 'OnlineUser', - phone: '+12068881235', - place: districtHospital._id, - type: 'person', - parent: { _id: districtHospital._id }, - }; + const offlineUser = userFactory.build({ username: 'offlineuser_messages', isOffline: true, place: healthCenter1._id, - contact: offlineUserContact._id, + contact: personFactory.build({ name: 'OfflineUser', phone: '+12068881234', parent: healthCenter1 }) }); const onlineUser = userFactory.build({ username: 'onlineuser_messages', roles: [ 'program_officer' ], place: districtHospital._id, - contact: onlineUserContact._id, - }); - const patient = personFactory.build({ - _id: 'patient1', - phone: '+14152223344', - name: 'patient1', - parent: { _id: clinic._id, parent: { _id: healthCenter1._id, parent: { _id: districtHospital._id }}} + contact: personFactory.build({ name: 'OnlineUser', phone: '+12068881235', parent: districtHospital }) }); + + const patient = personFactory.build({ phone: '+14152223344', name: 'patient1', parent: clinic }); + const contactWithManyPlaces = personFactory.build({ parent: { _id: healthCenter1._id, parent: { _id: districtHospital._id } }, }); + const userWithManyPlaces = { _id: 'org.couchdb.user:offline_many_facilities', language: 'en', @@ -68,10 +51,7 @@ describe('Message Tab - Sender Data', () => { const userWithManyPlacesPass = uuid(); before(async () => { - await utils.saveDocs([ - ...places.values(), healthCenter2, offlineUserContact, onlineUserContact, patient, - contactWithManyPlaces, userWithManyPlaces, - ]); + await utils.saveDocs([ ...places.values(), healthCenter2, patient, contactWithManyPlaces, userWithManyPlaces ]); await utils.request({ path: `/_users/${userWithManyPlaces._id}`, method: 'PUT', @@ -80,6 +60,11 @@ describe('Message Tab - Sender Data', () => { await utils.createUsers([ onlineUser, offlineUser ]); }); + after(async () => { + await utils.deleteUsers([ onlineUser, offlineUser ]); + await utils.revertDb([/^form:/], true); + }); + afterEach(async () => { await commonElements.logout(); }); @@ -88,7 +73,7 @@ describe('Message Tab - Sender Data', () => { await loginPage.login(onlineUser); await commonElements.waitForPageLoaded(); await commonElements.goToMessages(); - await messagesPage.sendMessage('Contact', patient.phone, patient.name); + await messagesPage.sendMessageDesktop('Contact', patient.phone, patient.name); const { lineage} = await messagesPage.getMessageInListDetails(patient._id); const expectedLineage = clinic.name.concat(healthCenter1.name, districtHospital.name); @@ -100,7 +85,7 @@ describe('Message Tab - Sender Data', () => { await loginPage.login({ password: userWithManyPlacesPass, username: userWithManyPlaces.name }); await commonElements.waitForPageLoaded(); await commonElements.goToMessages(); - await messagesPage.sendMessage('Contact', patient.phone, patient.name); + await messagesPage.sendMessageDesktop('Contact', patient.phone, patient.name); const { lineage} = await messagesPage.getMessageInListDetails(patient._id); const expectedLineage = clinic.name.concat(healthCenter1.name); diff --git a/tests/e2e/default/sms/rapidpro.wdio-spec.js b/tests/e2e/default/sms/rapidpro.wdio-spec.js index 2e4eeb1f5fc..eb8424a7fcb 100644 --- a/tests/e2e/default/sms/rapidpro.wdio-spec.js +++ b/tests/e2e/default/sms/rapidpro.wdio-spec.js @@ -43,17 +43,17 @@ describe('RapidPro SMS Gateway', () => { before(() => startMockApp()); - after(() => { - stopMockApp(); - utils.revertDb([/^form:/], true); - }); - beforeEach(() => { broadcastsEndpointRequests = []; messagesEndpointRequests = []; }); - afterEach(() => utils.revertDb([/^form:/], true)); + after(() => stopMockApp() ); + + afterEach(async () => { + await utils.revertDb([/^form:/], true); + await utils.revertSettings(true); + }); describe('Webapp Terminating messages', () => { const endpoint = '/api/v2/sms/rapidpro/incoming-messages'; @@ -259,14 +259,8 @@ describe('RapidPro SMS Gateway', () => { const pregnancyReportWithTasks = pregnancyReportFactory.pregnancy().build({ tasks: [ - { - messages: [{ to: 'phone1', message: 'message1', uuid: 'uuid1' }], - state: 'pending', - }, - { - messages: [{ to: 'phone2', message: 'message2', uuid: 'uuid2' }], - state: 'sent', - }, + { messages: [{ to: 'phone1', message: 'message1', uuid: 'uuid1' }], state: 'pending' }, + { messages: [{ to: 'phone2', message: 'message2', uuid: 'uuid2' }], state: 'sent' }, ], scheduled_tasks: [ { @@ -300,9 +294,6 @@ describe('RapidPro SMS Gateway', () => { await utils.updateSettings(settings, { ignoreReload: true }); }); - afterEach(() => utils.revertDb([], true)); - - it('should not call RapidPro endpoint when credentials are not set', async () => { await utils.saveDoc(pregnancyReportWithTasks); await browser.pause(1200); // interval to check the queue should run every second @@ -588,4 +579,3 @@ describe('RapidPro SMS Gateway', () => { }); //End describe 'Webapp originating messages and state updates' }); - diff --git a/tests/e2e/default/sms/send-message.wdio-spec.js b/tests/e2e/default/sms/send-message.wdio-spec.js index c8b7c52ec8f..3c1b54c431d 100644 --- a/tests/e2e/default/sms/send-message.wdio-spec.js +++ b/tests/e2e/default/sms/send-message.wdio-spec.js @@ -22,7 +22,7 @@ describe('Send message', () => { parent: {_id: healthCenter._id, parent: healthCenter.parent} }); - const offlineUser = userFactory.build({ place: healthCenter._id, roles: ['chw'], contact: anne }); + const offlineUser = userFactory.build({ place: healthCenter._id, contact: anne }); const smsMsg = (person, type = 'regular') => `Test SMS - ${person} - ${type}`; @@ -57,8 +57,13 @@ describe('Send message', () => { await commonPage.waitForPageLoaded(); }); + after(async () => { + await utils.deleteUsers([offlineUser]); + await utils.revertDb([/^form:/], true); + }); + it('should send messages to all the contacts, under a place, that have a primary phone number assigned', async () => { - await messagesPage.sendMessage( + await messagesPage.sendMessageDesktop( smsMsg(healthCenter.name), healthCenter.name, `${healthCenter.name} - all` @@ -76,14 +81,14 @@ describe('Send message', () => { }); it('should send a message to a raw phone number', async () => { - await messagesPage.sendMessage(smsMsg('raw'), rawNumber, rawNumber); + await messagesPage.sendMessageDesktop(smsMsg('raw'), rawNumber, rawNumber); await messagesPage.openMessage(rawNumber); await verifyMessageHeader(rawNumber, ''); await verifyLastSmsContent('raw'); }); it('should send a message to a contact with a phone number', async () => { - await messagesPage.sendMessage(smsMsg(anne.name), anne.name, anne.phone); + await messagesPage.sendMessageDesktop(smsMsg(anne.name), anne.name, anne.phone); await messagesPage.openMessage(anne._id); await verifyMessageHeader(anne.name, anne.phone); await verifyLastSmsContent(anne.name, 'regular'); diff --git a/tests/e2e/default/targets/target-aggregates.wdio-spec.js b/tests/e2e/default/targets/target-aggregates.wdio-spec.js index ed228ec25fe..159f1aea028 100644 --- a/tests/e2e/default/targets/target-aggregates.wdio-spec.js +++ b/tests/e2e/default/targets/target-aggregates.wdio-spec.js @@ -15,7 +15,6 @@ const helperFunctions = require('./utils/aggregates-helper-functions'); const targetAggregatesConfig = require('./config/target-aggregates'); describe('Target aggregates', () => { - describe('DB admin', () => { before(async () => await loginPage.cookieLogin()); @@ -412,8 +411,6 @@ describe('Target aggregates', () => { context.isCurrentPeriod = true; await helperFunctions.assertData(context, TARGET_VALUES_BY_CONTACT, expectedTargets, asserts); }); - }); - }); }); diff --git a/tests/e2e/default/tasks/due-dates.wdio-spec.js b/tests/e2e/default/tasks/due-dates.wdio-spec.js index 55a95579588..2faeff96317 100644 --- a/tests/e2e/default/tasks/due-dates.wdio-spec.js +++ b/tests/e2e/default/tasks/due-dates.wdio-spec.js @@ -1,65 +1,41 @@ const path = require('path'); - const utils = require('@utils'); const sentinelUtils = require('@utils/sentinel'); const tasksPage = require('@page-objects/default/tasks/tasks.wdio.page'); const loginPage = require('@page-objects/default/login/login.wdio.page'); const commonPage = require('@page-objects/default/common/common.wdio.page'); const chtConfUtils = require('@utils/cht-conf'); - -const contacts = [ - { - _id: 'fixture:district', - type: 'district_hospital', - name: 'District', - place_id: 'district', - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:center', - type: 'health_center', - name: 'Health Center', - parent: { _id: 'fixture:district' }, - place_id: 'health_center', - reported_date: new Date().getTime(), - }, -]; - -const chw = { - username: 'bob', - password: 'medic.123', - place: 'fixture:center', - contact: { _id: 'fixture:user:bob', name: 'Bob' }, - roles: ['chw'], -}; - -const getTasksInfos = async (tasks) => { - const infos = []; - for (const task of tasks) { - infos.push(await tasksPage.getTaskInfo(task)); - } - return infos; -}; - -const updateDueDatesSettings = async (updates = {}) => { - await chtConfUtils.initializeConfigDir(); - const tasksFilePath = path.join(__dirname, 'config/due-dates-config.js'); - - const { tasks } = await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath }); - updates.tasks = tasks; - await utils.updateSettings(updates, { ignoreReload: 'api', sync: true, refresh: true }); -}; +const placeFactory = require('@factories/cht/contacts/place'); +const userFactory = require('@factories/cht/users/users'); describe('Task list due dates', () => { + const places = placeFactory.generateHierarchy(); + const healthCenter = places.get('health_center'); + const chw = userFactory.build({ place: healthCenter._id, contact: { _id: 'fixture:user:bob', name: 'Bob' } }); + + const updateDueDatesSettings = async (updates = {}) => { + await chtConfUtils.initializeConfigDir(); + const tasksFilePath = path.join(__dirname, 'config/due-dates-config.js'); + + const { tasks } = await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath }); + updates.tasks = tasks; + await utils.updateSettings(updates, { ignoreReload: 'api', sync: true, refresh: true }); + }; + before(async () => { - await utils.saveDocs(contacts); + await utils.saveDocs([...places.values()]); await utils.createUsers([ chw ]); await sentinelUtils.waitForSentinel(); - await loginPage.login({ username: chw.username, password: chw.password }); + await loginPage.login(chw); await (await commonPage.analyticsTab()).waitForDisplayed(); }); + after(async () => { + await utils.deleteUsers([ chw ]); + await utils.revertDb([/^form:/], true); + }); + afterEach(async () => { await utils.revertSettings(true); }); @@ -67,8 +43,8 @@ describe('Task list due dates', () => { it('should display correct due dates with default settings', async () => { await updateDueDatesSettings(); - await tasksPage.goToTasksTab(); - const infos = await getTasksInfos(await tasksPage.getTasks()); + await commonPage.goToTasks(); + const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ { contactName: 'Bob', formTitle: 'person_create_7', dueDateText: '', overdue: false, lineage: '' }, @@ -103,8 +79,8 @@ describe('Task list due dates', () => { it('should display correct due dates with taskDaysOverdue setting', async () => { await updateDueDatesSettings({ task_days_overdue: true }); - await tasksPage.goToTasksTab(); - const infos = await getTasksInfos(await tasksPage.getTasks()); + await commonPage.goToTasks(); + const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ { contactName: 'Bob', formTitle: 'person_create_7', dueDateText: '', overdue: false, lineage: '' }, @@ -140,8 +116,8 @@ describe('Task list due dates', () => { await utils.addTranslations('en', { 'task.overdue.days': 'Late' }); await updateDueDatesSettings({ task_days_overdue: true }); - await tasksPage.goToTasksTab(); - const infos = await getTasksInfos(await tasksPage.getTasks()); + await commonPage.goToTasks(); + const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ { contactName: 'Bob', formTitle: 'person_create_7', dueDateText: '', overdue: false, lineage: '' }, diff --git a/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js b/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js index 91b3e4fe06a..351c55b03e3 100644 --- a/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js +++ b/tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js @@ -1,6 +1,5 @@ const { v4: uuid } = require('uuid'); const path = require('path'); - const utils = require('@utils'); const loginPage = require('@page-objects/default/login/login.wdio.page'); const userFactory = require('@factories/cht/users/users'); @@ -13,7 +12,6 @@ const commonPage = require('@page-objects/default/common/common.wdio.page'); const commonElements = require('@page-objects/default/common/common.wdio.page'); describe('Tasks tab breadcrumbs', () => { - const places = placeFactory.generateHierarchy(); const clinic = places.get('clinic'); const healthCenter1 = places.get('health_center'); @@ -23,27 +21,22 @@ describe('Tasks tab breadcrumbs', () => { type: 'health_center', parent: { _id: districtHospital._id }, }); - const chwContact = { - _id: 'fixture:user:user1', + + const chwContact = personFactory.build({ name: 'chw', phone: '+12068881234', - type: 'person', place: healthCenter1._id, - parent: { - _id: healthCenter1._id, - parent: healthCenter1.parent - }, - }; - const supervisorContact = { - _id: 'fixture:user:user2', + parent: healthCenter1, + reported_date: '' + }); + const supervisorContact = personFactory.build({ name: 'supervisor', phone: '+12068881235', - type: 'person', place: districtHospital._id, - parent: { - _id: districtHospital._id, - }, - }; + parent: districtHospital, + reported_date: '' + }); + const chw = userFactory.build({ username: 'offlineuser_tasks', isOffline: true, @@ -56,25 +49,11 @@ describe('Tasks tab breadcrumbs', () => { place: districtHospital._id, contact: supervisorContact._id, }); - const patient = personFactory.build({ - _id: 'patient1', - name: 'patient1', - type: 'person', - patient_id: 'patient1', - parent: { _id: clinic._id, parent: { _id: healthCenter1._id, parent: { _id: districtHospital._id }}}, - reported_date: new Date().getTime(), - }); - const patient2 = personFactory.build({ - _id: 'patient2', - name: 'patient2', - type: 'person', - patient_id: 'patient2', - parent: { _id: healthCenter1._id, parent: { _id: districtHospital._id }}, - reported_date: new Date().getTime(), - }); - const contactWithManyPlaces = personFactory.build({ - parent: { _id: healthCenter1._id, parent: { _id: districtHospital._id } }, - }); + + const patient = personFactory.build({ name: 'patient1', type: 'person', parent: clinic }); + const patient2 = personFactory.build({ name: 'patient2', patient_id: 'patient2', parent: healthCenter1 }); + const contactWithManyPlaces = personFactory.build({ parent: healthCenter1 }); + const userWithManyPlaces = { _id: 'org.couchdb.user:offline_many_facilities', language: 'en', @@ -110,6 +89,12 @@ describe('Tasks tab breadcrumbs', () => { await utils.updateSettings({ tasks }, { ignoreReload: 'api' }); }); + after(async () => { + await utils.deleteUsers([ chw, supervisor ]); + await utils.revertDb([/^form:/], true); + await utils.revertSettings(true); + }); + describe('for chw', () => { afterEach(async () => await commonElements.logout()); @@ -121,7 +106,7 @@ describe('Tasks tab breadcrumbs', () => { it('should not remove facility from breadcrumbs when offline user has many facilities associated', async () => { await loginPage.login({ password: userWithManyPlacesPass, username: userWithManyPlaces.name }); await commonPage.waitForPageLoaded(); - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ @@ -152,7 +137,7 @@ describe('Tasks tab breadcrumbs', () => { it('should display correct tasks with breadcrumbs for chw', async () => { await loginPage.login(chw); await commonPage.waitForPageLoaded(); - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ @@ -183,7 +168,7 @@ describe('Tasks tab breadcrumbs', () => { it('should open task with expression', async () => { await loginPage.login(chw); await commonPage.waitForPageLoaded(); - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const task = await tasksPage.getTaskByContactAndForm('patient1', 'person_create'); await task.click(); await tasksPage.waitForTaskContentLoaded('Home Visit'); @@ -201,7 +186,7 @@ describe('Tasks tab breadcrumbs', () => { }); it('should display correct tasks with breadcrumbs for supervisor', async () => { - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const infos = await tasksPage.getTasksListInfos(await tasksPage.getTasks()); expect(infos).to.have.deep.members([ @@ -230,5 +215,3 @@ describe('Tasks tab breadcrumbs', () => { }); }); }); - - diff --git a/tests/e2e/default/tasks/tasks-group.wdio-spec.js b/tests/e2e/default/tasks/tasks-group.wdio-spec.js index f5e39b5a513..c3dec57aeb2 100644 --- a/tests/e2e/default/tasks/tasks-group.wdio-spec.js +++ b/tests/e2e/default/tasks/tasks-group.wdio-spec.js @@ -1,5 +1,4 @@ const path = require('path'); - const utils = require('@utils'); const sentinelUtils = require('@utils/sentinel'); const tasksPage = require('@page-objects/default/tasks/tasks.wdio.page'); @@ -9,172 +8,131 @@ const contactsPage = require('@page-objects/default/contacts/contacts.wdio.page' const chtConfUtils = require('@utils/cht-conf'); const modalPage = require('@page-objects/default/common/modal.wdio.page'); const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page'); +const placeFactory = require('@factories/cht/contacts/place'); +const personFactory = require('@factories/cht/contacts/person'); +const userFactory = require('@factories/cht/users/users'); + +describe('Tasks group landing page', () => { + const todayDate = Date.now(); + + const places = placeFactory.generateHierarchy(['district_hospital', 'health_center']); + const healthCenter = places.get('health_center'); -const places = [ - { - _id: 'fixture:district', - type: 'district_hospital', - name: 'District', - place_id: 'district', - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:center', - type: 'health_center', - name: 'Health Center', - parent: { _id: 'fixture:district' }, - place_id: 'health_center', - reported_date: new Date().getTime(), - }, -]; - -const clinics = [ - { - _id: 'fixture:politicians', + const politiciansClinic = placeFactory.place().build({ type: 'clinic', name: 'Politicians', - parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' } }, - place_id: 'politicians', - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:artists', + parent: healthCenter, + reported_date: todayDate + }); + const artistClinic = placeFactory.place().build({ type: 'clinic', name: 'Artists', - parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' } }, - place_id: 'artists', - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:scientists', + parent: healthCenter, + reported_date: todayDate, + }); + const scientistsClinic = placeFactory.place().build({ type: 'clinic', name: 'Scientists', - parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' } }, - place_id: 'scientists', - reported_date: new Date().getTime(), - }, -]; - -const people = [ - { - _id: 'fixture:einstein', - name: 'Albert Einstenin', - type: 'person', - patient_id: 'einstein', - parent: { _id: 'fixture:scientists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:darwin', - name: 'Charles Darwin', - type: 'person', - patient_id: 'darwin', - parent: { _id: 'fixture:scientists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:tesla', - name: 'Nikola Tesla', - type: 'person', - patient_id: 'tesla', - parent: { _id: 'fixture:scientists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:leonardo', - name: 'Leonardo da Vinci', - type: 'person', - patient_id: 'leonardo', - parent: { _id: 'fixture:artists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:goya', - name: 'Francisco Goya', - type: 'person', - patient_id: 'goya', - parent: { _id: 'fixture:artists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:mozart', - name: 'Wolfgang Amadeus Mozart', - type: 'person', - patient_id: 'mozart', - parent: { _id: 'fixture:artists', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:napoleon', - name: 'Napoleon Bonaparte', - type: 'person', - patient_id: 'napoleon', - parent: { _id: 'fixture:politicians', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:caesar', - name: 'Julius Caesar', - type: 'person', - patient_id: 'caesar', - parent: { _id: 'fixture:politicians', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, - { - _id: 'fixture:victoria', - name: 'Queen Victoria', - type: 'person', - patient_id: 'victoria', - parent: { _id: 'fixture:politicians', parent: { _id: 'fixture:center', parent: { _id: 'fixture:district' }}}, - reported_date: new Date().getTime(), - }, -]; - -const chw = { - username: 'bob', - password: 'medic.123', - place: 'fixture:center', - contact: { _id: 'fixture:user:bob', name: 'Bob' }, - roles: ['chw'], - known: true, -}; - -const supervisor = { - username: 'super', - password: 'medic.123', - place: 'fixture:center', - contact: { _id: 'fixture:user:super', name: 'Nemo' }, - roles: ['chw_supervisor'], - known: true, -}; - -const getTaskNamesAndTitles = async (tasks) => { - const tasksNamesAndTitles = []; - for (const task of tasks) { - const { contactName, formTitle } = await tasksPage.getTaskInfo(task); - tasksNamesAndTitles.push({ contactName, formTitle }); - } - return tasksNamesAndTitles; -}; - -const getGroupTasksNamesAndTitles = async () => { - const groupTasks = await tasksPage.getTasksInGroup(); - return getTaskNamesAndTitles(groupTasks); -}; - -const expectTasksGroupLeaveModal = async () => { - await (await modalPage.body()).waitForClickable(); - expect(await (await modalPage.body()).getText()).to.equal( - 'Are you sure you want to leave this page? You will no longer be able to see this household\'s other tasks.' - ); - // modals have an animation, so clicking immediately on any of the buttons, mid animation, might cause the click to - // land in a different place, instead of the button. So wait for the animation to finish... - await browser.pause(500); -}; + parent: healthCenter, + reported_date: todayDate, + }); + + const people = [ + personFactory.build({ + name: 'Albert Einstein', + patient_id: 'einstein', + parent: scientistsClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Charles Darwin', + patient_id: 'darwin', + parent: scientistsClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Nikola Tesla', + patient_id: 'tesla', + parent: scientistsClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Leonardo da Vinci', + patient_id: 'leonardo', + parent: artistClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Francisco Goya', + patient_id: 'goya', + parent: artistClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Wolfgang Amadeus Mozart', + patient_id: 'mozart', + parent: artistClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Napoleon Bonaparte', + patient_id: 'napoleon', + parent: politiciansClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Julius Caesar', + patient_id: 'caesar', + parent: politiciansClinic, + reported_date: todayDate + }), + personFactory.build({ + name: 'Queen Victoria', + patient_id: 'victoria', + parent: politiciansClinic, + reported_date: todayDate + }), + ]; + + const chw = userFactory.build({ + username: 'bob', + place: healthCenter._id, + contact: { _id: 'fixture:user:bob', name: 'Bob' } + }); + + const supervisor = userFactory.build({ + username: 'super', + place: healthCenter._id, + contact: { _id: 'fixture:user:super', name: 'Nemo' }, + roles: ['chw_supervisor'], + }); + + const getTaskNamesAndTitles = async (tasks) => { + const tasksNamesAndTitles = []; + for (const task of tasks) { + const { contactName, formTitle } = await tasksPage.getTaskInfo(task); + tasksNamesAndTitles.push({ contactName, formTitle }); + } + return tasksNamesAndTitles; + }; + + const getGroupTasksNamesAndTitles = async () => { + const groupTasks = await tasksPage.getTasksInGroup(); + return getTaskNamesAndTitles(groupTasks); + }; + + const expectTasksGroupLeaveModal = async () => { + await (await modalPage.body()).waitForClickable(); + expect(await (await modalPage.body()).getText()).to.equal( + 'Are you sure you want to leave this page? You will no longer be able to see this household\'s other tasks.' + ); + // modals have an animation, so clicking immediately on any of the buttons, mid animation, might cause the click to + // land in a different place, instead of the button. So wait for the animation to finish... + await browser.pause(500); + }; -describe('Tasks group landing page', () => { before(async () => { - await utils.saveDocs([...places, ...clinics, ...people]); + await utils.saveDocs([...places.values(), politiciansClinic, artistClinic, scientistsClinic, ...people.values()]); await utils.createUsers([chw, supervisor]); await sentinelUtils.waitForSentinel(); @@ -188,9 +146,15 @@ describe('Tasks group landing page', () => { await utils.updateSettings({ tasks }, { ignoreReload: 'api' }); }); + after(async () => { + await utils.deleteUsers([ chw, supervisor ]); + await utils.revertDb([/^form:/], true); + await utils.revertSettings(true); + }); + describe('for chw', () => { before(async () => { - await loginPage.login({ username: chw.username, password: chw.password, loadPage: true }); + await loginPage.login(chw); }); after(async () => { @@ -199,9 +163,9 @@ describe('Tasks group landing page', () => { }); it('should have tasks', async () => { - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const list = await tasksPage.getTasks(); - expect(list.length).to.equal(people.length + clinics.length + 2); + expect(list.length).to.equal(people.length + 5); }); it('should display tasks group landing page after task completion', async () => { @@ -301,7 +265,7 @@ describe('Tasks group landing page', () => { }); it('should not show page when there are no more household tasks', async () => { - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); await (await commonPage.waitForPageLoaded()); await tasksPage.getTasks(); const task = await tasksPage.getTaskByContactAndForm('Napoleon Bonaparte', 'person_create'); @@ -347,7 +311,7 @@ describe('Tasks group landing page', () => { describe('for supervisor', () => { before(async () => { - await loginPage.login({ username: supervisor.username, password: supervisor.password, loadPage: true }); + await loginPage.login(supervisor); }); after(async () => { @@ -356,11 +320,11 @@ describe('Tasks group landing page', () => { }); it('should have tasks', async () => { - await tasksPage.goToTasksTab(); + await commonPage.goToTasks(); const list = await tasksPage.getTasks(); const taskNamesAndTitles = await getTaskNamesAndTitles(list); expect(taskNamesAndTitles).to.include.deep.members([ - { contactName: 'Albert Einstenin', formTitle: 'person_create' }, + { contactName: 'Albert Einstein', formTitle: 'person_create' }, { contactName: 'Charles Darwin', formTitle: 'person_create' }, { contactName: 'Nikola Tesla', formTitle: 'person_create' }, { contactName: 'Scientists', formTitle: 'clinic_create' }, @@ -368,7 +332,7 @@ describe('Tasks group landing page', () => { }); it('should not display task landing page after task completion', async () => { - const task = await tasksPage.getTaskByContactAndForm('Albert Einstenin', 'person_create'); + const task = await tasksPage.getTaskByContactAndForm('Albert Einstein', 'person_create'); await task.click(); await tasksPage.waitForTaskContentLoaded('Home Visit'); diff --git a/tests/e2e/default/tasks/tasks.wdio-spec.js b/tests/e2e/default/tasks/tasks.wdio-spec.js index 9ecf2cdcb35..9983a664262 100644 --- a/tests/e2e/default/tasks/tasks.wdio-spec.js +++ b/tests/e2e/default/tasks/tasks.wdio-spec.js @@ -8,37 +8,25 @@ const placeFactory = require('@factories/cht/contacts/place'); const personFactory = require('@factories/cht/contacts/person'); const chtDbUtils = require('@utils/cht-db'); -const compileTasks = async (tasksFileName) => { - await chtConfUtils.initializeConfigDir(); - const tasksFilePath = path.join(__dirname, `config/${tasksFileName}`); - return await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath }); -}; - describe('Tasks', () => { const places = placeFactory.generateHierarchy(); const clinic = places.get('clinic'); const healthCenter = places.get('health_center'); - const contact = { - _id: 'fixture:user:user1', + const contact = personFactory.build({ name: 'CHW', phone: '+12068881234', - type: 'person', - place: healthCenter._id, - parent: { - _id: healthCenter._id, - parent: healthCenter.parent - }, - }; - const chw = userFactory.build({ - isOffline: true, place: healthCenter._id, - contact: contact._id, - }); - const owl = personFactory.build({ - name: 'Owl', - parent: { _id: clinic._id, parent: clinic.parent } + parent: healthCenter }); + const chw = userFactory.build({ isOffline: true, place: healthCenter._id, contact: contact._id }); + const owl = personFactory.build({ name: 'Owl', parent: clinic }); + + const compileTasks = async (tasksFileName) => { + await chtConfUtils.initializeConfigDir(); + const tasksFilePath = path.join(__dirname, `config/${tasksFileName}`); + return await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath }); + }; before(async () => { await utils.saveDocs([...places.values(), contact, owl]); @@ -47,6 +35,8 @@ describe('Tasks', () => { }); after(async () => { + await utils.deleteUsers([chw]); + await utils.revertDb([/^form:/], true); await browser.deleteCookies(); await browser.refresh(); }); diff --git a/tests/page-objects/default/sms/messages.wdio.page.js b/tests/page-objects/default/sms/messages.wdio.page.js index a99344f7dc3..ee770506fcb 100644 --- a/tests/page-objects/default/sms/messages.wdio.page.js +++ b/tests/page-objects/default/sms/messages.wdio.page.js @@ -1,5 +1,5 @@ -const commonPage = require('../common/common.wdio.page'); -const modalPage = require('../common/modal.wdio.page'); +const commonPage = require('@page-objects/default/common/common.wdio.page'); +const modalPage = require('@page-objects/default/common/modal.wdio.page'); const MESSAGES_LIST = '#message-list'; const MESSAGE_HEADER = '#message-header'; @@ -70,7 +70,6 @@ const searchSelect = async (recipient, option) => { }; const sendMessage = async (message, recipient, entryText) => { - await commonPage.clickFastActionFlat({ waitForList: false }); await (await sendMessageModal()).waitForDisplayed(); await searchSelect(recipient, entryText); await (await messageText()).setValue(message); @@ -78,13 +77,14 @@ const sendMessage = async (message, recipient, entryText) => { await modalPage.checkModalHasClosed(); }; +const sendMessageDesktop = async (message, recipient, entryText) => { + await commonPage.clickFastActionFlat({ waitForList: false }); + await sendMessage(message, recipient, entryText); +}; + const sendMessageOnMobile = async (message, recipient, entryText) => { await commonPage.clickFastActionFAB({ waitForList: false }); - await (await sendMessageModal()).waitForDisplayed(); - await searchSelect(recipient, entryText); - await (await messageText()).setValue(message); - await modalPage.submit(); - await modalPage.checkModalHasClosed(); + await sendMessage(message, recipient, entryText); }; const sendReplyNewRecipient = async (recipient, entryText) => { @@ -146,7 +146,7 @@ module.exports = { getMessageInListDetails, getMessageHeader, getMessageContent, - sendMessage, + sendMessageDesktop, sendMessageOnMobile, sendReplyNewRecipient, sendMessageToContact, diff --git a/tests/page-objects/default/targets/target-aggregates.wdio.page.js b/tests/page-objects/default/targets/target-aggregates.wdio.page.js index f93d2ac08e7..d62d9bd7487 100644 --- a/tests/page-objects/default/targets/target-aggregates.wdio.page.js +++ b/tests/page-objects/default/targets/target-aggregates.wdio.page.js @@ -1,12 +1,15 @@ const commonPage = require('@page-objects/default/common/common.wdio.page'); -const AGGREGATE_LIST = '#target-aggregates-list'; -const loadingStatus = () => $(`${AGGREGATE_LIST} .loading-status`); -const aggregateList = () => $$(`${AGGREGATE_LIST} ul li.content-row`); +const AGGREGATE_LIST = '#target-aggregates-list'; const NAVIGATION_LINK = '.mm-navigation-menu li a'; const CONTENT_DISABLED = '.page .item-content.disabled'; +const TARGET_DETAIL = '.target-detail'; +const AGGREGATE_DETAIL_CONTACT_LIST = '.aggregate-detail li'; +const AGGREGATE_DETAIL_PROGRESS_BAR = '.progress-bar'; + +const loadingStatus = () => $(`${AGGREGATE_LIST} .loading-status`); +const aggregateList = () => $$(`${AGGREGATE_LIST} ul li.content-row`); const lineItem = (elementId) => $(`${AGGREGATE_LIST} li[data-record-id=${elementId}]`); -const getAggregateDetailListElementByIndex = (index) => $$(AGGREGATE_DETAIL_CONTACT_LIST)[index]; const sidebarFilter = { filterBtn: () => $('button*=Filter'), @@ -16,7 +19,6 @@ const sidebarFilter = { optionRadioBtn: (optionLabel) => $(`span*=${optionLabel}`).parentElement(), }; -const TARGET_DETAIL = '.target-detail'; const targetDetail = { title: (titleValue) => $(TARGET_DETAIL).$(`h2=${titleValue}`), counter: () => $(`${TARGET_DETAIL} .cell p`), @@ -24,9 +26,6 @@ const targetDetail = { period: (periodValue) => $('.aggregate-detail .action-header').$(`h3*=${periodValue}`), }; -const AGGREGATE_DETAIL_CONTACT_LIST = '.aggregate-detail li'; -const AGGREGATE_DETAIL_PROGRESS_BAR = '.progress-bar'; - const aggregateDetailContactItem = (contactId) => { return $(`${AGGREGATE_DETAIL_CONTACT_LIST}[data-record-id="${contactId}"]`); // a }; @@ -75,7 +74,7 @@ const checkContentDisabled = async () => { }; const getTargetItem = async (target, period, place) => { - const item = lineItem(target.id); + const item = await lineItem(target.id); return { title: await (await item.$('h4')).getText(), counter: await (await item.$('.aggregate-status span')).getText(), @@ -85,7 +84,7 @@ const getTargetItem = async (target, period, place) => { }; const openTargetDetails = async (target) => { - const item = lineItem(target.id); + const item = await lineItem(target.id); await item.waitForClickable(); await item.click(); await commonPage.waitForLoaders(); @@ -151,7 +150,6 @@ module.exports = { getTargetItem, openTargetDetails, getAggregateDetailListLength, - getAggregateDetailListElementByIndex, getAggregateDetailContact, getAggregateTargetProgressBar, getAggregateTargetGoal, diff --git a/tests/page-objects/default/tasks/tasks.wdio.page.js b/tests/page-objects/default/tasks/tasks.wdio.page.js index ae095a90cb8..1318c556220 100644 --- a/tests/page-objects/default/tasks/tasks.wdio.page.js +++ b/tests/page-objects/default/tasks/tasks.wdio.page.js @@ -1,13 +1,11 @@ -const taskListSelector = '#tasks-list'; -const taskFormSelector = '#task-report'; -const tasksGroupSelector = '#tasks-group .item-content'; -const formTitleSelector = `${taskFormSelector} h3#form-title`; -const noSelectedTaskSelector = '.empty-selection'; +const TASK_LIST_SELECTOR = '#tasks-list'; +const TASK_FORM_SELECTOR = '#task-report'; +const TASKS_GROUP_SELECTOR = '#tasks-group .item-content'; +const FORM_TITLE_SELECTOR = `${TASK_FORM_SELECTOR} h3#form-title`; +const NO_SELECTED_TASK_SELECTOR = '.empty-selection'; -const tasksList = () => $(taskListSelector); - -const getTaskById = (emissionId) => $(`${taskListSelector} li[data-record-id="${emissionId}"`); -const getTasks = () => $$(`${taskListSelector} li.content-row`); +const getTaskById = (emissionId) => $(`${TASK_LIST_SELECTOR} li[data-record-id="${emissionId}"`); +const getTasks = () => $$(`${TASK_LIST_SELECTOR} li.content-row`); const getTaskInfo = async (taskElement) => { const contactName = await (await taskElement.$('h4 span')).getText(); @@ -48,19 +46,10 @@ const getTaskByContactAndForm = async (name, title) => { } }; -const goToTasksTab = async () => { - await browser.url('/#/tasks'); - await (await tasksList()).waitForDisplayed(); - await browser.waitUntil(async () => (await getTasks()).length, { - timeout: 4000, - timeoutMsg: 'Timed out waiting for tasks to load' - }); -}; - const waitForTaskContentLoaded = async (name) => { - await (await $(formTitleSelector)).waitForDisplayed(); + await (await $(FORM_TITLE_SELECTOR)).waitForDisplayed(); await browser.waitUntil(async () => { - const formTitle = await (await $(`${formTitleSelector}`)).getText(); + const formTitle = await (await $(`${FORM_TITLE_SELECTOR}`)).getText(); return formTitle === name; }, { timeout: 2000 }); }; @@ -71,26 +60,23 @@ const getOpenTaskElement = async () => { }; const waitForTasksGroupLoaded = async () => { - await (await $(tasksGroupSelector)).waitForDisplayed(); + await (await $(TASKS_GROUP_SELECTOR)).waitForDisplayed(); await browser.waitUntil(async () => { - const pageTitle = await (await $(`${tasksGroupSelector} .action-header h3`)).getText(); + const pageTitle = await (await $(`${TASKS_GROUP_SELECTOR} .action-header h3`)).getText(); return pageTitle === 'Other household tasks'; }, { timeout: 2000 }); }; -const getTasksInGroup = () => $$(`${tasksGroupSelector} li`); -const noSelectedTask = () => $(noSelectedTaskSelector); +const getTasksInGroup = () => $$(`${TASKS_GROUP_SELECTOR} li`); +const noSelectedTask = () => $(NO_SELECTED_TASK_SELECTOR); const openTaskById = async (id, taskType) => { await getTaskById(`${id}${taskType}`).click(); - await $(taskFormSelector).waitForDisplayed(); + await $(TASK_FORM_SELECTOR).waitForDisplayed(); }; module.exports = { - tasksList, getTasks, - goToTasksTab, - getTaskById, getTaskByContactAndForm, waitForTaskContentLoaded, getTaskInfo,