Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / test / calendar / rrule / rruleEqual.spec.js
blobad0cebeebeee0e149992729b5f21c3376d44526a
1 import { FREQUENCY } from '../../../lib/calendar/constants';
2 import { getIsRruleEqual } from '../../../lib/calendar/recurrence/rruleEqual';
4 const getTest = (a, b, c, result) => ({
5     a,
6     b,
7     c,
8     result,
9 });
11 describe('rrule equal', () => {
12     [
13         getTest({ freq: FREQUENCY.ONCE }, undefined, false, false),
14         getTest({ freq: FREQUENCY.ONCE }, { freq: FREQUENCY.ONCE }, false, true),
15         getTest({ freq: FREQUENCY.ONCE }, { freq: FREQUENCY.WEEKLY }, false, false),
16         getTest(
17             {
18                 freq: FREQUENCY.MONTHLY,
19                 byday: ['TU', 'MO'],
20             },
21             {
22                 freq: FREQUENCY.MONTHLY,
23                 byday: ['MO', 'TU'],
24             },
25             false,
26             true
27         ),
28         getTest(
29             {
30                 freq: FREQUENCY.MONTHLY,
31                 byday: ['MO'],
32             },
33             {
34                 freq: FREQUENCY.MONTHLY,
35                 byday: 'MO',
36             },
37             false,
38             false
39         ),
40         getTest(
41             {
42                 freq: FREQUENCY.MONTHLY,
43                 byday: ['TU', 'MO'],
44             },
45             {
46                 freq: FREQUENCY.WEEKLY,
47             },
48             false,
49             false
50         ),
51         getTest({ count: 2 }, { count: 2 }, false, true),
52         getTest({ count: 2 }, { count: 3 }, false, false),
53         getTest(
54             {
55                 freq: FREQUENCY.WEEKLY,
56                 count: 65,
57             },
58             {
59                 freq: FREQUENCY.WEEKLY,
60                 count: 65,
61                 byday: 'WE',
62             },
63             false,
64             true
65         ),
66         getTest(
67             {
68                 freq: FREQUENCY.WEEKLY,
69                 until: {
70                     year: 2020,
71                     month: 1,
72                     day: 1,
73                 },
74             },
75             {
76                 freq: FREQUENCY.WEEKLY,
77                 until: {
78                     year: 2020,
79                     month: 1,
80                     day: 2,
81                 },
82             },
83             false,
84             false
85         ),
86         getTest(
87             {
88                 freq: FREQUENCY.WEEKLY,
89                 until: {
90                     year: 2020,
91                     month: 1,
92                     day: 1,
93                 },
94             },
95             {
96                 freq: FREQUENCY.WEEKLY,
97                 until: {
98                     year: 2020,
99                     month: 1,
100                     day: 1,
101                 },
102             },
103             false,
104             true
105         ),
106         getTest(
107             {
108                 until: {
109                     year: 2020,
110                     month: 1,
111                     day: 1,
112                 },
113             },
114             {
115                 until: {
116                     year: 2020,
117                     month: 1,
118                     day: 1,
119                     hours: 12,
120                     minutes: 59,
121                     seconds: 59,
122                 },
123             },
124             false,
125             true
126         ),
127         getTest(
128             {},
129             {
130                 until: {
131                     year: 2020,
132                     month: 1,
133                     day: 1,
134                     hours: 12,
135                     minutes: 59,
136                     seconds: 59,
137                 },
138             },
139             false,
140             false
141         ),
142         getTest(
143             {
144                 until: {
145                     year: 2020,
146                     month: 1,
147                     day: 1,
148                     hours: 12,
149                     minutes: 59,
150                     seconds: 59,
151                 },
152             },
153             {},
154             false,
155             false
156         ),
157         getTest(
158             {
159                 until: {
160                     year: 2020,
161                     month: 1,
162                     day: 1,
163                     hours: 12,
164                     minutes: 59,
165                     seconds: 59,
166                 },
167             },
168             {
169                 until: {
170                     year: 2020,
171                     month: 1,
172                     day: 2,
173                     hours: 12,
174                     minutes: 59,
175                     seconds: 59,
176                 },
177             },
178             false,
179             false
180         ),
181         getTest(
182             { freq: FREQUENCY.WEEKLY, byday: [1, 2, 3], interval: 2, wkst: 'SU' },
183             { freq: FREQUENCY.WEEKLY, byday: [1, 2, 3], interval: 2 },
184             false,
185             false
186         ),
187         getTest(
188             { freq: FREQUENCY.WEEKLY, byday: [1, 2, 3], interval: 2, wkst: 'SU' },
189             { freq: FREQUENCY.WEEKLY, byday: [1, 2, 3], interval: 2 },
190             true,
191             true
192         ),
193         getTest({ bymonth: [1, 3, 2] }, { bymonth: [3, 2, 1] }, false, true),
194         getTest({}, { bymonth: [1, 3, 2] }, false, false),
195         getTest({ freq: FREQUENCY.WEEKLY, byday: [1] }, { freq: FREQUENCY.WEEKLY }, false, true),
196         getTest({ freq: FREQUENCY.WEEKLY, byday: [1], bymonth: [8] }, { freq: FREQUENCY.WEEKLY }, false, false),
197         getTest({ freq: FREQUENCY.MONTHLY, bymonthday: [13] }, { freq: FREQUENCY.MONTHLY }, false, true),
198         getTest({ freq: FREQUENCY.MONTHLY, bymonthday: [13], byday: [2] }, { freq: FREQUENCY.MONTHLY }, false, false),
199         getTest({ freq: FREQUENCY.YEARLY, byday: [7], bymonth: [7] }, { freq: FREQUENCY.YEARLY }, false, true),
200         getTest({ freq: FREQUENCY.YEARLY, byday: [7] }, { freq: FREQUENCY.YEARLY }, false, false),
201     ].forEach(({ a, b, c, result }, i) => {
202         it(`is rrule equal for ${i}`, () => {
203             expect(getIsRruleEqual({ value: a }, { value: b }, c)).toEqual(result);
204         });
205     });