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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
XPCOMUtils.defineLazyModuleGetters(this, {
CalRecurrenceInfo: "resource:///modules/CalRecurrenceInfo.jsm",
CalTodo: "resource:///modules/CalTodo.jsm",
});
var calendar = CalendarTestUtils.createCalendar();
registerCleanupFunction(() => {
CalendarTestUtils.removeCalendar(calendar);
});
let tree = document.getElementById("calendar-task-tree");
add_task(async () => {
async function createTask(title, attributes = {}) {
let task = new CalTodo();
task.title = title;
for (let [key, value] of Object.entries(attributes)) {
task[key] = value;
}
return calendar.addItem(task);
}
function treeRefresh() {
return BrowserTestUtils.waitForEvent(tree, "refresh");
}
async function setFilterGroup(name) {
info(`Setting filter to ${name}`);
let radio = document.getElementById(`opt_${name}_filter`);
EventUtils.synthesizeMouseAtCenter(radio, {});
await treeRefresh();
Assert.equal(
document.getElementById("calendar-task-tree").getAttribute("filterValue"),
radio.value,
"Filter group changed"
);
}
async function setFilterText(text) {
EventUtils.synthesizeMouseAtCenter(document.getElementById("task-text-filter-field"), {});
EventUtils.sendString(text);
Assert.equal(document.getElementById("task-text-filter-field").value, text, "Filter text set");
await treeRefresh();
}
async function clearFilterText() {
EventUtils.synthesizeMouseAtCenter(document.getElementById("task-text-filter-field"), {});
EventUtils.synthesizeKey("VK_ESCAPE");
Assert.equal(
document.getElementById("task-text-filter-field").value,
"",
"Filter text cleared"
);
await treeRefresh();
}
async function checkVisibleTasks(...expectedTasks) {
function toPrettyString(task) {
if (task.recurrenceId) {
return `${task.title}#${task.recurrenceId}`;
}
return task.title;
}
tree.getBoundingClientRect(); // Try and trigger a reflow...
tree.invalidate();
// It seems that under certain conditions notifyOperationComplete() is
// called in CalStorageCalender.getItems before all the results have been
// retrieved. This results in the "refresh" event being fired prematurely in
// calendar-task-tree. After some investigation, the cause of this seems to
// be related to multiple calls of executeAsync() in CalStorageItemModel.
// getAdditionalDataForItemMap() not finishing before notifyOperationComplete()
// is called despite being awaited on.
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(r => setTimeout(r, 500));
let actualTasks = [];
for (let i = 0; i < tree.view.rowCount; i++) {
actualTasks.push(tree.getTaskAtRow(i));
}
info("Expected: " + expectedTasks.map(toPrettyString).join(", "));
info("Actual: " + actualTasks.map(toPrettyString).join(", "));
Assert.equal(tree.view.rowCount, expectedTasks.length, "Correct number of tasks");
await new Promise(r => setTimeout(r));
// Although the order of expectedTasks matches the observed behaviour when
// this test was written, order is NOT checked here. The order of the list
// is not well defined (particularly when changing the filter text).
for (let aTask of actualTasks) {
Assert.ok(
expectedTasks.some(eTask => eTask.hasSameIds(aTask)),
toPrettyString(aTask)
);
}
}
let today = cal.dtz.now();
today.hour = today.minute = today.second = 0;
let yesterday = today.clone();
yesterday.addDuration(cal.createDuration("-P1D"));
let tomorrow = today.clone();
tomorrow.addDuration(cal.createDuration("P1D"));
let later = today.clone();
later.addDuration(cal.createDuration("P2W"));
let tasks = {
incomplete: await createTask("Incomplete"),
started30: await createTask("30% started", { percentComplete: 30 }),
started60: await createTask("60% started", { percentComplete: 60 }),
complete: await createTask("Complete", { isCompleted: true }),
overdue: await createTask("Overdue", { dueDate: yesterday }),
startsToday: await createTask("Starts today", { entryDate: today }),
startsTomorrow: await createTask("Starts tomorrow", { entryDate: tomorrow }),
startsLater: await createTask("Starts later", { entryDate: later }),
};
let repeatingTask = new CalTodo();
repeatingTask.title = "Repeating";
repeatingTask.entryDate = yesterday;
repeatingTask.recurrenceInfo = new CalRecurrenceInfo(repeatingTask);
repeatingTask.recurrenceInfo.appendRecurrenceItem(
cal.createRecurrenceRule("RRULE:FREQ=DAILY;COUNT=3")
);
let firstOccurrence = repeatingTask.recurrenceInfo.getOccurrenceFor(yesterday);
firstOccurrence.isCompleted = true;
firstOccurrence.completedDate = yesterday;
repeatingTask.recurrenceInfo.modifyException(firstOccurrence, true);
repeatingTask = await calendar.addItem(repeatingTask);
let occurrences = repeatingTask.recurrenceInfo.getOccurrences(yesterday, later, 10);
Assert.equal(occurrences.length, 3);
await openTasksTab();
await setFilterGroup("all");
await checkVisibleTasks(
tasks.incomplete,
tasks.started30,
tasks.started60,
tasks.complete,
tasks.overdue,
tasks.startsToday,
tasks.startsTomorrow,
tasks.startsLater,
repeatingTask
);
await setFilterGroup("open");
await checkVisibleTasks(
tasks.incomplete,
tasks.started30,
tasks.started60,
tasks.overdue,
tasks.startsToday,
tasks.startsTomorrow,
tasks.startsLater,
occurrences[1],
occurrences[2]
);
await setFilterGroup("completed");
await checkVisibleTasks(tasks.complete, occurrences[0]);
await setFilterGroup("overdue");
await checkVisibleTasks(tasks.overdue);
await setFilterGroup("notstarted");
await checkVisibleTasks(tasks.overdue, tasks.incomplete, tasks.startsToday, occurrences[1]);
await setFilterGroup("next7days");
await checkVisibleTasks(
tasks.overdue,
tasks.incomplete,
tasks.startsToday,
tasks.started30,
tasks.started60,
tasks.complete,
tasks.startsTomorrow,
occurrences[1],
occurrences[2]
);
await setFilterGroup("today");
await checkVisibleTasks(
tasks.overdue,
tasks.incomplete,
tasks.startsToday,
tasks.started30,
tasks.started60,
tasks.complete,
occurrences[1]
);
await setFilterGroup("throughcurrent");
await checkVisibleTasks(
tasks.overdue,
tasks.incomplete,
tasks.startsToday,
tasks.started30,
tasks.started60,
tasks.complete,
occurrences[1]
);
await setFilterText("No matches");
await checkVisibleTasks();
await clearFilterText();
await checkVisibleTasks(
tasks.incomplete,
tasks.started30,
tasks.started60,
tasks.complete,
tasks.overdue,
tasks.startsToday,
occurrences[1]
);
await setFilterText("StArTeD");
await checkVisibleTasks(tasks.started30, tasks.started60);
await setFilterGroup("today");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks(tasks.started30, tasks.started60);
await setFilterGroup("next7days");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks(tasks.started30, tasks.started60);
await setFilterGroup("notstarted");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks();
await setFilterGroup("overdue");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks();
await setFilterGroup("completed");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks();
await setFilterGroup("open");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks(tasks.started30, tasks.started60);
await setFilterGroup("all");
Assert.equal(document.getElementById("task-text-filter-field").value, "StArTeD");
await checkVisibleTasks(tasks.started30, tasks.started60);
await clearFilterText();
await checkVisibleTasks(
tasks.started30,
tasks.started60,
tasks.incomplete,
tasks.complete,
tasks.overdue,
tasks.startsToday,
tasks.startsTomorrow,
tasks.startsLater,
repeatingTask
);
for (let task of Object.values(tasks)) {
await calendar.deleteItem(task);
}
await setFilterGroup("throughcurrent");
});
|