summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/browser/recurrence/browser_annual.js
blob: 54c7198f052dcd58da1b492aa2975b5ec33c8590 (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
/* 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 STARTYEAR = 1950;
const EPOCH = 1970;

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

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

  // Create yearly recurring all-day event.
  let eventBox = dayView.getAllDayHeader(window);
  let { dialogWindow, iframeWindow } = await CalendarTestUtils.editNewEvent(window, eventBox);
  await setData(dialogWindow, iframeWindow, { title: "Event", repeat: "yearly" });
  await saveAndCloseItemDialog(dialogWindow);
  await TestUtils.waitForCondition(
    () => CalendarTestUtils.dayView.getAllDayItemAt(window, 1),
    "recurring all-day event created"
  );

  let checkYears = [STARTYEAR, STARTYEAR + 1, EPOCH - 1, EPOCH, EPOCH + 1];
  for (let year of checkYears) {
    await CalendarTestUtils.goToDate(window, year, 1, 1);
    let date = new Date(Date.UTC(year, 0, 1));
    let column = date.getUTCDay() + 1;

    // day view
    await CalendarTestUtils.setCalendarView(window, "day");
    await dayView.waitForAllDayItemAt(window, 1);

    // week view
    await CalendarTestUtils.setCalendarView(window, "week");
    await weekView.waitForAllDayItemAt(window, column, 1);

    // multiweek view
    await CalendarTestUtils.setCalendarView(window, "multiweek");
    await multiweekView.waitForItemAt(window, 1, column, 1);

    // month view
    await CalendarTestUtils.setCalendarView(window, "month");
    await monthView.waitForItemAt(window, 1, column, 1);
  }

  // Delete event.
  await CalendarTestUtils.goToDate(window, checkYears[0], 1, 1);
  await CalendarTestUtils.setCalendarView(window, "day");
  const box = await dayView.waitForAllDayItemAt(window, 1);
  EventUtils.synthesizeMouseAtCenter(box, {}, window);
  await handleDeleteOccurrencePrompt(window, box, true);
  await TestUtils.waitForCondition(() => !dayView.getAllDayItemAt(window, 1), "No all-day events");

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