@hero-design/rn 7.13.0 → 7.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.eslintrc.json +3 -1
  2. package/.turbo/turbo-build.log +9 -8
  3. package/assets/fonts/hero-icons.ttf +0 -0
  4. package/babel.config.js +16 -0
  5. package/es/index.js +26977 -7611
  6. package/lib/assets/fonts/hero-icons.ttf +0 -0
  7. package/lib/index.js +26983 -7613
  8. package/package.json +9 -4
  9. package/rollup.config.js +1 -0
  10. package/src/components/Accordion/AccordionItem.tsx +50 -0
  11. package/src/components/Accordion/StyledAccordion.tsx +29 -0
  12. package/src/components/Accordion/__tests__/AccordionItem.spec.tsx +56 -0
  13. package/src/components/Accordion/__tests__/StyledAccordion.spec.tsx +17 -0
  14. package/src/components/Accordion/__tests__/__snapshots__/AccordionItem.spec.tsx.snap +529 -0
  15. package/src/components/Accordion/__tests__/__snapshots__/StyledAccordion.spec.tsx.snap +33 -0
  16. package/src/components/Accordion/__tests__/__snapshots__/index.spec.tsx.snap +822 -0
  17. package/src/components/Accordion/__tests__/index.spec.tsx +54 -0
  18. package/src/components/Accordion/index.tsx +82 -0
  19. package/src/components/Accordion/utils.tsx +11 -0
  20. package/src/components/Button/IconButton.tsx +1 -1
  21. package/src/components/Calendar/CalendarRowItem.tsx +54 -0
  22. package/src/components/Calendar/StyledCalendar.tsx +76 -0
  23. package/src/components/Calendar/__tests__/CalendarRowItem.spec.tsx +76 -0
  24. package/src/components/Calendar/__tests__/__snapshots__/CalendarRowItem.spec.tsx.snap +411 -0
  25. package/src/components/Calendar/__tests__/helper.spec.ts +50 -0
  26. package/src/components/Calendar/__tests__/index.spec.tsx +99 -0
  27. package/src/components/Calendar/helpers.ts +29 -0
  28. package/src/components/Calendar/index.tsx +217 -0
  29. package/src/components/Collapse/index.tsx +13 -15
  30. package/src/components/ContentNavigator/index.tsx +6 -0
  31. package/src/components/Empty/StyledEmpty.tsx +47 -0
  32. package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +66 -0
  33. package/src/components/Empty/__tests__/index.spec.tsx +17 -0
  34. package/src/components/Empty/index.tsx +53 -0
  35. package/src/components/FAB/ActionGroup/ActionItem.tsx +6 -2
  36. package/src/components/FAB/ActionGroup/StyledActionGroup.tsx +1 -0
  37. package/src/components/FAB/ActionGroup/StyledActionItem.tsx +7 -1
  38. package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +84 -22
  39. package/src/components/FAB/ActionGroup/index.tsx +8 -1
  40. package/src/components/Icon/HeroIcon/selection.json +1 -1
  41. package/src/components/Icon/IconList.ts +14 -0
  42. package/src/components/List/BasicListItem.tsx +44 -34
  43. package/src/components/List/ListItem.tsx +67 -58
  44. package/src/components/List/StyledBasicListItem.tsx +2 -3
  45. package/src/components/List/StyledListItem.tsx +2 -2
  46. package/src/components/List/__tests__/StyledBasicListItem.spec.tsx +5 -2
  47. package/src/components/List/__tests__/StyledListItem.spec.tsx +4 -1
  48. package/src/components/List/__tests__/__snapshots__/BasicListItem.spec.tsx.snap +15 -10
  49. package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +52 -32
  50. package/src/components/List/__tests__/__snapshots__/StyledBasicListItem.spec.tsx.snap +128 -48
  51. package/src/components/List/__tests__/__snapshots__/StyledListItem.spec.tsx.snap +132 -52
  52. package/src/components/RichTextEditor/EditorEvent.ts +7 -0
  53. package/src/components/RichTextEditor/EditorToolbar.tsx +220 -0
  54. package/src/components/RichTextEditor/MentionList.tsx +69 -0
  55. package/src/components/RichTextEditor/RichTextEditor.tsx +396 -0
  56. package/src/components/RichTextEditor/StyledRichTextEditor.ts +20 -0
  57. package/src/components/RichTextEditor/StyledToolbar.ts +32 -0
  58. package/src/components/RichTextEditor/__tests__/EditorToolbar.spec.tsx +130 -0
  59. package/src/components/RichTextEditor/__tests__/MentionList.spec.tsx +109 -0
  60. package/src/components/RichTextEditor/__tests__/RichTextEditor.spec.tsx +245 -0
  61. package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +324 -0
  62. package/src/components/RichTextEditor/__tests__/__snapshots__/MentionList.spec.tsx.snap +45 -0
  63. package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +526 -0
  64. package/src/components/RichTextEditor/constants.ts +20 -0
  65. package/src/components/RichTextEditor/hero-editor.d.ts +8 -0
  66. package/src/components/RichTextEditor/index.tsx +8 -0
  67. package/src/components/RichTextEditor/utils/events.ts +31 -0
  68. package/src/components/RichTextEditor/utils/rnWebView.ts +19 -0
  69. package/src/components/SectionHeading/__tests__/__snapshots__/index.spec.tsx.snap +77 -0
  70. package/src/components/SectionHeading/__tests__/index.spec.tsx +14 -0
  71. package/src/components/SectionHeading/index.tsx +16 -9
  72. package/src/components/Tag/StyledTag.tsx +12 -2
  73. package/src/components/Tag/__tests__/Tag.spec.tsx +35 -8
  74. package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +118 -4
  75. package/src/components/Tag/index.tsx +9 -2
  76. package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +1 -0
  77. package/src/components/Typography/Text/StyledText.tsx +2 -1
  78. package/src/components/Typography/Text/__tests__/StyledText.spec.tsx +1 -0
  79. package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +22 -0
  80. package/src/components/Typography/Text/index.tsx +2 -1
  81. package/src/index.ts +8 -0
  82. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +101 -4
  83. package/src/theme/components/accordion.ts +19 -0
  84. package/src/theme/components/calendar.ts +34 -0
  85. package/src/theme/components/card.ts +1 -1
  86. package/src/theme/components/empty.ts +38 -0
  87. package/src/theme/components/fab.ts +4 -3
  88. package/src/theme/components/list.ts +1 -0
  89. package/src/theme/components/pinInput.ts +1 -1
  90. package/src/theme/components/richTextEditor.ts +34 -0
  91. package/src/theme/components/tag.ts +8 -2
  92. package/src/theme/components/typography.ts +1 -0
  93. package/src/theme/global/borders.ts +6 -6
  94. package/src/theme/global/colors.ts +4 -1
  95. package/src/theme/index.ts +12 -0
  96. package/testUtils/setup.tsx +17 -0
  97. package/types/components/Accordion/AccordionItem.d.ts +14 -0
  98. package/types/components/Accordion/StyledAccordion.d.ts +32 -0
  99. package/types/components/Accordion/__tests__/AccordionItem.spec.d.ts +1 -0
  100. package/types/components/Accordion/__tests__/StyledAccordion.spec.d.ts +1 -0
  101. package/types/components/Accordion/__tests__/index.spec.d.ts +1 -0
  102. package/types/components/Accordion/index.d.ts +38 -0
  103. package/types/components/Accordion/utils.d.ts +1 -0
  104. package/types/components/Button/IconButton.d.ts +1 -1
  105. package/types/components/Calendar/CalendarRowItem.d.ts +10 -0
  106. package/types/components/Calendar/StyledCalendar.d.ts +54 -0
  107. package/types/components/Calendar/__tests__/CalendarRowItem.spec.d.ts +1 -0
  108. package/types/components/Calendar/__tests__/helper.spec.d.ts +1 -0
  109. package/types/components/Calendar/__tests__/index.spec.d.ts +1 -0
  110. package/types/components/Calendar/helpers.d.ts +3 -0
  111. package/types/components/Calendar/index.d.ts +40 -0
  112. package/types/components/Collapse/index.d.ts +1 -1
  113. package/types/components/ContentNavigator/index.d.ts +5 -1
  114. package/types/components/Empty/StyledEmpty.d.ts +31 -0
  115. package/types/components/Empty/__tests__/index.spec.d.ts +1 -0
  116. package/types/components/Empty/index.d.ts +26 -0
  117. package/types/components/FAB/ActionGroup/StyledActionItem.d.ts +6 -1
  118. package/types/components/FAB/ActionGroup/index.d.ts +6 -1
  119. package/types/components/FAB/index.d.ts +1 -1
  120. package/types/components/Icon/IconList.d.ts +1 -1
  121. package/types/components/Icon/utils.d.ts +1 -1
  122. package/types/components/List/StyledBasicListItem.d.ts +3 -3
  123. package/types/components/List/StyledListItem.d.ts +3 -3
  124. package/types/components/RichTextEditor/EditorEvent.d.ts +3 -0
  125. package/types/components/RichTextEditor/EditorToolbar.d.ts +17 -0
  126. package/types/components/RichTextEditor/MentionList.d.ts +12 -0
  127. package/types/components/RichTextEditor/RichTextEditor.d.ts +65 -0
  128. package/types/components/RichTextEditor/StyledRichTextEditor.d.ts +16 -0
  129. package/types/components/RichTextEditor/StyledToolbar.d.ts +21 -0
  130. package/types/components/RichTextEditor/__tests__/EditorToolbar.spec.d.ts +1 -0
  131. package/types/components/RichTextEditor/__tests__/MentionList.spec.d.ts +1 -0
  132. package/types/components/RichTextEditor/__tests__/RichTextEditor.spec.d.ts +1 -0
  133. package/types/components/RichTextEditor/constants.d.ts +19 -0
  134. package/types/components/RichTextEditor/index.d.ts +5 -0
  135. package/types/components/RichTextEditor/utils/events.d.ts +8 -0
  136. package/types/components/RichTextEditor/utils/rnWebView.d.ts +7 -0
  137. package/types/components/SectionHeading/index.d.ts +2 -2
  138. package/types/components/Select/MultiSelect/OptionList.d.ts +1 -1
  139. package/types/components/Select/SingleSelect/OptionList.d.ts +1 -1
  140. package/types/components/Tag/StyledTag.d.ts +1 -1
  141. package/types/components/Tag/index.d.ts +1 -1
  142. package/types/components/Typography/Text/StyledText.d.ts +1 -1
  143. package/types/components/Typography/Text/index.d.ts +1 -1
  144. package/types/index.d.ts +5 -1
  145. package/types/theme/components/accordion.d.ts +13 -0
  146. package/types/theme/components/calendar.d.ts +26 -0
  147. package/types/theme/components/empty.d.ts +28 -0
  148. package/types/theme/components/fab.d.ts +1 -0
  149. package/types/theme/components/list.d.ts +1 -0
  150. package/types/theme/components/richTextEditor.d.ts +26 -0
  151. package/types/theme/components/tag.d.ts +8 -2
  152. package/types/theme/components/typography.d.ts +1 -0
  153. package/types/theme/global/colors.d.ts +4 -1
  154. package/types/theme/global/index.d.ts +4 -1
  155. package/types/theme/index.d.ts +8 -0
@@ -0,0 +1,411 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`CalendarRowItem renders correctly 1`] = `
4
+ <View
5
+ style={
6
+ Array [
7
+ Object {
8
+ "alignItems": "center",
9
+ "flexBasis": "14%",
10
+ "height": 48,
11
+ "justifyContent": "center",
12
+ "width": 48,
13
+ },
14
+ undefined,
15
+ ]
16
+ }
17
+ testID="calendar-date-cell"
18
+ >
19
+ <View
20
+ accessible={true}
21
+ collapsable={false}
22
+ focusable={true}
23
+ nativeID="animatedComponent"
24
+ onClick={[Function]}
25
+ onResponderGrant={[Function]}
26
+ onResponderMove={[Function]}
27
+ onResponderRelease={[Function]}
28
+ onResponderTerminate={[Function]}
29
+ onResponderTerminationRequest={[Function]}
30
+ onStartShouldSetResponder={[Function]}
31
+ style={
32
+ Object {
33
+ "alignItems": "center",
34
+ "backgroundColor": undefined,
35
+ "borderColor": "#292a2b",
36
+ "borderRadius": 999,
37
+ "borderWidth": 0,
38
+ "height": 44,
39
+ "justifyContent": "center",
40
+ "opacity": 1,
41
+ "width": 44,
42
+ }
43
+ }
44
+ >
45
+ <Text
46
+ style={
47
+ Array [
48
+ Object {
49
+ "color": "#292a2b",
50
+ "fontFamily": "BeVietnamPro-Regular",
51
+ "fontSize": 14,
52
+ "letterSpacing": 0.42,
53
+ "lineHeight": 22,
54
+ },
55
+ undefined,
56
+ ]
57
+ }
58
+ themeFontSize="medium"
59
+ themeFontWeight="regular"
60
+ themeIntent="body"
61
+ >
62
+ 10
63
+ </Text>
64
+ <View
65
+ style={
66
+ Array [
67
+ Object {
68
+ "backgroundColor": "#7622d7",
69
+ "borderRadius": 999,
70
+ "bottom": "10%",
71
+ "height": 4,
72
+ "position": "absolute",
73
+ "width": 4,
74
+ },
75
+ undefined,
76
+ ]
77
+ }
78
+ testID="calendar-date-mark"
79
+ variant="primary"
80
+ />
81
+ </View>
82
+ </View>
83
+ `;
84
+
85
+ exports[`CalendarRowItem renders correctly 2`] = `
86
+ <View
87
+ style={
88
+ Array [
89
+ Object {
90
+ "alignItems": "center",
91
+ "flexBasis": "14%",
92
+ "height": 48,
93
+ "justifyContent": "center",
94
+ "width": 48,
95
+ },
96
+ undefined,
97
+ ]
98
+ }
99
+ testID="calendar-date-cell"
100
+ >
101
+ <View
102
+ accessible={true}
103
+ collapsable={false}
104
+ focusable={true}
105
+ nativeID="animatedComponent"
106
+ onClick={[Function]}
107
+ onResponderGrant={[Function]}
108
+ onResponderMove={[Function]}
109
+ onResponderRelease={[Function]}
110
+ onResponderTerminate={[Function]}
111
+ onResponderTerminationRequest={[Function]}
112
+ onStartShouldSetResponder={[Function]}
113
+ style={
114
+ Object {
115
+ "alignItems": "center",
116
+ "backgroundColor": undefined,
117
+ "borderColor": "#292a2b",
118
+ "borderRadius": 999,
119
+ "borderWidth": 0,
120
+ "height": 44,
121
+ "justifyContent": "center",
122
+ "opacity": 1,
123
+ "width": 44,
124
+ }
125
+ }
126
+ >
127
+ <Text
128
+ style={
129
+ Array [
130
+ Object {
131
+ "color": "#8b8d92",
132
+ "fontFamily": "BeVietnamPro-Regular",
133
+ "fontSize": 14,
134
+ "letterSpacing": 0.42,
135
+ "lineHeight": 22,
136
+ },
137
+ undefined,
138
+ ]
139
+ }
140
+ themeFontSize="medium"
141
+ themeFontWeight="regular"
142
+ themeIntent="subdued"
143
+ >
144
+ 10
145
+ </Text>
146
+ <View
147
+ style={
148
+ Array [
149
+ Object {
150
+ "backgroundColor": "#7622d7",
151
+ "borderRadius": 999,
152
+ "bottom": "10%",
153
+ "height": 4,
154
+ "position": "absolute",
155
+ "width": 4,
156
+ },
157
+ undefined,
158
+ ]
159
+ }
160
+ testID="calendar-date-mark"
161
+ variant="primary"
162
+ />
163
+ </View>
164
+ </View>
165
+ `;
166
+
167
+ exports[`CalendarRowItem renders correctly when is current date 1`] = `
168
+ <View
169
+ style={
170
+ Array [
171
+ Object {
172
+ "alignItems": "center",
173
+ "flexBasis": "14%",
174
+ "height": 48,
175
+ "justifyContent": "center",
176
+ "width": 48,
177
+ },
178
+ undefined,
179
+ ]
180
+ }
181
+ testID="calendar-date-cell"
182
+ >
183
+ <View
184
+ accessible={true}
185
+ collapsable={false}
186
+ focusable={true}
187
+ nativeID="animatedComponent"
188
+ onClick={[Function]}
189
+ onResponderGrant={[Function]}
190
+ onResponderMove={[Function]}
191
+ onResponderRelease={[Function]}
192
+ onResponderTerminate={[Function]}
193
+ onResponderTerminationRequest={[Function]}
194
+ onStartShouldSetResponder={[Function]}
195
+ style={
196
+ Object {
197
+ "alignItems": "center",
198
+ "backgroundColor": "#7622d7",
199
+ "borderColor": "#292a2b",
200
+ "borderRadius": 999,
201
+ "borderWidth": 0,
202
+ "height": 44,
203
+ "justifyContent": "center",
204
+ "opacity": 1,
205
+ "width": 44,
206
+ }
207
+ }
208
+ >
209
+ <Text
210
+ style={
211
+ Array [
212
+ Object {
213
+ "color": "#ffffff",
214
+ "fontFamily": "BeVietnamPro-Regular",
215
+ "fontSize": 14,
216
+ "letterSpacing": 0.42,
217
+ "lineHeight": 22,
218
+ },
219
+ undefined,
220
+ ]
221
+ }
222
+ themeFontSize="medium"
223
+ themeFontWeight="regular"
224
+ themeIntent="inverted"
225
+ >
226
+ 10
227
+ </Text>
228
+ <View
229
+ style={
230
+ Array [
231
+ Object {
232
+ "backgroundColor": "#ffffff",
233
+ "borderRadius": 999,
234
+ "bottom": "10%",
235
+ "height": 4,
236
+ "position": "absolute",
237
+ "width": 4,
238
+ },
239
+ undefined,
240
+ ]
241
+ }
242
+ testID="calendar-date-mark"
243
+ variant="inverted"
244
+ />
245
+ </View>
246
+ </View>
247
+ `;
248
+
249
+ exports[`CalendarRowItem renders correctly when selected, and is current date equal to $current 1`] = `
250
+ <View
251
+ style={
252
+ Array [
253
+ Object {
254
+ "alignItems": "center",
255
+ "flexBasis": "14%",
256
+ "height": 48,
257
+ "justifyContent": "center",
258
+ "width": 48,
259
+ },
260
+ undefined,
261
+ ]
262
+ }
263
+ testID="calendar-date-cell"
264
+ >
265
+ <View
266
+ accessible={true}
267
+ collapsable={false}
268
+ focusable={true}
269
+ nativeID="animatedComponent"
270
+ onClick={[Function]}
271
+ onResponderGrant={[Function]}
272
+ onResponderMove={[Function]}
273
+ onResponderRelease={[Function]}
274
+ onResponderTerminate={[Function]}
275
+ onResponderTerminationRequest={[Function]}
276
+ onStartShouldSetResponder={[Function]}
277
+ style={
278
+ Object {
279
+ "alignItems": "center",
280
+ "backgroundColor": "#7622d7",
281
+ "borderColor": "#292a2b",
282
+ "borderRadius": 999,
283
+ "borderWidth": 0,
284
+ "height": 44,
285
+ "justifyContent": "center",
286
+ "opacity": 1,
287
+ "width": 44,
288
+ }
289
+ }
290
+ >
291
+ <Text
292
+ style={
293
+ Array [
294
+ Object {
295
+ "color": "#ffffff",
296
+ "fontFamily": "BeVietnamPro-Regular",
297
+ "fontSize": 14,
298
+ "letterSpacing": 0.42,
299
+ "lineHeight": 22,
300
+ },
301
+ undefined,
302
+ ]
303
+ }
304
+ themeFontSize="medium"
305
+ themeFontWeight="regular"
306
+ themeIntent="inverted"
307
+ >
308
+ 10
309
+ </Text>
310
+ <View
311
+ style={
312
+ Array [
313
+ Object {
314
+ "backgroundColor": "#ffffff",
315
+ "borderRadius": 999,
316
+ "bottom": "10%",
317
+ "height": 4,
318
+ "position": "absolute",
319
+ "width": 4,
320
+ },
321
+ undefined,
322
+ ]
323
+ }
324
+ testID="calendar-date-mark"
325
+ variant="inverted"
326
+ />
327
+ </View>
328
+ </View>
329
+ `;
330
+
331
+ exports[`CalendarRowItem renders correctly when selected, and is current date equal to $current 2`] = `
332
+ <View
333
+ style={
334
+ Array [
335
+ Object {
336
+ "alignItems": "center",
337
+ "flexBasis": "14%",
338
+ "height": 48,
339
+ "justifyContent": "center",
340
+ "width": 48,
341
+ },
342
+ undefined,
343
+ ]
344
+ }
345
+ testID="calendar-date-cell"
346
+ >
347
+ <View
348
+ accessible={true}
349
+ collapsable={false}
350
+ focusable={true}
351
+ nativeID="animatedComponent"
352
+ onClick={[Function]}
353
+ onResponderGrant={[Function]}
354
+ onResponderMove={[Function]}
355
+ onResponderRelease={[Function]}
356
+ onResponderTerminate={[Function]}
357
+ onResponderTerminationRequest={[Function]}
358
+ onStartShouldSetResponder={[Function]}
359
+ style={
360
+ Object {
361
+ "alignItems": "center",
362
+ "backgroundColor": "#7622d7",
363
+ "borderColor": "#292a2b",
364
+ "borderRadius": 999,
365
+ "borderWidth": 0,
366
+ "height": 44,
367
+ "justifyContent": "center",
368
+ "opacity": 1,
369
+ "width": 44,
370
+ }
371
+ }
372
+ >
373
+ <Text
374
+ style={
375
+ Array [
376
+ Object {
377
+ "color": "#ffffff",
378
+ "fontFamily": "BeVietnamPro-Regular",
379
+ "fontSize": 14,
380
+ "letterSpacing": 0.42,
381
+ "lineHeight": 22,
382
+ },
383
+ undefined,
384
+ ]
385
+ }
386
+ themeFontSize="medium"
387
+ themeFontWeight="regular"
388
+ themeIntent="inverted"
389
+ >
390
+ 10
391
+ </Text>
392
+ <View
393
+ style={
394
+ Array [
395
+ Object {
396
+ "backgroundColor": "#ffffff",
397
+ "borderRadius": 999,
398
+ "bottom": "10%",
399
+ "height": 4,
400
+ "position": "absolute",
401
+ "width": 4,
402
+ },
403
+ undefined,
404
+ ]
405
+ }
406
+ testID="calendar-date-mark"
407
+ variant="inverted"
408
+ />
409
+ </View>
410
+ </View>
411
+ `;
@@ -0,0 +1,50 @@
1
+ import { getValidDate, initArray, isEqDate } from '../helpers';
2
+
3
+ describe('initArray', () => {
4
+ it('returns correct value', () => {
5
+ const transform = (index: number) => `test ${index + 1}`;
6
+ const actual = initArray(5, transform);
7
+ const expected = ['test 1', 'test 2', 'test 3', 'test 4', 'test 5'];
8
+
9
+ expect(actual).toEqual(expected);
10
+ });
11
+ });
12
+
13
+ describe('isEqDate', () => {
14
+ it.each`
15
+ dateA | dateB | expected
16
+ ${undefined} | ${undefined} | ${true}
17
+ ${new Date(2022, 10, 10)} | ${undefined} | ${false}
18
+ ${undefined} | ${new Date(2022, 10, 10)} | ${false}
19
+ ${new Date(2022, 10, 11)} | ${new Date(2022, 10, 10)} | ${false}
20
+ ${new Date(2022, 10, 10)} | ${new Date(2022, 10, 10)} | ${true}
21
+ ${new Date(2022, 10, 10, 5, 12, 3)} | ${new Date(2022, 10, 10, 6, 12, 4)} | ${true}
22
+ `(
23
+ 'returns correct when dateA is $dateA and dateB is $dateB',
24
+ ({ dateA, dateB, expected }) => {
25
+ const actual = isEqDate(dateA, dateB);
26
+ expect(actual).toEqual(expected);
27
+ }
28
+ );
29
+ });
30
+
31
+ describe('getValidDate', () => {
32
+ const date = new Date(2022, 10, 10);
33
+ it.each`
34
+ minDate | maxDate | expected
35
+ ${undefined} | ${undefined} | ${date}
36
+ ${new Date(2022, 10, 8)} | ${undefined} | ${date}
37
+ ${new Date(2022, 10, 15)} | ${undefined} | ${undefined}
38
+ ${undefined} | ${new Date(2022, 10, 11)} | ${date}
39
+ ${undefined} | ${new Date(2022, 10, 8)} | ${undefined}
40
+ ${new Date(2022, 10, 8)} | ${new Date(2022, 10, 11)} | ${date}
41
+ ${new Date(2022, 10, 12)} | ${new Date(2022, 10, 11)} | ${undefined}
42
+ ${new Date(2022, 10, 8)} | ${new Date(2022, 10, 9)} | ${undefined}
43
+ `(
44
+ 'returns correct value when minDate is $minDate and maxDate is $maxDate',
45
+ ({ minDate, maxDate, expected }) => {
46
+ const actual = getValidDate(date, minDate, maxDate);
47
+ expect(actual).toBe(expected);
48
+ }
49
+ );
50
+ });
@@ -0,0 +1,99 @@
1
+ import { fireEvent } from '@testing-library/react-native';
2
+ import React from 'react';
3
+ import Calendar from '..';
4
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
5
+
6
+ Date.now = jest.fn(() => new Date(2022, 10, 2).valueOf());
7
+
8
+ describe('Calendar', () => {
9
+ it('renders correctly', () => {
10
+ const onChange = jest.fn();
11
+ const onTitlePress = jest.fn();
12
+ const onPreviousPress = jest.fn();
13
+ const onNextPress = jest.fn();
14
+ const { getByText, queryAllByTestId, queryByTestId } = renderWithTheme(
15
+ <Calendar
16
+ value={new Date(2022, 10, 5)}
17
+ visibleDate={new Date(2022, 10, 5)}
18
+ onChange={onChange}
19
+ onTitlePress={onTitlePress}
20
+ onPreviousPress={onPreviousPress}
21
+ onNextPress={onNextPress}
22
+ markedDates={[
23
+ new Date(2022, 10, 5),
24
+ new Date(2022, 10, 6),
25
+ new Date(2022, 10, 7),
26
+ new Date(2022, 10, 8),
27
+ new Date(2022, 10, 9),
28
+ ]}
29
+ />
30
+ );
31
+
32
+ expect(getByText('November 2022')).toBeTruthy();
33
+ expect(getByText('Mo')).toBeTruthy();
34
+ expect(getByText('Tu')).toBeTruthy();
35
+ expect(getByText('We')).toBeTruthy();
36
+ expect(getByText('Th')).toBeTruthy();
37
+ expect(getByText('Fr')).toBeTruthy();
38
+ expect(getByText('Sa')).toBeTruthy();
39
+ expect(getByText('Su')).toBeTruthy();
40
+
41
+ expect(queryAllByTestId('calendar-date-cell')).toHaveLength(42);
42
+ expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(0);
43
+ expect(queryAllByTestId('calendar-date-mark')).toHaveLength(5);
44
+
45
+ fireEvent.press(getByText('28'));
46
+ expect(onChange).toBeCalledWith(new Date(2022, 10, 28));
47
+
48
+ fireEvent.press(queryByTestId('previous-icon-button'));
49
+ expect(onPreviousPress).toBeCalled();
50
+
51
+ fireEvent.press(queryByTestId('next-icon-button'));
52
+ expect(onNextPress).toBeCalled();
53
+
54
+ fireEvent.press(getByText('November 2022'));
55
+ expect(onTitlePress).toBeCalled();
56
+ });
57
+
58
+ it('renders correctly with minDate and maxDate', () => {
59
+ const onChange = jest.fn();
60
+ const onTitlePress = jest.fn();
61
+ const onPreviousPress = jest.fn();
62
+ const onNextPress = jest.fn();
63
+ const {
64
+ getByText,
65
+ queryByText,
66
+ queryAllByTestId,
67
+ queryByTestId,
68
+ } = renderWithTheme(
69
+ <Calendar
70
+ value={new Date(2022, 10, 5)}
71
+ visibleDate={new Date(2022, 10, 5)}
72
+ onChange={onChange}
73
+ onTitlePress={onTitlePress}
74
+ onPreviousPress={onPreviousPress}
75
+ onNextPress={onNextPress}
76
+ minDate={new Date(2022, 10, 3)}
77
+ maxDate={new Date(2022, 10, 27)}
78
+ />
79
+ );
80
+
81
+ expect(queryAllByTestId('calendar-date-cell')).toHaveLength(25);
82
+ expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(17);
83
+
84
+ expect(queryByText('2')).toBeNull();
85
+ expect(queryByText('28')).toBeNull();
86
+
87
+ fireEvent.press(queryByTestId('previous-icon-button'));
88
+ expect(onPreviousPress).not.toBeCalled();
89
+
90
+ fireEvent.press(queryByTestId('next-icon-button'));
91
+ expect(onNextPress).not.toBeCalled();
92
+
93
+ fireEvent.press(queryAllByTestId('calendar-disabled-cell')[0]);
94
+ expect(onChange).not.toBeCalled();
95
+
96
+ fireEvent.press(getByText('26'));
97
+ expect(onChange).toBeCalledWith(new Date(2022, 10, 26));
98
+ });
99
+ });
@@ -0,0 +1,29 @@
1
+ export const initArray = <T>(length: number, func: (value: number) => T): T[] =>
2
+ Array.from(Array(length)).map((_, index) => func(index));
3
+
4
+ export const isEqDate = (dateA?: Date, dateB?: Date) =>
5
+ dateA?.toDateString() === dateB?.toDateString();
6
+
7
+ export const getValidDate = (
8
+ date: Date,
9
+ minDate?: Date,
10
+ maxDate?: Date
11
+ ): Date | undefined => {
12
+ if (minDate === undefined && maxDate === undefined) {
13
+ return date;
14
+ }
15
+
16
+ if (minDate !== undefined && maxDate === undefined) {
17
+ return date >= minDate ? date : undefined;
18
+ }
19
+
20
+ if (minDate === undefined && maxDate !== undefined) {
21
+ return date <= maxDate ? date : undefined;
22
+ }
23
+
24
+ if (minDate !== undefined && maxDate !== undefined) {
25
+ return date >= minDate && date <= maxDate ? date : undefined;
26
+ }
27
+
28
+ return undefined;
29
+ };