summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_bug485571.js
blob: 855109b7e89a552e2d08f6723d93297bbe04ef66 (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
/* 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 { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs");

XPCOMUtils.defineLazyModuleGetters(this, {
  CalAlarm: "resource:///modules/CalAlarm.jsm",
});

function run_test() {
  // Check that the RELATED property is correctly set
  // after parsing the given VALARM component

  // trigger set 15 minutes prior to the start of the event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER:-PT15M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_START
  );

  // trigger set 15 minutes prior to the start of the event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;VALUE=DURATION:-PT15M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_START
  );

  // trigger set 15 minutes prior to the start of the event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;RELATED=START:-PT15M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_START
  );

  // trigger set 15 minutes prior to the start of the event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;VALUE=DURATION;RELATED=START:-PT15M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_START
  );

  // trigger set 5 minutes after the end of an event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;RELATED=END:PT5M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_END
  );

  // trigger set 5 minutes after the end of an event
  check_relative(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;VALUE=DURATION;RELATED=END:PT5M\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM",
    Ci.calIAlarm.ALARM_RELATED_END
  );

  // trigger set to an absolute date/time
  check_absolute(
    "BEGIN:VALARM\n" +
      "ACTION:DISPLAY\n" +
      "TRIGGER;VALUE=DATE-TIME:20090430T080000Z\n" +
      "DESCRIPTION:TEST\n" +
      "END:VALARM"
  );
}

function check_relative(aIcalString, aRelated) {
  let alarm = new CalAlarm();
  alarm.icalString = aIcalString;
  equal(alarm.related, aRelated);
  equal(alarm.alarmDate, null);
  notEqual(alarm.offset, null);
}

function check_absolute(aIcalString) {
  let alarm = new CalAlarm();
  alarm.icalString = aIcalString;
  equal(alarm.related, Ci.calIAlarm.ALARM_RELATED_ABSOLUTE);
  ok(alarm.alarmDate != null);
  equal(alarm.offset, null);
}