Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / notificationModel.spec.js
blob77f2ae7824303d3d4a6689525b9ccb5e2fe5afb5
1 import { triggerToModel } from '@proton/shared/lib/calendar/alarms/notificationModel';
2 import { NOTIFICATION_TYPE_API, NOTIFICATION_UNITS, NOTIFICATION_WHEN } from '@proton/shared/lib/calendar/constants';
3 import { fromTriggerString } from '@proton/shared/lib/calendar/vcal';
5 const { DEVICE } = NOTIFICATION_TYPE_API;
6 const { WEEK, DAY, HOUR, MINUTE } = NOTIFICATION_UNITS;
7 const { AFTER, BEFORE } = NOTIFICATION_WHEN;
9 describe('properties to model positive trigger', () => {
10 test('part day 0', () => {
11 expect(
12 triggerToModel({
13 isAllDay: false,
14 type: DEVICE,
15 trigger: fromTriggerString('PT0S'),
17 ).toEqual({
18 isAllDay: false,
19 value: 0,
20 unit: MINUTE,
21 type: DEVICE,
22 when: AFTER,
23 });
24 });
26 test('part day trigger 1 minute', () => {
27 expect(
28 triggerToModel({
29 isAllDay: false,
30 type: DEVICE,
31 trigger: fromTriggerString('PT1M'),
33 ).toEqual({
34 isAllDay: false,
35 value: 1,
36 unit: MINUTE,
37 type: DEVICE,
38 when: AFTER,
39 });
40 });
42 test('all day trigger at 10:01 on the same day', () => {
43 expect(
44 triggerToModel({
45 isAllDay: true,
46 type: DEVICE,
47 trigger: fromTriggerString('PT10H1M'),
49 ).toEqual({
50 isAllDay: true,
51 value: 0,
52 unit: DAY,
53 type: DEVICE,
54 when: AFTER,
55 at: new Date(2000, 0, 1, 10, 1),
56 });
57 });
59 test('all day trigger at 10:01 a day after', () => {
60 expect(
61 triggerToModel({
62 isAllDay: true,
63 type: DEVICE,
64 trigger: fromTriggerString('PT1D10H1M'),
66 ).toEqual({
67 isAllDay: true,
68 value: 1,
69 unit: DAY,
70 type: DEVICE,
71 when: AFTER,
72 at: new Date(2000, 0, 1, 10, 1),
73 });
74 });
76 test('all day trigger at 10:01 a week after', () => {
77 expect(
78 triggerToModel({
79 isAllDay: true,
80 type: DEVICE,
81 trigger: fromTriggerString('PT1W10H1M'),
83 ).toEqual({
84 isAllDay: true,
85 value: 1,
86 unit: WEEK,
87 type: DEVICE,
88 when: AFTER,
89 at: new Date(2000, 0, 1, 10, 1),
90 });
91 });
93 test('all day trigger at 10:01 a week and two days after', () => {
94 expect(
95 triggerToModel({
96 isAllDay: true,
97 type: DEVICE,
98 trigger: fromTriggerString('PT1W2D10H1M'),
100 ).toEqual({
101 isAllDay: true,
102 value: 9,
103 unit: DAY,
104 type: DEVICE,
105 when: AFTER,
106 at: new Date(2000, 0, 1, 10, 1),
111 describe('properties to model negative trigger', () => {
112 test('part day notification 15 hours before', () => {
113 expect(
114 triggerToModel({
115 isAllDay: false,
116 type: DEVICE,
117 trigger: fromTriggerString('-PT15H'),
119 ).toEqual({
120 isAllDay: false,
121 value: 15,
122 unit: HOUR,
123 type: DEVICE,
124 when: BEFORE,
128 test('part day notification 1 day before', () => {
129 expect(
130 triggerToModel({
131 isAllDay: false,
132 type: DEVICE,
133 trigger: fromTriggerString('-PT1D'),
135 ).toEqual({
136 isAllDay: false,
137 value: 1,
138 unit: DAY,
139 type: DEVICE,
140 when: BEFORE,
144 test('part day notification 1 day and 15 hours before', () => {
145 expect(
146 triggerToModel({
147 isAllDay: false,
148 type: DEVICE,
149 trigger: fromTriggerString('-PT1D15H'),
151 ).toEqual({
152 isAllDay: false,
153 value: 39,
154 unit: HOUR,
155 type: DEVICE,
156 when: BEFORE,
160 test('part day notification 60 minutes before', () => {
161 expect(
162 triggerToModel({
163 isAllDay: false,
164 type: DEVICE,
165 trigger: fromTriggerString('-PT60M'),
167 ).toEqual({
168 isAllDay: false,
169 value: 60,
170 unit: MINUTE,
171 type: DEVICE,
172 when: BEFORE,
176 test('part day notification with two components 1 week minutes before', () => {
177 expect(
178 triggerToModel({
179 isAllDay: false,
180 type: DEVICE,
181 trigger: fromTriggerString('-PT24H6D'),
183 ).toEqual({
184 isAllDay: false,
185 value: 1,
186 unit: WEEK,
187 type: DEVICE,
188 when: BEFORE,
192 test('all day notification 1 day before at 00:00', () => {
193 expect(
194 triggerToModel({
195 isAllDay: true,
196 type: DEVICE,
197 trigger: fromTriggerString('-PT1D'),
199 ).toEqual({
200 isAllDay: true,
201 value: 1,
202 unit: DAY,
203 type: DEVICE,
204 when: BEFORE,
205 at: new Date(2000, 0, 1, 0, 0),
209 test('all day notification 1 day before at 13:50', () => {
210 expect(
211 triggerToModel({
212 isAllDay: true,
213 type: DEVICE,
214 trigger: fromTriggerString('-PT10H10M'),
216 ).toEqual({
217 isAllDay: true,
218 value: 1,
219 unit: DAY,
220 type: DEVICE,
221 when: BEFORE,
222 at: new Date(2000, 0, 1, 13, 50),
226 test('all day notification 1 week before at 00:00', () => {
227 expect(
228 triggerToModel({
229 isAllDay: true,
230 type: DEVICE,
231 trigger: fromTriggerString('-PT1W'),
233 ).toEqual({
234 isAllDay: true,
235 value: 1,
236 unit: WEEK,
237 type: DEVICE,
238 when: BEFORE,
239 at: new Date(2000, 0, 1, 0, 0),
243 test('all day notification 1 week and 6 days before', () => {
244 expect(
245 triggerToModel({
246 isAllDay: true,
247 type: DEVICE,
248 trigger: fromTriggerString('-PT1W6D'),
250 ).toEqual({
251 isAllDay: true,
252 value: 13,
253 unit: DAY,
254 type: DEVICE,
255 when: BEFORE,
256 at: new Date(2000, 0, 1, 0, 0),
260 test('all day notification 1 week before at 13:50', () => {
261 expect(
262 triggerToModel({
263 isAllDay: true,
264 type: DEVICE,
265 trigger: fromTriggerString('-PT6D10H10M'),
267 ).toEqual({
268 isAllDay: true,
269 value: 1,
270 unit: WEEK,
271 type: DEVICE,
272 when: BEFORE,
273 at: new Date(2000, 0, 1, 13, 50),
277 test('all day notification 2 weeks before at 13:50', () => {
278 expect(
279 triggerToModel({
280 isAllDay: true,
281 type: DEVICE,
282 trigger: fromTriggerString('-PT1W6D10H10M'),
284 ).toEqual({
285 isAllDay: true,
286 value: 2,
287 unit: WEEK,
288 type: DEVICE,
289 when: BEFORE,
290 at: new Date(2000, 0, 1, 13, 50),
294 test('all day notification 1 week and 6 days before at 13:50', () => {
295 expect(
296 triggerToModel({
297 isAllDay: true,
298 type: DEVICE,
299 trigger: fromTriggerString('-PT1W5D10H10M'),
301 ).toEqual({
302 isAllDay: true,
303 value: 13,
304 unit: DAY,
305 type: DEVICE,
306 when: BEFORE,
307 at: new Date(2000, 0, 1, 13, 50),
311 test('all day notification 8 days before at 15:35 in two ways', () => {
312 expect(
313 triggerToModel({
314 isAllDay: true,
315 type: DEVICE,
316 trigger: fromTriggerString('-P1WT8H25M'),
318 ).toEqual({
319 isAllDay: true,
320 value: 8,
321 unit: DAY,
322 type: DEVICE,
323 when: BEFORE,
324 at: new Date(2000, 0, 1, 15, 35),
327 expect(
328 triggerToModel({
329 isAllDay: true,
330 type: DEVICE,
331 trigger: fromTriggerString('-P7DT8H25M'),
333 ).toEqual({
334 isAllDay: true,
335 value: 8,
336 unit: DAY,
337 type: DEVICE,
338 when: BEFORE,
339 at: new Date(2000, 0, 1, 15, 35),