summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/browser/recurrence/browser_biweekly.js
blob: 68898223751bab6aa7a4ba1dd22aa000b32f42d1 (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
/* 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 { saveAndCloseItemDialog, setData } = ChromeUtils.import(
  "resource://testing-common/calendar/ItemEditingHelpers.jsm"
);

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

const HOUR = 8;

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

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

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

  // Check day view.
  await CalendarTestUtils.setCalendarView(window, "day");
  for (let i = 0; i < 4; i++) {
    await dayView.waitForEventBoxAt(window, 1);
    await CalendarTestUtils.calendarViewForward(window, 14);
  }

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

  for (let i = 0; i < 4; i++) {
    await weekView.waitForEventBoxAt(window, 7, 1);
    await CalendarTestUtils.calendarViewForward(window, 2);
  }

  // Check multiweek view.
  await CalendarTestUtils.setCalendarView(window, "multiweek");
  await CalendarTestUtils.goToDate(window, 2009, 1, 31);

  // Always two occurrences in view, 1st and 3rd or 2nd and 4th week.
  for (let i = 0; i < 5; i++) {
    await multiweekView.waitForItemAt(window, (i % 2) + 1, 7, 1);
    Assert.ok(multiweekView.getItemAt(window, (i % 2) + 3, 7, 1));
    await CalendarTestUtils.calendarViewForward(window, 1);
  }

  // Check month view.
  await CalendarTestUtils.setCalendarView(window, "month");
  await CalendarTestUtils.goToDate(window, 2009, 1, 31);

  // January
  await monthView.waitForItemAt(window, 5, 7, 1);
  await CalendarTestUtils.calendarViewForward(window, 1);

  // February
  await monthView.waitForItemAt(window, 2, 7, 1);
  Assert.ok(monthView.getItemAt(window, 4, 7, 1));
  await CalendarTestUtils.calendarViewForward(window, 1);

  // March
  await monthView.waitForItemAt(window, 2, 7, 1);

  let box = monthView.getItemAt(window, 4, 7, 1);
  Assert.ok(box);

  // Delete event.
  EventUtils.synthesizeMouseAtCenter(box, {}, window);
  await handleDeleteOccurrencePrompt(window, box, true);

  await monthView.waitForNoItemAt(window, 4, 7, 1);

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