Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / propertiesToModel.spec.ts
bloba3ce73184e4bf5f2e67b4c94f76a33c34eb62989
1 import { parse } from '@proton/shared/lib/calendar/vcal';
2 import type { VcalVeventComponent } from '@proton/shared/lib/interfaces/calendar';
4 import { propertiesToModel } from './propertiesToModel';
6 describe('properties to model', () => {
7     test('can parse start and end time correctly', () => {
8         const VEVENT = `BEGIN:VEVENT
9 DTSTART;TZID=America/New_York:20190719T120000
10 DTEND;TZID=Europe/Zurich:20190719T183000
11 SUMMARY:My title
12 END:VEVENT`;
13         expect(
14             propertiesToModel({
15                 veventComponent: parse(VEVENT) as VcalVeventComponent,
16                 hasDefaultNotifications: true,
17                 isAllDay: false,
18                 isProtonProtonInvite: false,
19                 tzid: 'Europe/Zurich',
20             })
21         ).toMatchObject({
22             title: 'My title',
23             start: {
24                 date: new Date(2019, 6, 19),
25                 time: new Date(2000, 0, 1, 12),
26                 tzid: 'America/New_York',
27             },
28             end: {
29                 date: new Date(2019, 6, 19),
30                 time: new Date(2000, 0, 1, 18, 30),
31                 tzid: 'Europe/Zurich',
32             },
33         });
34     });
36     test('it allows end before start in part day event', () => {
37         const VEVENT = `BEGIN:VEVENT
38 DTSTART;TZID=Europe/Zurich:20190719T120000
39 DTEND;TZID=Europe/Zurich:20190719T110000
40 END:VEVENT`;
41         expect(
42             propertiesToModel({
43                 veventComponent: parse(VEVENT) as VcalVeventComponent,
44                 hasDefaultNotifications: true,
45                 isAllDay: false,
46                 isProtonProtonInvite: false,
47                 tzid: 'Europe/Zurich',
48             })
49         ).toMatchObject({
50             start: {
51                 date: new Date(2019, 6, 19),
52                 time: new Date(2000, 0, 1, 12),
53                 tzid: 'Europe/Zurich',
54             },
55             end: {
56                 date: new Date(2019, 6, 19),
57                 time: new Date(2000, 0, 1, 11),
58                 tzid: 'Europe/Zurich',
59             },
60         });
61     });
63     test('it allows end before start in full day event', () => {
64         const VEVENT = `BEGIN:VEVENT
65 DTSTART;VALUE=DATE:20190719
66 DTEND;VALUE=DATE:20190718
67 END:VEVENT`;
68         expect(
69             propertiesToModel({
70                 veventComponent: parse(VEVENT) as VcalVeventComponent,
71                 hasDefaultNotifications: true,
72                 isAllDay: true,
73                 isProtonProtonInvite: false,
74                 tzid: 'Europe/Zurich',
75             })
76         ).toMatchObject({
77             start: {
78                 date: new Date(2019, 6, 19),
79                 time: new Date(2000, 0, 1, 0),
80             },
81             end: {
82                 date: new Date(2019, 6, 17),
83                 time: new Date(2000, 0, 1, 0),
84             },
85         });
86     });
87 });