Skip to content

Commit

Permalink
chore(#9443): offline user e2e test coverage for tasks (#9498)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafa <[email protected]>
  • Loading branch information
ralfudx and Rafa authored Oct 23, 2024
1 parent e8e4918 commit fab7764
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 35 deletions.
48 changes: 48 additions & 0 deletions tests/e2e/default/tasks/config/tasks-multiple-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const oneDay = 24 * 60 * 60 * 1000;
const isFormArraySubmittedInWindow = (reports, formArray, start, end, count) => {
end = end || start + 10 * oneDay;
let found = false;
let reportCount = 0;
reports.forEach(function (report) {
if (formArray.includes(report.form)) {
if (report.reported_date >= start && report.reported_date <= end) {
found = true;
if (count) {
reportCount++;
}
}
}
});

return count ? reportCount >= count : found;
};

module.exports = Array.from({ length: 67 }, (_, index) => ({
name: `person_create_${index + 1}`,
icon: 'icon-person',
title: `person_create_${index + 1}`,
appliesTo: 'contacts',
appliesToType: ['person'],
appliesIf: function () {
return true;
},
resolvedIf: function (contact) {
return isFormArraySubmittedInWindow(contact.reports, ['home_visit'], contact.contact.reported_date);
},
actions: [
{
type: 'report',
form: 'home_visit'
}
],
events: [
{
id: `person-creation-follow-up-${index + 1}`,
start: 3,
end: 7,
dueDate: function (event, contact) {
return contact.contact.reported_date;
}
}
]
}));
7 changes: 1 addition & 6 deletions tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,9 @@ describe('Tasks tab breadcrumbs', () => {
await utils.createUsers([ chw, supervisor ]);
await sentinelUtils.waitForSentinel();

await chtConfUtils.initializeConfigDir();

const formsPath = path.join(__dirname, 'forms');
await chtConfUtils.compileAndUploadAppForms(formsPath);

const tasksFilePath = path.join(__dirname, 'config/tasks-breadcrumbs-config.js');
const { tasks } = await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath });
await utils.updateSettings({ tasks }, { ignoreReload: 'api' });
await tasksPage.compileTasks('tasks-breadcrumbs-config.js', false);
});

after(async () => {
Expand Down
7 changes: 1 addition & 6 deletions tests/e2e/default/tasks/tasks-group.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,9 @@ describe('Tasks group landing page', () => {
await utils.createUsers([chw, supervisor]);
await sentinelUtils.waitForSentinel();

await chtConfUtils.initializeConfigDir();

const formsPath = path.join(__dirname, 'forms');
await chtConfUtils.compileAndUploadAppForms(formsPath);

const tasksFilePath = path.join(__dirname, 'config/tasks-group-config.js');
const { tasks } = await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath });
await utils.updateSettings({ tasks }, { ignoreReload: 'api' });
await tasksPage.compileTasks('tasks-group-config.js', false);
});

after(async () => {
Expand Down
119 changes: 97 additions & 22 deletions tests/e2e/default/tasks/tasks.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,72 @@
const path = require('path');
const chtConfUtils = require('@utils/cht-conf');

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 userFactory = require('@factories/cht/users/users');
const placeFactory = require('@factories/cht/contacts/place');
const personFactory = require('@factories/cht/contacts/person');
const tasksPage = require('@page-objects/default/tasks/tasks.wdio.page');
const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page');
const chtConfUtils = require('@utils/cht-conf');
const sentinelUtils = require('@utils/sentinel');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const chtDbUtils = require('@utils/cht-db');

describe('Tasks', () => {

const places = placeFactory.generateHierarchy();
const clinic = places.get('clinic');
const healthCenter = places.get('health_center');

const contact = personFactory.build({
name: 'CHW',
const healthCenter1 = places.get('health_center');
const districtHospital = places.get('district_hospital');
const healthCenter2 = placeFactory.place().build({
name: 'health_center_2',
type: 'health_center',
parent: { _id: districtHospital._id },
});
const chwContact = personFactory.build({
name: 'Megan Spice',
phone: '+12068881234',
place: healthCenter._id,
parent: healthCenter
place: healthCenter1._id,
parent: healthCenter1,
});
const chw = userFactory.build({
username: 'offlineuser_tasks',
isOffline: true,
place: healthCenter1._id,
contact: chwContact._id,
});
const patient = personFactory.build({
name: 'patient1',
patient_id: 'patient1',
parent: clinic,
reported_date: new Date().getTime(),
});
const patient2 = personFactory.build({
name: 'patient2',
patient_id: 'patient2',
parent: healthCenter1,
reported_date: new Date().getTime(),
});
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]);
await utils.createUsers([chw]);
await utils.saveDocs([
...places.values(), healthCenter2, chwContact, patient, patient2,
]);
await utils.createUsers([ chw ]);
await sentinelUtils.waitForSentinel();

const formsPath = path.join(__dirname, 'forms');
await chtConfUtils.compileAndUploadAppForms(formsPath);
});

beforeEach(async () => {
await loginPage.login(chw);
await commonPage.waitForPageLoaded();
});

afterEach(async () => {
await commonPage.logout();
await utils.revertSettings(true);
});

after(async () => {
Expand All @@ -41,13 +76,53 @@ describe('Tasks', () => {
await browser.refresh();
});

afterEach(async () => {
await utils.revertSettings(true);
it('should remove task from list when CHW completes a task successfully', async () => {
await tasksPage.compileTasks('tasks-breadcrumbs-config.js', true);

await commonPage.goToTasks();
let list = await tasksPage.getTasks();
expect(list).to.have.length(3);
const task = await tasksPage.getTaskByContactAndForm('patient1', 'person_create');
await task.click();
await tasksPage.waitForTaskContentLoaded('Home Visit');
const taskElement = await tasksPage.getOpenTaskElement();
await genericForm.submitForm();
await taskElement.waitForDisplayed({ reverse: true });
list = await tasksPage.getTasks();
expect(list).to.have.length(2);
});

it('should load multiple pages of tasks on infinite scrolling', async () => {
await tasksPage.compileTasks('tasks-multiple-config.js', true);

await commonPage.goToTasks();
const list = await tasksPage.getTasks();
const infos = await tasksPage.getTasksListInfos(list);
expect(infos).to.have.length(134);
for (let i = 0; i < (infos.length/2); i++) {
expect(infos).to.include.deep.members([
{
contactName: 'Megan Spice',
formTitle: `person_create_${i + 1}`,
lineage: '',
dueDateText: 'Due today',
overdue: true
},
{
contactName: 'patient2',
formTitle: `person_create_${i + 1}`,
lineage: '',
dueDateText: 'Due today',
overdue: true
},
]);
}
await commonPage.loadNextInfiniteScrollPage();
expect(await tasksPage.isTaskElementDisplayed('p', 'No more tasks')).to.be.true;
});

it('Should show error message for bad config', async () => {
const settings = await compileTasks('tasks-error-config.js');
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true });
await tasksPage.compileTasks('tasks-error-config.js', true);
await commonPage.goToTasks();

const { errorMessage, url, username, errorStack } = await commonPage.getErrorLog();
Expand Down
2 changes: 1 addition & 1 deletion tests/page-objects/default/common/common.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ const isMenuOptionVisible = async (action, item) => {

const loadNextInfiniteScrollPage = async () => {
await browser.execute(() => {
$('.items-container .content-row:last-child').get(0).scrollIntoView();
$('.inbox-items .content-row:last-child').get(0).scrollIntoView();
});
await waitForLoaderToDisappear(await $('.left-pane'));
};
Expand Down
17 changes: 17 additions & 0 deletions tests/page-objects/default/tasks/tasks.wdio.page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const path = require('path');
const utils = require('@utils');
const chtConfUtils = require('@utils/cht-conf');

const TASK_LIST_SELECTOR = '#tasks-list';
const TASK_FORM_SELECTOR = '#task-report';
const TASKS_GROUP_SELECTOR = '#tasks-group .item-content';
Expand Down Expand Up @@ -75,6 +79,17 @@ const openTaskById = async (id, taskType) => {
await $(TASK_FORM_SELECTOR).waitForDisplayed();
};

const compileTasks = async (tasksFileName, sync) => {
await chtConfUtils.initializeConfigDir();
const tasksFilePath = path.join(__dirname, `../../../e2e/default/tasks/config/${tasksFileName}`);
const settings = await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath });
await utils.updateSettings(settings, { ignoreReload: 'api', sync });
};

const isTaskElementDisplayed = async (type, text) => {
return await (await $(TASK_LIST_SELECTOR)).$(`${type}*=${text}`).isDisplayed();
};

module.exports = {
getTasks,
getTaskByContactAndForm,
Expand All @@ -86,4 +101,6 @@ module.exports = {
getTasksInGroup,
noSelectedTask,
openTaskById,
compileTasks,
isTaskElementDisplayed,
};

0 comments on commit fab7764

Please sign in to comment.