1 import { buildMailTo } from '@proton/shared/lib/helpers/email';
6 getDateTimePropertyInDifferentTimezone,
7 getHasModifiedDateTimes,
8 getIsEquivalentOrganizer,
12 } from '../../lib/calendar/vcalConverter';
14 describe('propertyToUTCDate', () => {
15 it('should convert all-day properties to UTC end-of-day times', () => {
17 value: { year: 2021, month: 7, day: 7 },
18 parameters: { type: 'date' },
20 expect(+propertyToUTCDate(property)).toEqual(Date.UTC(2021, 6, 7));
23 it('should convert Zulu date-time properties', () => {
25 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: true },
27 expect(+propertyToUTCDate(property)).toEqual(Date.UTC(2021, 6, 7, 7, 7, 7));
30 it('should convert floating date-time properties to Zulu time', () => {
32 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: false },
34 expect(+propertyToUTCDate(property)).toEqual(Date.UTC(2021, 6, 7, 7, 7, 7));
37 it('should convert localized date-time properties', () => {
39 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: false },
40 parameters: { tzid: 'Europe/Brussels' },
42 expect(+propertyToUTCDate(property)).toEqual(Date.UTC(2021, 6, 7, 5, 7, 7));
46 describe('propertyToLocalDate', () => {
47 it('should convert all-day properties to local end-of-day times', () => {
49 value: { year: 2021, month: 7, day: 7 },
50 parameters: { type: 'date' },
52 expect(+propertyToLocalDate(property)).toEqual(+new Date(2021, 6, 7));
55 it('should convert Zulu date-time properties', () => {
57 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: true },
59 expect(+propertyToLocalDate(property)).toEqual(Date.UTC(2021, 6, 7, 7, 7, 7));
62 it('should convert floating date-time properties to Zulu time', () => {
64 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: false },
66 expect(+propertyToLocalDate(property)).toEqual(Date.UTC(2021, 6, 7, 7, 7, 7));
69 it('should convert localized date-time properties', () => {
71 value: { year: 2021, month: 7, day: 7, hours: 7, minutes: 7, seconds: 7, isUTC: false },
72 parameters: { tzid: 'Europe/Brussels' },
74 expect(+propertyToLocalDate(property)).toEqual(Date.UTC(2021, 6, 7, 5, 7, 7));
78 describe('dateTimeToProperty', () => {
79 it('should convert a date with a timezone into a property', () => {
80 const property = dateTimeToProperty(
91 expect(property).toEqual({
92 value: { year: 2019, month: 10, day: 1, hours: 1, minutes: 13, seconds: 0, isUTC: false },
99 it('should convert utc time', () => {
100 const property = dateTimeToProperty(
110 expect(property).toEqual({
111 value: { year: 2019, month: 10, day: 1, hours: 1, minutes: 13, seconds: 0, isUTC: true },
116 describe('day converter', () => {
117 it('should convert from number to day', () => {
118 expect(numericDayToDay(-3)).toEqual('TH');
119 expect(numericDayToDay(-2)).toEqual('FR');
120 expect(numericDayToDay(-1)).toEqual('SA');
121 expect(numericDayToDay(0)).toEqual('SU');
122 expect(numericDayToDay(1)).toEqual('MO');
123 expect(numericDayToDay(2)).toEqual('TU');
124 expect(numericDayToDay(3)).toEqual('WE');
127 it('should convert from day to number', () => {
128 expect(dayToNumericDay('SU')).toEqual(0);
129 expect(dayToNumericDay('MO')).toEqual(1);
130 expect(dayToNumericDay('TU')).toEqual(2);
131 expect(dayToNumericDay('WE')).toEqual(3);
132 expect(dayToNumericDay('TH')).toEqual(4);
133 expect(dayToNumericDay('FR')).toEqual(5);
134 expect(dayToNumericDay('SA')).toEqual(6);
135 expect(dayToNumericDay('su')).toBeUndefined();
136 expect(dayToNumericDay('asd')).toBeUndefined();
140 describe('getDateTimePropertyInDifferentTimezone', () => {
141 const tzid = 'Pacific/Honolulu';
142 it('should not modify all-day properties', () => {
144 value: { year: 2020, month: 4, day: 23 },
145 parameters: { type: 'date' },
147 expect(getDateTimePropertyInDifferentTimezone(property, tzid)).toEqual(property);
148 expect(getDateTimePropertyInDifferentTimezone(property, tzid, true)).toEqual(property);
151 it('should change the timezone of UTC dates', () => {
153 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: true },
156 value: { year: 2020, month: 4, day: 23, hours: 2, minutes: 30, seconds: 0, isUTC: false },
157 parameters: { tzid },
159 expect(getDateTimePropertyInDifferentTimezone(property, tzid)).toEqual(expected);
162 it('should change the timezone of timezoned dates', () => {
164 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
165 parameters: { tzid: 'Europe/Zurich' },
168 value: { year: 2020, month: 4, day: 23, hours: 0, minutes: 30, seconds: 0, isUTC: false },
169 parameters: { tzid },
171 expect(getDateTimePropertyInDifferentTimezone(property, tzid)).toEqual(expected);
174 it('should return simplified form of UTC dates', () => {
176 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
177 parameters: { tzid: 'Europe/Zurich' },
180 value: { year: 2020, month: 4, day: 23, hours: 10, minutes: 30, seconds: 0, isUTC: true },
182 expect(getDateTimePropertyInDifferentTimezone(property, 'UTC')).toEqual(expected);
186 describe('getHasModifiedDateTimes', () => {
187 it('should detect same times as equal for part-day events', () => {
190 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
191 parameters: { tzid: 'Europe/Zurich' },
194 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
195 parameters: { tzid: 'Europe/Zurich' },
200 value: { year: 2020, month: 4, day: 23, hours: 11, minutes: 30, seconds: 0, isUTC: false },
201 parameters: { tzid: 'Europe/London' },
204 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(false);
207 it('should detect same times as equal for all-day events', () => {
210 value: { year: 2020, month: 4, day: 23 },
211 parameters: { type: 'date' },
214 value: { year: 2020, month: 4, day: 24 },
215 parameters: { type: 'date' },
220 value: { year: 2020, month: 4, day: 23 },
221 parameters: { type: 'date' },
224 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(false);
227 it('should detect different start times as different for part-day events', () => {
230 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
231 parameters: { tzid: 'Europe/Zurich' },
234 value: { year: 2020, month: 4, day: 23, hours: 13, minutes: 30, seconds: 0, isUTC: false },
235 parameters: { tzid: 'Europe/Zurich' },
240 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
241 parameters: { tzid: 'Europe/London' },
244 value: { year: 2020, month: 4, day: 23, hours: 13, minutes: 30, seconds: 0, isUTC: false },
245 parameters: { tzid: 'Europe/Zurich' },
248 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(true);
251 it('should detect different end times as different for all-day events', () => {
254 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
255 parameters: { tzid: 'Europe/Zurich' },
258 value: { year: 2020, month: 4, day: 23, hours: 12, minutes: 30, seconds: 0, isUTC: false },
259 parameters: { tzid: 'Europe/Zurich' },
264 value: { year: 2020, month: 4, day: 23, hours: 11, minutes: 30, seconds: 0, isUTC: false },
265 parameters: { tzid: 'Europe/London' },
268 value: { year: 2020, month: 4, day: 23, hours: 13, minutes: 30, seconds: 0, isUTC: false },
269 parameters: { tzid: 'Europe/Zurich' },
272 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(true);
275 it('should detect different start times as different for all-day events', () => {
278 value: { year: 2020, month: 4, day: 21 },
279 parameters: { type: 'date' },
282 value: { year: 2020, month: 4, day: 24 },
283 parameters: { type: 'date' },
288 value: { year: 2020, month: 4, day: 22 },
289 parameters: { type: 'date' },
292 value: { year: 2020, month: 4, day: 24 },
293 parameters: { type: 'date' },
296 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(true);
299 it('should detect different end times as different for all-day events', () => {
302 value: { year: 2020, month: 4, day: 21 },
303 parameters: { type: 'date' },
308 value: { year: 2020, month: 4, day: 21 },
309 parameters: { type: 'date' },
312 value: { year: 2020, month: 4, day: 24 },
313 parameters: { type: 'date' },
316 expect(getHasModifiedDateTimes(vevent1, vevent2)).toEqual(true);
320 describe('getHasEquivalentOrganizer', () => {
321 it('should return true for organizers that only differ by email property (but have same mailto value)', () => {
323 getIsEquivalentOrganizer(
325 value: buildMailTo('organizer@proton.me'),
332 value: buildMailTo('organizer@proton.me'),
342 it('should return false for organizers whose emails differ by canonicalization', () => {
344 getIsEquivalentOrganizer(
346 value: buildMailTo('organizer@proton.me'),
352 value: buildMailTo('Organizer@proton.me'),
361 it('should return false for organizers that only differ by cn property', () => {
363 getIsEquivalentOrganizer(
365 value: buildMailTo('organizer@proton.me'),
371 value: buildMailTo('organizer@proton.me'),