1 import { END_TYPE, FREQUENCY, MONTHLY_TYPE, WEEKLY_TYPE } from '@proton/shared/lib/calendar/constants';
3 import { propertiesToFrequencyModel } from './propertiesToFrequencyModel';
4 import { getInitialFrequencyModel } from './state';
6 jest.mock('@proton/shared/lib/helpers/setupCryptoWorker', () => ({
8 loadCryptoWorker: jest.fn(),
12 date: new Date(2020, 0, 20),
14 const dummyFrequencyModel = (rrule) => ({
15 ...getInitialFrequencyModel(startModel.date),
16 vcalRruleValue: rrule.value,
19 describe('frequency properties to model, daily recurring rule', () => {
20 test('non-custom: single day, recurring never ends', () => {
26 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
27 ...dummyFrequencyModel(rrule),
28 type: FREQUENCY.DAILY,
29 frequency: FREQUENCY.DAILY,
33 test('every three days, recurring never ends', () => {
40 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
41 ...dummyFrequencyModel(rrule),
42 type: FREQUENCY.CUSTOM,
43 frequency: FREQUENCY.DAILY,
48 test('every two days, recurring ends after 5 occurrences', () => {
56 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
57 ...dummyFrequencyModel(rrule),
58 type: FREQUENCY.CUSTOM,
59 frequency: FREQUENCY.DAILY,
62 type: END_TYPE.AFTER_N_TIMES,
68 test('recursion ends on 30th January on Europe/Athens timezone', () => {
69 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: true };
70 const date = new Date(2020, 0, 30);
80 tzid: 'Europe/Athens',
82 expect(propertiesToFrequencyModel(rrule, startAthens)).toEqual({
83 ...dummyFrequencyModel(rrule),
84 type: FREQUENCY.CUSTOM,
85 frequency: FREQUENCY.DAILY,
93 test('all-day event every two days, recursion ends on 30th January', () => {
94 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: false };
95 const date = new Date(2020, 0, 30);
105 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
106 ...dummyFrequencyModel(rrule),
107 type: FREQUENCY.CUSTOM,
108 frequency: FREQUENCY.DAILY,
111 type: END_TYPE.UNTIL,
119 describe('frequency properties to model, weekly recurring rule', () => {
120 test('non-custom: single day, recurring never ends', () => {
126 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
127 ...dummyFrequencyModel(rrule),
128 type: FREQUENCY.WEEKLY,
132 test('single day, every three weeks, recurring never ends', () => {
140 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
141 ...dummyFrequencyModel(rrule),
142 type: FREQUENCY.CUSTOM,
143 frequency: FREQUENCY.WEEKLY,
148 test('two days, recurring never ends', () => {
156 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
157 ...dummyFrequencyModel(rrule),
158 type: FREQUENCY.CUSTOM,
159 frequency: FREQUENCY.WEEKLY,
162 type: WEEKLY_TYPE.ON_DAYS,
168 test('three days, recurring ends after 5 occurrences', () => {
172 byday: ['MO', 'WE', 'FR'],
176 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
177 ...dummyFrequencyModel(rrule),
178 type: FREQUENCY.CUSTOM,
179 frequency: FREQUENCY.WEEKLY,
181 type: WEEKLY_TYPE.ON_DAYS,
185 type: END_TYPE.AFTER_N_TIMES,
191 test('three days, recursion ends on 30th January on Europe/Athens timezone', () => {
192 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: true };
193 const date = new Date(2020, 0, 30);
198 byday: ['MO', 'WE', 'FR'],
202 const startAthens = {
204 tzid: 'Europe/Athens',
206 expect(propertiesToFrequencyModel(rrule, startAthens)).toEqual({
207 ...dummyFrequencyModel(rrule),
208 type: FREQUENCY.CUSTOM,
209 frequency: FREQUENCY.WEEKLY,
211 type: WEEKLY_TYPE.ON_DAYS,
215 type: END_TYPE.UNTIL,
222 test('one all-day event, recursion ends on 30th January', () => {
223 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: false };
224 const date = new Date(2020, 0, 30);
229 byday: ['MO', 'WE', 'FR'],
234 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
235 ...dummyFrequencyModel(rrule),
236 type: FREQUENCY.CUSTOM,
237 frequency: FREQUENCY.WEEKLY,
239 type: WEEKLY_TYPE.ON_DAYS,
243 type: END_TYPE.UNTIL,
251 describe('frequency properties to model, monthly recurring rule', () => {
252 test('non-custom: single day, recurring never ends', () => {
258 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
259 ...dummyFrequencyModel(rrule),
260 type: FREQUENCY.MONTHLY,
261 frequency: FREQUENCY.MONTHLY,
265 test('single day, every three months, recurring never ends', () => {
272 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
273 ...dummyFrequencyModel(rrule),
274 type: FREQUENCY.CUSTOM,
275 frequency: FREQUENCY.MONTHLY,
280 test('every month on the last Monday, lasting 5 times', () => {
281 const lastMondayStart = {
282 date: new Date(2020, 0, 27),
292 expect(propertiesToFrequencyModel(rrule, lastMondayStart)).toEqual({
293 ...getInitialFrequencyModel(lastMondayStart.date),
294 type: FREQUENCY.CUSTOM,
295 frequency: FREQUENCY.MONTHLY,
297 type: MONTHLY_TYPE.ON_MINUS_NTH_DAY,
300 type: END_TYPE.AFTER_N_TIMES,
303 vcalRruleValue: rrule.value,
307 test('every other month on the 12th, recurring ends after 2 occurrences', () => {
308 const twelvethStart = {
309 date: new Date(2020, 0, 12),
319 expect(propertiesToFrequencyModel(rrule, twelvethStart)).toEqual({
320 ...getInitialFrequencyModel(twelvethStart.date),
321 type: FREQUENCY.CUSTOM,
322 frequency: FREQUENCY.MONTHLY,
325 type: END_TYPE.AFTER_N_TIMES,
328 vcalRruleValue: rrule.value,
332 test('every second Wednesday, recursion ends on 30th January on Europe/Athens timezone', () => {
333 const secondWednesdayStart = {
334 date: new Date(2020, 0, 8),
335 tzid: 'Europe/Athens',
337 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: true };
338 const date = new Date(2020, 0, 30);
349 expect(propertiesToFrequencyModel(rrule, secondWednesdayStart)).toEqual({
350 ...getInitialFrequencyModel(secondWednesdayStart.date),
351 type: FREQUENCY.CUSTOM,
352 frequency: FREQUENCY.MONTHLY,
354 type: MONTHLY_TYPE.ON_NTH_DAY,
357 type: END_TYPE.UNTIL,
361 vcalRruleValue: rrule.value,
364 test('one all-day event every 12th of every 6 months, recursion ends on 30th January', () => {
365 const twelvethStart = {
366 date: new Date(2020, 0, 12),
368 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: false };
369 const date = new Date(2020, 0, 30);
380 expect(propertiesToFrequencyModel(rrule, twelvethStart)).toEqual({
381 ...getInitialFrequencyModel(twelvethStart.date),
382 type: FREQUENCY.CUSTOM,
383 frequency: FREQUENCY.MONTHLY,
386 type: END_TYPE.UNTIL,
390 vcalRruleValue: rrule.value,
395 describe('frequency properties to model, yearly recurring rule', () => {
396 test('non-custom: single day, recurring never ends', () => {
402 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
403 ...dummyFrequencyModel(rrule),
404 type: FREQUENCY.YEARLY,
405 frequency: FREQUENCY.YEARLY,
409 test('every other year, recurring never ends', () => {
418 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
419 ...dummyFrequencyModel(rrule),
420 type: FREQUENCY.CUSTOM,
421 frequency: FREQUENCY.YEARLY,
426 test('every other year, recurring ends after 5 occurrences', () => {
436 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
437 ...dummyFrequencyModel(rrule),
438 type: FREQUENCY.CUSTOM,
439 frequency: FREQUENCY.YEARLY,
442 type: END_TYPE.AFTER_N_TIMES,
448 test('recursion ends on 30th January 2020 on Europe/Athens timezone', () => {
449 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: true };
450 const date = new Date(2020, 0, 30);
462 tzid: 'Europe/Athens',
464 expect(propertiesToFrequencyModel(rrule, start)).toEqual({
465 ...dummyFrequencyModel(rrule),
466 type: FREQUENCY.CUSTOM,
467 frequency: FREQUENCY.YEARLY,
469 type: END_TYPE.UNTIL,
476 test('all-day event every other year, recursion ends on 30th January 2020', () => {
477 const dateTime = { year: 2020, month: 1, day: 30, hours: 21, minutes: 59, seconds: 59, isUTC: false };
478 const date = new Date(2020, 0, 30);
487 expect(propertiesToFrequencyModel(rrule, startModel)).toEqual({
488 ...dummyFrequencyModel(rrule),
489 type: FREQUENCY.CUSTOM,
490 frequency: FREQUENCY.YEARLY,
493 type: END_TYPE.UNTIL,