summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/browser/recurrence/browser_weeklyWithException.js
blob: fbe007ea45eb8f83a40f4d363822c50bc5983be7 (plain)
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
/* 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/. */

var { handleDeleteOccurrencePrompt } = ChromeUtils.import(
  "resource://testing-common/calendar/CalendarUtils.jsm"
);

var { menulistSelect, saveAndCloseItemDialog, setData } = ChromeUtils.import(
  "resource://testing-common/calendar/ItemEditingHelpers.jsm"
);

var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");

var { dayView, weekView, multiweekView, monthView } = CalendarTestUtils;

const HOUR = 8;
const STARTDATE = cal.createDateTime("20090106T000000Z");
const TITLE = "Event";

add_task(async function testWeeklyWithExceptionRecurrence() {
  let calendar = CalendarTestUtils.createCalendar();
  registerCleanupFunction(() => {
    CalendarTestUtils.removeCalendar(calendar);
  });

  await CalendarTestUtils.setCalendarView(window, "day");
  await CalendarTestUtils.goToDate(window, 2009, 1, 5);

  // Create weekly recurring event.
  let eventBox = dayView.getHourBoxAt(window, HOUR);
  let { dialogWindow, iframeWindow } = await CalendarTestUtils.editNewEvent(window, eventBox);
  await setData(dialogWindow, iframeWindow, { title: TITLE, repeat: setRecurrence });
  await saveAndCloseItemDialog(dialogWindow);

  let eventItem = await dayView.waitForEventBoxAt(window, 1);
  let icon = eventItem.querySelector(".item-recurrence-icon");
  Assert.equal(icon.src, "chrome://messenger/skin/icons/new/recurrence.svg");
  Assert.ok(!icon.hidden);

  // Move 5th January occurrence to 6th January.
  ({ dialogWindow, iframeWindow } = await dayView.editEventOccurrenceAt(window, 1));
  await setData(dialogWindow, iframeWindow, {
    title: TITLE,
    startdate: STARTDATE,
    enddate: STARTDATE,
  });
  await saveAndCloseItemDialog(dialogWindow);

  await CalendarTestUtils.goToDate(window, 2009, 1, 6);
  eventItem = await dayView.waitForEventBoxAt(window, 1);
  icon = eventItem.querySelector(".item-recurrence-icon");
  Assert.equal(icon.src, "chrome://messenger/skin/icons/new/recurrence-exception.svg");

  // Change recurrence rule.
  await CalendarTestUtils.goToDate(window, 2009, 1, 7);
  ({ dialogWindow, iframeWindow } = await dayView.editEventOccurrencesAt(window, 1));
  await setData(dialogWindow, iframeWindow, {
    title: "Event",
    repeat: changeRecurrence,
  });
  await saveAndCloseItemDialog(dialogWindow);

  // Check two weeks.
  // day view
  await CalendarTestUtils.setCalendarView(window, "day");

  await CalendarTestUtils.goToDate(window, 2009, 1, 5);
  await dayView.waitForNoEventBoxAt(window, 1);

  await CalendarTestUtils.calendarViewForward(window, 1);

  // Assert exactly two.
  Assert.ok(!!(await dayView.waitForEventBoxAt(window, 1)));
  Assert.ok(!!(await dayView.waitForEventBoxAt(window, 2)));

  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForNoEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForNoEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForNoEventBoxAt(window, 1);

  // next week
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForNoEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForEventBoxAt(window, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);
  await dayView.waitForNoEventBoxAt(window, 1);

  // week view
  await CalendarTestUtils.setCalendarView(window, "week");
  await CalendarTestUtils.goToDate(window, 2009, 1, 5);

  // Assert exactly two on Tuesday.
  Assert.ok(!!(await weekView.waitForEventBoxAt(window, 3, 1)));
  Assert.ok(!!(await weekView.waitForEventBoxAt(window, 3, 2)));

  // Wait for the last occurrence because this appears last.
  eventItem = await weekView.waitForEventBoxAt(window, 6, 1);
  icon = eventItem.querySelector(".item-recurrence-icon");
  Assert.equal(icon.src, "chrome://messenger/skin/icons/new/recurrence.svg");
  Assert.ok(!icon.hidden);

  Assert.ok(!weekView.getEventBoxAt(window, 1, 1));
  Assert.ok(!weekView.getEventBoxAt(window, 2, 1));
  Assert.ok(!!weekView.getEventBoxAt(window, 4, 1));
  Assert.ok(!weekView.getEventBoxAt(window, 5, 1));
  Assert.ok(!weekView.getEventBoxAt(window, 7, 1));

  await CalendarTestUtils.calendarViewForward(window, 1);
  await weekView.waitForEventBoxAt(window, 6, 1);
  Assert.ok(!weekView.getEventBoxAt(window, 1, 1));
  Assert.ok(!!weekView.getEventBoxAt(window, 2, 1));
  Assert.ok(!!weekView.getEventBoxAt(window, 3, 1));
  Assert.ok(!!weekView.getEventBoxAt(window, 4, 1));
  Assert.ok(!weekView.getEventBoxAt(window, 5, 1));
  Assert.ok(!weekView.getEventBoxAt(window, 7, 1));

  // multiweek view
  await CalendarTestUtils.setCalendarView(window, "multiweek");
  await CalendarTestUtils.goToDate(window, 2009, 1, 5);
  // Wait for the first items, then check the ones not to be present.
  // Assert exactly two.
  await multiweekView.waitForItemAt(window, 1, 3, 1, 1);
  Assert.ok(multiweekView.getItemAt(window, 1, 3, 2, 1));
  Assert.ok(!multiweekView.getItemAt(window, 1, 3, 3, 1));
  // Then check no item on the 5th.
  Assert.ok(!multiweekView.getItemAt(window, 1, 2, 1));
  Assert.ok(multiweekView.getItemAt(window, 1, 4, 1));
  Assert.ok(!multiweekView.getItemAt(window, 1, 5, 1));
  Assert.ok(multiweekView.getItemAt(window, 1, 6, 1));
  Assert.ok(!multiweekView.getItemAt(window, 1, 7, 1));

  Assert.ok(!multiweekView.getItemAt(window, 2, 1, 1));
  Assert.ok(multiweekView.getItemAt(window, 2, 2, 1));
  Assert.ok(multiweekView.getItemAt(window, 2, 3, 1));
  Assert.ok(multiweekView.getItemAt(window, 2, 4, 1));
  Assert.ok(!multiweekView.getItemAt(window, 2, 5, 1));
  Assert.ok(multiweekView.getItemAt(window, 2, 6, 1));
  Assert.ok(!multiweekView.getItemAt(window, 2, 7, 1));

  eventItem = multiweekView.getItemAt(window, 2, 4, 1);
  icon = eventItem.querySelector(".item-recurrence-icon");
  Assert.equal(icon.src, "chrome://messenger/skin/icons/new/recurrence.svg");
  Assert.ok(!icon.hidden);

  // month view
  await CalendarTestUtils.setCalendarView(window, "month");
  // Wait for the first items, then check the ones not to be present.
  // Assert exactly two.
  // start on the second week
  await monthView.waitForItemAt(window, 2, 3, 1);
  Assert.ok(monthView.getItemAt(window, 2, 3, 2));
  Assert.ok(!monthView.getItemAt(window, 2, 3, 3));
  // Then check no item on the 5th.
  Assert.ok(!monthView.getItemAt(window, 2, 2, 1));
  Assert.ok(monthView.getItemAt(window, 2, 4, 1));
  Assert.ok(!monthView.getItemAt(window, 2, 5, 1));
  Assert.ok(monthView.getItemAt(window, 2, 6, 1));
  Assert.ok(!monthView.getItemAt(window, 2, 7, 1));

  Assert.ok(!monthView.getItemAt(window, 3, 1, 1));
  Assert.ok(monthView.getItemAt(window, 3, 2, 1));
  Assert.ok(monthView.getItemAt(window, 3, 3, 1));
  Assert.ok(monthView.getItemAt(window, 3, 4, 1));
  Assert.ok(!monthView.getItemAt(window, 3, 5, 1));
  Assert.ok(monthView.getItemAt(window, 3, 6, 1));
  Assert.ok(!monthView.getItemAt(window, 3, 7, 1));

  eventItem = monthView.getItemAt(window, 3, 6, 1);
  icon = eventItem.querySelector(".item-recurrence-icon");
  Assert.equal(icon.src, "chrome://messenger/skin/icons/new/recurrence.svg");
  Assert.ok(!icon.hidden);

  // Delete event.
  await CalendarTestUtils.setCalendarView(window, "day");
  await CalendarTestUtils.goToDate(window, 2009, 1, 12);
  eventBox = await dayView.waitForEventBoxAt(window, 1);
  EventUtils.synthesizeMouseAtCenter(eventBox, {}, window);
  await handleDeleteOccurrencePrompt(window, eventBox, true);
  await dayView.waitForNoEventBoxAt(window, 1);

  Assert.ok(true, "Test ran to completion");
});

async function setRecurrence(recurrenceWindow) {
  let recurrenceDocument = recurrenceWindow.document;

  // weekly
  await menulistSelect(recurrenceDocument.getElementById("period-list"), "1");

  let mon = cal.l10n.getDateFmtString("day.2.Mmm");
  let wed = cal.l10n.getDateFmtString("day.4.Mmm");
  let fri = cal.l10n.getDateFmtString("day.6.Mmm");

  let dayPicker = recurrenceDocument.getElementById("daypicker-weekday");

  // Starting from Monday so it should be checked.
  Assert.ok(dayPicker.querySelector(`[label="${mon}"]`).checked, "mon checked");

  // Check Wednesday and Friday too.
  EventUtils.synthesizeMouseAtCenter(
    dayPicker.querySelector(`[label="${wed}"]`),
    {},
    recurrenceWindow
  );
  Assert.ok(dayPicker.querySelector(`[label="${wed}"]`).checked, "wed checked");
  EventUtils.synthesizeMouseAtCenter(
    dayPicker.querySelector(`[label="${fri}"]`),
    {},
    recurrenceWindow
  );
  Assert.ok(dayPicker.querySelector(`[label="${fri}"]`).checked, "fri checked");

  let button = recurrenceDocument.querySelector("dialog").getButton("accept");
  button.scrollIntoView();
  // Close dialog.
  EventUtils.synthesizeMouseAtCenter(button, {}, recurrenceWindow);
}

async function changeRecurrence(recurrenceWindow) {
  let recurrenceDocument = recurrenceWindow.document;

  // weekly
  await menulistSelect(recurrenceDocument.getElementById("period-list"), "1");

  let mon = cal.l10n.getDateFmtString("day.2.Mmm");
  let tue = cal.l10n.getDateFmtString("day.3.Mmm");
  let wed = cal.l10n.getDateFmtString("day.4.Mmm");
  let fri = cal.l10n.getDateFmtString("day.6.Mmm");

  let dayPicker = recurrenceDocument.getElementById("daypicker-weekday");

  // Check old rule.
  // Starting from Monday so it should be checked.
  Assert.ok(dayPicker.querySelector(`[label="${mon}"]`).checked, "mon checked");
  Assert.ok(dayPicker.querySelector(`[label="${wed}"]`).checked, "wed checked");
  Assert.ok(dayPicker.querySelector(`[label="${fri}"]`).checked, "fri checked");

  // Check Tuesday.
  EventUtils.synthesizeMouseAtCenter(
    dayPicker.querySelector(`[label="${tue}"]`),
    {},
    recurrenceWindow
  );
  Assert.ok(dayPicker.querySelector(`[label="${tue}"]`).checked, "tue checked");

  let button = recurrenceDocument.querySelector("dialog").getButton("accept");
  button.scrollIntoView();
  // Close dialog.
  EventUtils.synthesizeMouseAtCenter(button, {}, recurrenceWindow);
}