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

chore(#9443): offline user e2e test coverage for tasks #9498

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
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: 200 }, (_, 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;
}
}
]
}));
56 changes: 56 additions & 0 deletions tests/e2e/default/tasks/tasks.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 tasksPage = require('@page-objects/default/tasks/tasks.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');
Expand Down Expand Up @@ -43,7 +44,11 @@ describe('Tasks', () => {
before(async () => {
await utils.saveDocs([...places.values(), contact, owl]);
await utils.createUsers([chw]);
});

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

after(async () => {
Expand All @@ -53,6 +58,57 @@ describe('Tasks', () => {

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

// WIP
it('should remove task from list when CHW completes a task successfully', async () => {
const settings = await compileTasks('tasks-breadcrumbs-config.js');
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true });

await tasksPage.goToTasksTab();
const list = await tasksPage.getTasks();
await browser.debug();
const infos = await tasksPage.getTasksListInfos(list);
expect(infos).to.have.length(3);
// open task and then complete the task
// expect(infos).to.have.length(2);
});

// WIP
it('should add a task when CHW completes a task successfully, and that task creates another task', async () => {
const settings = await compileTasks('tasks-multiple-config.js');
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true });

await tasksPage.goToTasksTab();
const list = await tasksPage.getTasks();
const infos = await tasksPage.getTasksListInfos(list);
});

it('should load multiple pages of tasks on infinite scrolling', async () => {
const settings = await compileTasks('tasks-multiple-config.js');
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true });

await tasksPage.goToTasksTab();
const list = await tasksPage.getTasks();
const infos = await tasksPage.getTasksListInfos(list);
expect(infos).to.have.length(200);
for (let i = 0; i < infos.length; i++) {
expect(infos).to.include.deep.members([
{
contactName: 'Owl',
formTitle: `person_create_${i + 1}`,
lineage: 'clinic2',
dueDateText: 'Due today',
overdue: true
},
]);
}

await tasksPage.scrollToLastTaskItem();
const loadingStatusSelector = await $('#tasks-list p.loading-status');
const elementText = await loadingStatusSelector.getText();
expect(elementText).to.contain('No more tasks');
});

it('Should show error message for bad config', async () => {
Expand Down
7 changes: 7 additions & 0 deletions tests/page-objects/default/tasks/tasks.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ const openTaskById = async (id, taskType) => {
await $(taskFormSelector).waitForDisplayed();
};

const scrollToLastTaskItem = async () => {
await browser.execute(() => {
$('.content-row:last-child').get(0).scrollIntoView();
});
};

module.exports = {
tasksList,
getTasks,
Expand All @@ -100,4 +106,5 @@ module.exports = {
getTasksInGroup,
noSelectedTask,
openTaskById,
scrollToLastTaskItem,
};
Loading