Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / modelToProperties.spec.ts
bloba320e8d68738d4902ec808b7435c788d33f4cc2d
1 import { NOTIFICATION_TYPE_API, NOTIFICATION_UNITS, NOTIFICATION_WHEN } from '@proton/shared/lib/calendar/constants';
2 import type { EventModel } from '@proton/shared/lib/interfaces/calendar';
4 import { modelToValarmComponents } from './modelToProperties';
6 describe('modelToValarmComponent', () => {
7     describe('part day', () => {
8         it('should transform to valarm components', () => {
9             const model = {
10                 isAllDay: false,
11                 partDayNotifications: [
12                     {
13                         value: 1,
14                         type: NOTIFICATION_TYPE_API.EMAIL,
15                         unit: NOTIFICATION_UNITS.HOUR,
16                         when: NOTIFICATION_WHEN.AFTER,
17                     },
18                     {
19                         value: 15,
20                         type: NOTIFICATION_TYPE_API.DEVICE,
21                         unit: NOTIFICATION_UNITS.MINUTE,
22                         when: NOTIFICATION_WHEN.BEFORE,
23                     },
24                     {
25                         value: 10,
26                         type: NOTIFICATION_TYPE_API.DEVICE,
27                         unit: NOTIFICATION_UNITS.MINUTE,
28                         when: NOTIFICATION_WHEN.BEFORE,
29                     },
30                 ],
31             } as EventModel;
32             expect(modelToValarmComponents(model)).toEqual(
33                 expect.arrayContaining([
34                     {
35                         component: 'valarm',
36                         action: {
37                             value: 'EMAIL',
38                         },
39                         trigger: {
40                             value: {
41                                 days: 0,
42                                 hours: 1,
43                                 isNegative: false,
44                                 minutes: 0,
45                                 seconds: 0,
46                                 weeks: 0,
47                             },
48                         },
49                     },
50                     {
51                         component: 'valarm',
52                         action: {
53                             value: 'DISPLAY',
54                         },
55                         trigger: {
56                             value: {
57                                 days: 0,
58                                 hours: 0,
59                                 isNegative: true,
60                                 minutes: 15,
61                                 seconds: 0,
62                                 weeks: 0,
63                             },
64                         },
65                     },
66                     {
67                         component: 'valarm',
68                         action: {
69                             value: 'DISPLAY',
70                         },
71                         trigger: {
72                             value: {
73                                 days: 0,
74                                 hours: 0,
75                                 isNegative: true,
76                                 minutes: 10,
77                                 seconds: 0,
78                                 weeks: 0,
79                             },
80                         },
81                     },
82                 ])
83             );
84         });
86         it('should remove duplicate notifications (part day)', () => {
87             const model = {
88                 isAllDay: false,
89                 partDayNotifications: [
90                     {
91                         value: 1,
92                         type: NOTIFICATION_TYPE_API.EMAIL,
93                         unit: NOTIFICATION_UNITS.HOUR,
94                         when: NOTIFICATION_WHEN.AFTER,
95                     },
96                     {
97                         value: 1,
98                         type: NOTIFICATION_TYPE_API.DEVICE,
99                         unit: NOTIFICATION_UNITS.HOUR,
100                         when: NOTIFICATION_WHEN.BEFORE,
101                     },
102                     {
103                         value: 60,
104                         type: NOTIFICATION_TYPE_API.DEVICE,
105                         unit: NOTIFICATION_UNITS.MINUTE,
106                         when: NOTIFICATION_WHEN.BEFORE,
107                     },
108                     {
109                         value: 15,
110                         type: NOTIFICATION_TYPE_API.DEVICE,
111                         unit: NOTIFICATION_UNITS.MINUTE,
112                         when: NOTIFICATION_WHEN.BEFORE,
113                     },
114                     {
115                         value: 15,
116                         type: NOTIFICATION_TYPE_API.DEVICE,
117                         unit: NOTIFICATION_UNITS.MINUTE,
118                         when: NOTIFICATION_WHEN.BEFORE,
119                     },
120                 ],
121             } as EventModel;
122             expect(modelToValarmComponents(model)).toEqual([
123                 {
124                     component: 'valarm',
125                     action: {
126                         value: 'EMAIL',
127                     },
128                     trigger: {
129                         value: {
130                             days: 0,
131                             hours: 1,
132                             isNegative: false,
133                             minutes: 0,
134                             seconds: 0,
135                             weeks: 0,
136                         },
137                     },
138                 },
139                 {
140                     component: 'valarm',
141                     action: {
142                         value: 'DISPLAY',
143                     },
144                     trigger: {
145                         value: {
146                             days: 0,
147                             hours: 1,
148                             isNegative: true,
149                             minutes: 0,
150                             seconds: 0,
151                             weeks: 0,
152                         },
153                     },
154                 },
155                 {
156                     component: 'valarm',
157                     action: {
158                         value: 'DISPLAY',
159                     },
160                     trigger: {
161                         value: {
162                             days: 0,
163                             hours: 0,
164                             isNegative: true,
165                             minutes: 15,
166                             seconds: 0,
167                             weeks: 0,
168                         },
169                     },
170                 },
171             ]);
172         });
173     });
175     describe('all day', () => {
176         it('should transform to valarm components', () => {
177             const model = {
178                 isAllDay: true,
179                 fullDayNotifications: [
180                     {
181                         value: 1,
182                         type: NOTIFICATION_TYPE_API.EMAIL,
183                         unit: NOTIFICATION_UNITS.DAY,
184                         when: NOTIFICATION_WHEN.AFTER,
185                         isAllDay: true,
186                         at: new Date(2000, 0, 1, 10, 1),
187                     },
188                     {
189                         value: 1,
190                         type: NOTIFICATION_TYPE_API.DEVICE,
191                         unit: NOTIFICATION_UNITS.DAY,
192                         when: NOTIFICATION_WHEN.BEFORE,
193                         isAllDay: true,
194                         at: new Date(2000, 0, 1, 10, 1),
195                     },
196                     {
197                         value: 2,
198                         type: NOTIFICATION_TYPE_API.DEVICE,
199                         unit: NOTIFICATION_UNITS.DAY,
200                         when: NOTIFICATION_WHEN.BEFORE,
201                         isAllDay: true,
202                         at: new Date(2000, 0, 1, 10, 1),
203                     },
204                 ],
205             } as EventModel;
206             expect(modelToValarmComponents(model)).toEqual([
207                 {
208                     component: 'valarm',
209                     action: {
210                         value: 'EMAIL',
211                     },
212                     trigger: {
213                         value: {
214                             days: 1,
215                             hours: 10,
216                             isNegative: false,
217                             minutes: 1,
218                             seconds: 0,
219                             weeks: 0,
220                         },
221                     },
222                 },
223                 {
224                     component: 'valarm',
225                     action: {
226                         value: 'DISPLAY',
227                     },
228                     trigger: {
229                         value: {
230                             days: 0,
231                             hours: 13,
232                             isNegative: true,
233                             minutes: 59,
234                             seconds: 0,
235                             weeks: 0,
236                         },
237                     },
238                 },
239                 {
240                     component: 'valarm',
241                     action: {
242                         value: 'DISPLAY',
243                     },
244                     trigger: {
245                         value: {
246                             days: 1,
247                             hours: 13,
248                             isNegative: true,
249                             minutes: 59,
250                             seconds: 0,
251                             weeks: 0,
252                         },
253                     },
254                 },
255             ]);
256         });
258         it('should remove duplicate notifications', () => {
259             const model = {
260                 isAllDay: true,
261                 fullDayNotifications: [
262                     {
263                         value: 1,
264                         type: NOTIFICATION_TYPE_API.EMAIL,
265                         unit: NOTIFICATION_UNITS.DAY,
266                         when: NOTIFICATION_WHEN.AFTER,
267                         isAllDay: true,
268                         at: new Date(2000, 0, 1, 10, 1),
269                     },
270                     {
271                         value: 1,
272                         type: NOTIFICATION_TYPE_API.EMAIL,
273                         unit: NOTIFICATION_UNITS.DAY,
274                         when: NOTIFICATION_WHEN.AFTER,
275                         isAllDay: true,
276                         at: new Date(2000, 0, 1, 10, 1),
277                     },
278                     {
279                         value: 1,
280                         type: NOTIFICATION_TYPE_API.DEVICE,
281                         unit: NOTIFICATION_UNITS.DAY,
282                         when: NOTIFICATION_WHEN.AFTER,
283                         isAllDay: true,
284                         at: new Date(2000, 0, 1, 10, 1),
285                     },
286                     {
287                         value: 1,
288                         type: NOTIFICATION_TYPE_API.DEVICE,
289                         unit: NOTIFICATION_UNITS.DAY,
290                         when: NOTIFICATION_WHEN.AFTER,
291                         isAllDay: true,
292                         at: new Date(2000, 0, 1, 10, 1),
293                     },
294                     {
295                         value: 1,
296                         type: NOTIFICATION_TYPE_API.DEVICE,
297                         unit: NOTIFICATION_UNITS.DAY,
298                         when: NOTIFICATION_WHEN.BEFORE,
299                         isAllDay: true,
300                         at: new Date(2000, 0, 1, 10, 1),
301                     },
302                     {
303                         value: 2,
304                         type: NOTIFICATION_TYPE_API.DEVICE,
305                         unit: NOTIFICATION_UNITS.DAY,
306                         when: NOTIFICATION_WHEN.BEFORE,
307                         isAllDay: true,
308                         at: new Date(2000, 0, 1, 10, 1),
309                     },
310                     {
311                         value: 0,
312                         type: NOTIFICATION_TYPE_API.DEVICE,
313                         unit: NOTIFICATION_UNITS.DAY,
314                         when: NOTIFICATION_WHEN.BEFORE,
315                         isAllDay: true,
316                         at: new Date(2000, 0, 1, 10, 1),
317                     },
318                     {
319                         value: 0,
320                         type: NOTIFICATION_TYPE_API.DEVICE,
321                         unit: NOTIFICATION_UNITS.WEEK,
322                         when: NOTIFICATION_WHEN.BEFORE,
323                         isAllDay: true,
324                         at: new Date(2000, 0, 1, 10, 1),
325                     },
326                 ],
327             } as EventModel;
328             expect(modelToValarmComponents(model)).toEqual(
329                 expect.arrayContaining([
330                     {
331                         component: 'valarm',
332                         action: {
333                             value: 'EMAIL',
334                         },
335                         trigger: {
336                             value: {
337                                 days: 1,
338                                 hours: 10,
339                                 isNegative: false,
340                                 minutes: 1,
341                                 seconds: 0,
342                                 weeks: 0,
343                             },
344                         },
345                     },
346                     {
347                         component: 'valarm',
348                         action: {
349                             value: 'DISPLAY',
350                         },
351                         trigger: {
352                             value: {
353                                 days: 1,
354                                 hours: 10,
355                                 isNegative: false,
356                                 minutes: 1,
357                                 seconds: 0,
358                                 weeks: 0,
359                             },
360                         },
361                     },
362                     {
363                         component: 'valarm',
364                         action: {
365                             value: 'DISPLAY',
366                         },
367                         trigger: {
368                             value: {
369                                 days: 0,
370                                 hours: 13,
371                                 isNegative: true,
372                                 minutes: 59,
373                                 seconds: 0,
374                                 weeks: 0,
375                             },
376                         },
377                     },
378                     {
379                         component: 'valarm',
380                         action: {
381                             value: 'DISPLAY',
382                         },
383                         trigger: {
384                             value: {
385                                 days: 1,
386                                 hours: 13,
387                                 isNegative: true,
388                                 minutes: 59,
389                                 seconds: 0,
390                                 weeks: 0,
391                             },
392                         },
393                     },
394                 ])
395             );
396         });
397     });