Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / getValarmTrigger.spec.js
blob8bb397a4cde9e7313b340ffe54973abf2f13a4d0
1 import { getValarmTrigger } from '@proton/shared/lib/calendar/alarms/getValarmTrigger';
2 import { NOTIFICATION_TYPE_API, NOTIFICATION_UNITS, NOTIFICATION_WHEN } from '@proton/shared/lib/calendar/constants';
3 import { toTriggerString } from '@proton/shared/lib/calendar/vcal';
5 const { DEVICE } = NOTIFICATION_TYPE_API;
6 const { DAY, HOUR, WEEK, MINUTE } = NOTIFICATION_UNITS;
7 const { BEFORE, AFTER } = NOTIFICATION_WHEN;
9 describe('model to properties positive trigger', () => {
10     test('0 minutes before', () => {
11         expect(
12             toTriggerString(
13                 getValarmTrigger({
14                     isAllDay: false,
15                     value: 0,
16                     unit: MINUTE,
17                     type: DEVICE,
18                     when: BEFORE,
19                 })
20             )
21         ).toEqual('PT0S');
22     });
24     test('1 minute after', () => {
25         expect(
26             toTriggerString(
27                 getValarmTrigger({
28                     isAllDay: false,
29                     value: 1,
30                     unit: MINUTE,
31                     type: DEVICE,
32                     when: AFTER,
33                 })
34             )
35         ).toEqual('PT1M');
36     });
38     test('same day at 13:50', () => {
39         expect(
40             toTriggerString(
41                 getValarmTrigger({
42                     isAllDay: true,
43                     value: 0,
44                     unit: DAY,
45                     type: DEVICE,
46                     when: AFTER,
47                     at: new Date(2000, 0, 1, 13, 50),
48                 })
49             )
50         ).toEqual('PT13H50M');
51     });
53     test('1 day after at 00:00', () => {
54         expect(
55             toTriggerString(
56                 getValarmTrigger({
57                     isAllDay: true,
58                     value: 1,
59                     unit: DAY,
60                     type: DEVICE,
61                     when: AFTER,
62                     at: new Date(2000, 0, 1, 0, 0),
63                 })
64             )
65         ).toEqual('P1D');
66     });
68     test('1 day after at 13:50', () => {
69         expect(
70             toTriggerString(
71                 getValarmTrigger({
72                     isAllDay: true,
73                     value: 1,
74                     unit: DAY,
75                     type: DEVICE,
76                     when: AFTER,
77                     at: new Date(2000, 0, 1, 13, 50),
78                 })
79             )
80         ).toEqual('P1DT13H50M');
81     });
83     test('1 week after at 13:50', () => {
84         expect(
85             toTriggerString(
86                 getValarmTrigger({
87                     isAllDay: true,
88                     value: 1,
89                     unit: WEEK,
90                     type: DEVICE,
91                     when: AFTER,
92                     at: new Date(2000, 0, 1, 13, 50),
93                 })
94             )
95         ).toEqual('P1WT13H50M');
96     });
97 });
99 describe('model to properties negative trigger', () => {
100     test('1 day before at 00:00', () => {
101         expect(
102             toTriggerString(
103                 getValarmTrigger({
104                     isAllDay: true,
105                     value: 1,
106                     unit: DAY,
107                     type: DEVICE,
108                     when: BEFORE,
109                     at: new Date(2000, 0, 1, 0, 0),
110                 })
111             )
112         ).toEqual('-P1D');
113     });
115     test('1 day before at 13:50', () => {
116         expect(
117             toTriggerString(
118                 getValarmTrigger({
119                     isAllDay: true,
120                     value: 1,
121                     unit: DAY,
122                     type: DEVICE,
123                     when: BEFORE,
124                     at: new Date(2000, 0, 1, 13, 50),
125                 })
126             )
127         ).toEqual('-PT10H10M');
128     });
130     test('2 days before at 00:00', () => {
131         expect(
132             toTriggerString(
133                 getValarmTrigger({
134                     isAllDay: true,
135                     value: 2,
136                     unit: DAY,
137                     type: DEVICE,
138                     when: BEFORE,
139                     at: new Date(2000, 0, 1, 0, 0),
140                 })
141             )
142         ).toEqual('-P2D');
143     });
145     test('2 days before at 13:50', () => {
146         expect(
147             toTriggerString(
148                 getValarmTrigger({
149                     isAllDay: true,
150                     value: 2,
151                     unit: DAY,
152                     type: DEVICE,
153                     when: BEFORE,
154                     at: new Date(2000, 0, 1, 13, 50),
155                 })
156             )
157         ).toEqual('-P1DT10H10M');
158     });
160     test('0 weeks before at 13:50', () => {
161         expect(
162             toTriggerString(
163                 getValarmTrigger({
164                     isAllDay: true,
165                     value: 0,
166                     unit: WEEK,
167                     type: DEVICE,
168                     when: BEFORE,
169                     at: new Date(2000, 0, 1, 13, 50),
170                 })
171             )
172         ).toEqual('-PT10H10M');
173     });
175     test('1 week before at 13:50', () => {
176         expect(
177             toTriggerString(
178                 getValarmTrigger({
179                     isAllDay: true,
180                     value: 1,
181                     unit: WEEK,
182                     type: DEVICE,
183                     when: BEFORE,
184                     at: new Date(2000, 0, 1, 13, 50),
185                 })
186             )
187         ).toEqual('-P6DT10H10M');
188     });
190     test('2 weeks before at 13:50', () => {
191         expect(
192             toTriggerString(
193                 getValarmTrigger({
194                     isAllDay: true,
195                     value: 2,
196                     unit: WEEK,
197                     type: DEVICE,
198                     when: BEFORE,
199                     at: new Date(2000, 0, 1, 13, 50),
200                 })
201             )
202         ).toEqual('-P1W6DT10H10M');
203     });
205     test('1 week before at 00:00', () => {
206         expect(
207             toTriggerString(
208                 getValarmTrigger({
209                     isAllDay: true,
210                     value: 1,
211                     unit: WEEK,
212                     type: DEVICE,
213                     when: BEFORE,
214                     at: new Date(2000, 0, 1, 0, 0),
215                 })
216             )
217         ).toEqual('-P1W');
218     });
220     test('2 weeks before at 00:00', () => {
221         expect(
222             toTriggerString(
223                 getValarmTrigger({
224                     isAllDay: true,
225                     value: 2,
226                     unit: WEEK,
227                     type: DEVICE,
228                     when: BEFORE,
229                     at: new Date(2000, 0, 1, 0, 0),
230                 })
231             )
232         ).toEqual('-P2W');
233     });
235     test('2 weeks before', () => {
236         expect(
237             toTriggerString(
238                 getValarmTrigger({
239                     isAllDay: false,
240                     value: 2,
241                     unit: WEEK,
242                     type: DEVICE,
243                     when: BEFORE,
244                 })
245             )
246         ).toEqual('-P2W');
247     });
249     test('15 minutes before', () => {
250         expect(
251             toTriggerString(
252                 getValarmTrigger({
253                     isAllDay: false,
254                     value: 15,
255                     unit: MINUTE,
256                     type: DEVICE,
257                     when: BEFORE,
258                 })
259             )
260         ).toEqual('-PT15M');
261     });
263     test('1 hour before', () => {
264         expect(
265             toTriggerString(
266                 getValarmTrigger({
267                     isAllDay: false,
268                     value: 1,
269                     unit: HOUR,
270                     type: DEVICE,
271                     when: BEFORE,
272                 })
273             )
274         ).toEqual('-PT1H');
275     });