1 import { enUS } from 'date-fns/locale';
3 import { FREQUENCY } from '../../lib/calendar/constants';
4 import { getTimezonedFrequencyString } from '../../lib/calendar/recurrence/getFrequencyString';
5 import { getDateTimeProperty, getUntilProperty } from '../../lib/calendar/vcalConverter';
6 import { getFormattedWeekdays } from '../../lib/date/date';
8 const weekdays = getFormattedWeekdays('cccc', { locale: enUS });
9 const dummyTzid = 'Europe/Athens';
10 const options = { currentTzid: dummyTzid, weekdays, locale: enUS };
11 const dummyStart = getDateTimeProperty({ year: 2020, month: 1, day: 20 }, dummyTzid);
12 const dummyUntil = getUntilProperty({ year: 2020, month: 2, day: 20 }, false, dummyTzid);
13 const dummyRruleValue = {
14 freq: FREQUENCY.DAILY,
16 const getRrule = (value) => ({ value: { ...dummyRruleValue, ...value } });
17 const otherTzOptions = { ...options, currentTzid: 'Pacific/Tahiti' };
19 describe('getTimezonedFrequencyString should produce the expected string for daily recurring events', () => {
20 it('should get a standard daily recurring event', () => {
21 expect(getTimezonedFrequencyString(getRrule(dummyRruleValue), dummyStart, options)).toEqual('Daily');
24 it('should get a custom daily recurring event that is actually standard', () => {
25 const rrule = getRrule();
26 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Daily');
29 it('should get a custom daily recurring event happening every 2 days', () => {
30 const rrule = getRrule({
33 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 days');
36 it('should get a custom daily recurring event happening every three days, lasting 5 times', () => {
37 const rrule = getRrule({
41 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 3 days, 5 times');
44 it('should get a custom daily recurring event, until 20th February 2020', () => {
45 const rrule = getRrule({
48 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Daily, until Feb 20, 2020');
51 it('should get a custom daily recurring event happening every two days, lasting 1 time on a different timezone', () => {
52 const rrule = getRrule({
56 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 days, 1 time');
59 it('should get a custom daily event, until 20th February 2020 on a different timezone', () => {
60 const rrule = getRrule({
63 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
64 'Daily, until Feb 20, 2020 (Europe/Athens)'
68 it('should get a custom daily event happening every two days, until 20th February 2020 on a different timezone', () => {
69 const rrule = getRrule({
73 const extendedOptions = otherTzOptions;
74 expect(getTimezonedFrequencyString(rrule, dummyStart, extendedOptions)).toEqual(
75 'Every 2 days, until Feb 20, 2020 (Europe/Athens)'
80 describe('getTimezonedFrequencyString should produce the expected string for weekly recurring events', () => {
81 const getWeeklyRrule = (rrule) => getRrule({ ...rrule, freq: FREQUENCY.WEEKLY });
83 it('should get a standard weekly recurring event', () => {
84 const rrule = getWeeklyRrule();
85 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Weekly on Monday');
88 it('should get a standard weekly recurring event, on a different timezone', () => {
89 const rrule = getWeeklyRrule();
90 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
91 'Weekly on Monday (Europe/Athens)'
95 it('should get a custom weekly recurring event that is actually standard', () => {
96 const rrule = getWeeklyRrule({
99 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Weekly on Monday');
102 it('should get a custom weekly recurring event happening every 2 weeks', () => {
103 const rrule = getWeeklyRrule({
107 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 weeks on Monday');
110 it('should get a custom weekly recurring event happening every 2 weeks, on Monday and Tuesday, lasting 1 time', () => {
111 const rrule = getWeeklyRrule({
116 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual(
117 'Every 2 weeks on Monday, Tuesday, 1 time'
121 it('should get a custom weekly recurring event happening on all days of the week', () => {
122 const rrule = getWeeklyRrule({
124 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
126 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Weekly on all days');
129 it('should get a custom weekly recurring event happening every three weeks, on all days of the week, lasting 5 times', () => {
130 const rrule = getWeeklyRrule({
132 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
135 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 3 weeks on all days, 5 times');
138 it('should get a weekly rrule with an until date in a different timezone', () => {
139 const tzid = 'America/Kentucky/Louisville';
140 const rrule = getWeeklyRrule({
142 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
143 until: getUntilProperty({ year: 2020, month: 10, day: 17 }, false, tzid),
145 const start = getDateTimeProperty({ year: 2020, month: 1, day: 20 }, tzid);
146 expect(getTimezonedFrequencyString(rrule, start, options)).toEqual(
147 'Weekly on all days, until Oct 17, 2020 (America/Kentucky/Louisville)'
151 it('should get a custom weekly recurring event happening every three weeks, on all days of the week, until 20th February 2020', () => {
152 const rrule = getWeeklyRrule({
154 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
157 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual(
158 'Every 3 weeks on all days, until Feb 20, 2020'
162 it('should get a custom weekly recurring event happening on Monday and Wednesday, until 20th February 2020', () => {
163 const rrule = getWeeklyRrule({
167 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual(
168 'Weekly on Monday, Wednesday, until Feb 20, 2020'
172 it('should get a custom weekly recurring event happening every 2 weeks on Monday and Wednesday, until 20th February 2020', () => {
173 const rrule = getWeeklyRrule({
178 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual(
179 'Every 2 weeks on Monday, Wednesday, until Feb 20, 2020'
183 it('should get a custom weekly recurring event happening weekly on Monday, on a different timezone', () => {
184 const rrule = getWeeklyRrule({
189 expect(getTimezonedFrequencyString(rrule, dummyStart, { ...options, currentTzid: 'Pacific/Tahiti ' })).toEqual(
190 'Weekly on Monday, until Feb 20, 2020 (Europe/Athens)'
194 it('should get a custom weekly recurring event happening every 2 weeks on all days, until 20th February 2020 on a different timezone', () => {
195 const rrule = getWeeklyRrule({
197 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
200 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
201 'Every 2 weeks on all days, until Feb 20, 2020 (Europe/Athens)'
205 it('should get a custom weekly recurring event happening every 2 weeks on all days, 2 times on a different timezone', () => {
206 const rrule = getWeeklyRrule({
208 byday: ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'],
211 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
212 'Every 2 weeks on all days, 2 times'
217 describe('getTimezonedFrequencyString should produce the expected string for monthly recurring events', () => {
218 const getMonthlyRrule = (rrule = {}) => getRrule({ ...rrule, freq: FREQUENCY.MONTHLY });
220 it('should get a standard monthly recurring event', () => {
221 expect(getTimezonedFrequencyString(getMonthlyRrule(), dummyStart, options)).toEqual('Monthly on day 20');
224 it('should get a standard monthly recurring event, on a different timezone', () => {
225 expect(getTimezonedFrequencyString(getMonthlyRrule(), dummyStart, otherTzOptions)).toEqual(
226 'Monthly on day 20 (Europe/Athens)'
230 it('should get a custom monthly recurring event happening every 2 months', () => {
231 const rrule = getMonthlyRrule({
234 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 months on day 20');
237 it('should get a custom monthly recurring event happening every 2 months, on the third Monday', () => {
238 const rrule = getMonthlyRrule({
243 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 months on the third Monday');
246 it('should get a custom monthly recurring event, on the first Monday, different timezone', () => {
247 const rrule = getMonthlyRrule({
251 const start = getDateTimeProperty({ year: 2020, month: 1, day: 6 }, dummyTzid);
252 expect(getTimezonedFrequencyString(rrule, start, otherTzOptions)).toEqual(
253 'Monthly on the first Monday (Europe/Athens)'
257 it('should get a custom monthly recurring event happening every 2 months, on the last Wednesday, lasting 3 times', () => {
258 const start = getDateTimeProperty({ year: 2020, month: 1, day: 29 }, dummyTzid);
259 const rrule = getMonthlyRrule({
265 expect(getTimezonedFrequencyString(rrule, start, options)).toEqual(
266 'Every 2 months on the last Wednesday, 3 times'
270 it('should get a custom monthly recurring event happening every 2 months, on the last Wednesday, lasting 1 time', () => {
271 const start = getDateTimeProperty({ year: 2020, month: 1, day: 29 }, dummyTzid);
272 const rrule = getMonthlyRrule({
278 expect(getTimezonedFrequencyString(rrule, start, options)).toEqual(
279 'Every 2 months on the last Wednesday, 1 time'
283 it('should get a custom monthly recurring event happening on a fifth and last Thursday, until 20th February 2020', () => {
284 const start = getDateTimeProperty({ year: 2020, month: 1, day: 30 }, dummyTzid);
285 const rrule = getMonthlyRrule({
290 expect(getTimezonedFrequencyString(rrule, start, options)).toEqual(
291 'Monthly on the last Thursday, until Feb 20, 2020'
295 it('should get a custom monthly recurring event happening every three months on a fifth and last Thursday, until 20th February 2020', () => {
296 const start = getDateTimeProperty({ year: 2020, month: 1, day: 30 }, dummyTzid);
297 const rrule = getMonthlyRrule({
298 freq: FREQUENCY.MONTHLY,
304 expect(getTimezonedFrequencyString(rrule, start, options)).toEqual(
305 'Every 3 months on the last Thursday, until Feb 20, 2020'
309 it('should get a custom monthly recurring event happening on a fifth and last Thursday, until 20th February 2020 on a different timezone', () => {
310 const start = getDateTimeProperty({ year: 2020, month: 1, day: 30 }, dummyTzid);
311 const rrule = getMonthlyRrule({
316 expect(getTimezonedFrequencyString(rrule, start, otherTzOptions)).toEqual(
317 'Monthly on the last Thursday, until Feb 20, 2020 (Europe/Athens)'
322 describe('getTimezonedFrequencyString should produce the expected string for yearly recurring events', () => {
323 const getYearlyRrule = (rrule = {}) => getRrule({ ...rrule, freq: FREQUENCY.YEARLY });
325 it('should get a standard yearly recurring event', () => {
326 expect(getTimezonedFrequencyString(getYearlyRrule(), dummyStart, options)).toEqual('Yearly');
329 it('should get a custom yearly recurring event happening every 2 years, lasting 1 time', () => {
330 const rrule = getYearlyRrule({
334 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 2 years, 1 time');
337 it('should get a custom yearly recurring event happening every three years, lasting 5 times', () => {
338 const rrule = getYearlyRrule({
342 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Every 3 years, 5 times');
345 it('should get a custom yearly recurring event, until 20th February 2020', () => {
346 const rrule = getYearlyRrule({
350 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Yearly, until Feb 20, 2020');
353 it('should get a custom weekly recurring event happening every year, lasting 8 times on a different timezone', () => {
354 const rrule = getYearlyRrule({
357 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual('Yearly, 8 times');
360 it('should get a custom weekly recurring event happening every two years, lasting 2 times on a different timezone', () => {
361 const rrule = getYearlyRrule({
365 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual('Every 2 years, 2 times');
368 it('should get a custom yearly event, until 20th February 2020 on a different timezone', () => {
369 const rrule = getYearlyRrule({
372 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
373 'Yearly, until Feb 20, 2020 (Europe/Athens)'
377 it('should get a custom yearly event happening every ten years until 20th February 2020 on a different timezone', () => {
378 const rrule = getYearlyRrule({
382 expect(getTimezonedFrequencyString(rrule, dummyStart, otherTzOptions)).toEqual(
383 'Every 10 years, until Feb 20, 2020 (Europe/Athens)'
388 describe('getTimezonedFrequencyString should produce the expected string for unsupported recurring rules', () => {
389 const getCustomRrule = (rrule) => getRrule({ ...rrule, x: 'test' });
390 it('should get a non-supported daily recurring event', () => {
391 const rrule = getCustomRrule({
392 freq: FREQUENCY.DAILY,
394 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Custom daily');
397 it('shold get a non-supported weekly recurring event', () => {
398 const rrule = getCustomRrule({
399 freq: FREQUENCY.WEEKLY,
401 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Custom weekly');
404 it('should get a non-supported monthly recurring event', () => {
405 const rrule = getCustomRrule({
406 freq: FREQUENCY.MONTHLY,
408 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Custom monthly');
411 it('should geta non-supported yearly recurring event', () => {
412 const rrule = getCustomRrule({
413 freq: FREQUENCY.YEARLY,
415 expect(getTimezonedFrequencyString(rrule, dummyStart, options)).toEqual('Custom yearly');