forked from medic/cht-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.wdio.page.js
More file actions
218 lines (186 loc) · 7.12 KB
/
Copy pathtasks.wdio.page.js
File metadata and controls
218 lines (186 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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 .material';
const FORM_TITLE_SELECTOR = `${TASK_FORM_SELECTOR} h3#form-title`;
const NO_SELECTED_TASK_SELECTOR = '.empty-selection';
const sidebarFilterSelectors = {
openBtn: () => $('mm-search-bar .open-filter, .mm-search-bar-container .btn.open-filter'),
resetBtn: () => $('.sidebar-reset'),
overdueAccordionHeader: () => $('#overdue-filter-accordion mat-expansion-panel-header'),
overdueAccordionBody: () => $('#overdue-filter-accordion mat-panel-description'),
taskTypeAccordionHeader: () => $('#task-type-filter-accordion mat-expansion-panel-header'),
taskTypeAccordionBody: () => $('#task-type-filter-accordion mat-panel-description'),
placeAccordionHeader: () => $('#place-filter-accordion mat-expansion-panel-header'),
placeAccordionBody: () => $('#place-filter-accordion mat-panel-description'),
};
const getTaskById = (emissionId) => $(`${TASK_LIST_SELECTOR} li[data-record-id="${emissionId}"]`);
const getTasks = async (timeout = 10000) => {
let tasks;
await browser.waitUntil(async () => {
const tasksList = await $(TASK_LIST_SELECTOR);
tasks = await $$(`${TASK_LIST_SELECTOR} li.content-row`);
return await tasksList.isDisplayed() && tasks.length > 0;
}, {
timeout,
timeoutMsg: 'Expected tasks list to be displayed with at least one task'
});
return tasks;
};
const getTaskInfo = async (taskElement) => {
await taskElement.scrollIntoView();
const contactName = await taskElement.$('h4 span').getText();
const formTitle = await taskElement.$('.summary p').getText();
let lineage = '';
if (await taskElement.$('.detail').isExisting()){
lineage = await taskElement.$('.detail').getText();
}
let dueDateText = '';
if (await taskElement.$('.date .relative-date-content').isExisting()) {
dueDateText = await taskElement.$('.date .relative-date-content').getText();
}
const classAttr = await taskElement.getAttribute('class');
const overdue = classAttr.split(' ').includes('overdue');
return { contactName, formTitle, dueDateText, overdue, lineage };
};
const getTasksListInfos = async (tasks) => {
const infos = [];
for (const task of tasks) {
infos.push(await getTaskInfo(task));
}
return infos;
};
const getTaskByContactAndForm = async (name, title) => {
const tasks = await getTasks();
for (const task of tasks) {
const { contactName, formTitle } = await getTaskInfo(task);
if (contactName === name && formTitle === title) {
await task.scrollIntoView();
return task;
}
}
};
const waitForTaskContentLoaded = async (name) => {
await $(FORM_TITLE_SELECTOR).waitForDisplayed();
await browser.waitUntil(async () => {
const formTitle = await $(`${FORM_TITLE_SELECTOR}`).getText();
return formTitle === name;
}, { timeout: 2000 });
};
const getTaskListCount = async () => {
const tasks = await $$(`${TASK_LIST_SELECTOR} li.content-row`);
return tasks.length;
};
const waitForTaskListCountChange = async (initialCount) => {
await browser.waitUntil(
async () => (await getTaskListCount()) !== initialCount,
{ timeout: 10000, timeoutMsg: `Task list count did not change from ${initialCount}.` }
);
};
const waitForTasksGroupLoaded = async () => {
await $(TASKS_GROUP_SELECTOR).waitForDisplayed();
await browser.waitUntil(async () => {
const pageTitle = await $(`${TASKS_GROUP_SELECTOR} .action-header h3`).getText();
return pageTitle === 'Other household tasks';
}, { timeout: 2000 });
};
const getTasksInGroup = () => $$(`${TASKS_GROUP_SELECTOR} li`);
const noSelectedTask = () => $(NO_SELECTED_TASK_SELECTOR);
const openTaskById = async (id, taskType) => {
await getTaskById(`${id}${taskType}`).click();
await $(TASK_FORM_SELECTOR).waitForDisplayed();
};
const openTaskByIndex = async (idx = 0) => {
const task = await (await getTasks())[idx];
await task.click();
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.compileConfig({ tasks: tasksFilePath });
await utils.updateSettings(settings, { sync, refresh: sync, ignoreReload: !sync });
};
const isTaskElementDisplayed = async (type, text) => {
return await $(TASK_LIST_SELECTOR).$(`${type}*=${text}`).isDisplayed();
};
const openSidebarFilter = async () => {
if (!await sidebarFilterSelectors.resetBtn().isDisplayed()) {
await sidebarFilterSelectors.openBtn().click();
}
return await sidebarFilterSelectors.resetBtn().waitForDisplayed();
};
const filterByOverdue = async (overdueOption) => {
if (!await sidebarFilterSelectors.overdueAccordionBody().isDisplayed()) {
await sidebarFilterSelectors.overdueAccordionHeader().click();
await sidebarFilterSelectors.overdueAccordionBody().waitForDisplayed();
}
const option = sidebarFilterSelectors.overdueAccordionBody().$(`label*=${overdueOption}`);
const radio = await option.$('input[type="radio"]');
await radio.click();
};
const filterByTaskType = async (taskType) => {
if (!await sidebarFilterSelectors.taskTypeAccordionBody().isDisplayed()) {
await sidebarFilterSelectors.taskTypeAccordionHeader().click();
await sidebarFilterSelectors.taskTypeAccordionBody().waitForDisplayed();
}
const option = sidebarFilterSelectors.taskTypeAccordionBody().$(`a*=${taskType}`);
await option.click();
};
const filterByPlace = async (facility, parentFacility) => {
if (!await sidebarFilterSelectors.placeAccordionBody().isDisplayed()) {
await sidebarFilterSelectors.placeAccordionHeader().click();
await sidebarFilterSelectors.placeAccordionBody().waitForDisplayed();
}
if (parentFacility) {
const parent = sidebarFilterSelectors.placeAccordionBody().$(`a*=${parentFacility}`);
await parent.click();
}
const facilityOption = sidebarFilterSelectors
.placeAccordionBody()
.$(`a*=${facility}`);
await facilityOption.waitForDisplayed();
const checkbox = facilityOption.previousElement();
await checkbox.click();
};
const resetFilters = async () => {
await sidebarFilterSelectors.resetBtn().click();
};
const isPlaceFilterDisplayed = async () => {
return await sidebarFilterSelectors.placeAccordionHeader().isDisplayed();
};
const scrollTaskList = async () => {
await browser.execute(() => {
const el = document.getElementById('tasks-list');
if (el) {
el.scrollTop += 300;
el.dispatchEvent(new Event('scroll'));
}
});
};
module.exports = {
getTasks,
getTaskByContactAndForm,
waitForTaskContentLoaded,
getTaskInfo,
getTasksListInfos,
getTaskListCount,
waitForTaskListCountChange,
waitForTasksGroupLoaded,
getTasksInGroup,
noSelectedTask,
openTaskById,
compileTasks,
isTaskElementDisplayed,
sidebarFilterSelectors,
openSidebarFilter,
filterByOverdue,
filterByTaskType,
filterByPlace,
resetFilters,
isPlaceFilterDisplayed,
openTaskByIndex,
scrollTaskList,
};