@ionic/core 7.5.6-dev.11700169088.140f3e6a → 7.5.6-dev.11700492285.1581ed02

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 (68) hide show
  1. package/dist/collection/collection-manifest.json +4 -4
  2. package/dist/collection/components/accordion/test/accordion.spec.js +195 -0
  3. package/dist/collection/components/action-sheet/test/action-sheet-id.spec.js +32 -0
  4. package/dist/collection/components/action-sheet/test/basic/action-sheet.spec.js +18 -0
  5. package/dist/collection/components/alert/test/alert-id.spec.js +32 -0
  6. package/dist/collection/components/alert/test/alert.spec.js +37 -0
  7. package/dist/collection/components/back-button/test/back-button.spec.js +86 -0
  8. package/dist/collection/components/breadcrumb/test/aria.spec.js +22 -0
  9. package/dist/collection/components/breadcrumbs/test/breadcrumbs.spec.js +58 -0
  10. package/dist/collection/components/button/test/form-reference/button.spec.js +26 -0
  11. package/dist/collection/components/card/test/aria.spec.js +16 -0
  12. package/dist/collection/components/checkbox/test/checkbox.spec.js +20 -0
  13. package/dist/collection/components/datetime/test/a11y/datetime.spec.js +43 -0
  14. package/dist/collection/components/datetime/test/comparison.spec.js +43 -0
  15. package/dist/collection/components/datetime/test/data.spec.js +456 -0
  16. package/dist/collection/components/datetime/test/format.spec.js +124 -0
  17. package/dist/collection/components/datetime/test/helpers.spec.js +72 -0
  18. package/dist/collection/components/datetime/test/manipulation.spec.js +433 -0
  19. package/dist/collection/components/datetime/test/parse.spec.js +222 -0
  20. package/dist/collection/components/datetime/test/state.spec.js +114 -0
  21. package/dist/collection/components/infinite-scroll-content/test/infinite-scroll-content.spec.js +37 -0
  22. package/dist/collection/components/input/test/input.spec.js +85 -0
  23. package/dist/collection/components/input/test/item/input.spec.js +24 -0
  24. package/dist/collection/components/item/test/a11y/item.spec.js +48 -0
  25. package/dist/collection/components/loading/test/basic/loading.spec.js +16 -0
  26. package/dist/collection/components/loading/test/loading-id.spec.js +32 -0
  27. package/dist/collection/components/loading/test/loading.spec.js +37 -0
  28. package/dist/collection/components/modal/test/a11y/modal.spec.js +22 -0
  29. package/dist/collection/components/modal/test/basic/modal.spec.js +16 -0
  30. package/dist/collection/components/modal/test/can-dismiss/modal.spec.js +191 -0
  31. package/dist/collection/components/modal/test/modal-id.spec.js +32 -0
  32. package/dist/collection/components/nav/test/nav-controller.spec.js +749 -0
  33. package/dist/collection/components/picker/test/picker-id.spec.js +32 -0
  34. package/dist/collection/components/picker-column/test/picker-column-aria.spec.js +35 -0
  35. package/dist/collection/components/picker-column/test/picker-column-dynamic.spec.js +29 -0
  36. package/dist/collection/components/picker-column/test/picker-column.spec.js +17 -0
  37. package/dist/collection/components/popover/test/basic/popover.spec.js +16 -0
  38. package/dist/collection/components/popover/test/popover-id.spec.js +32 -0
  39. package/dist/collection/components/popover/test/util.spec.js +53 -0
  40. package/dist/collection/components/radio/test/radio.spec.js +46 -0
  41. package/dist/collection/components/range/test/label/range.spec.js +23 -0
  42. package/dist/collection/components/range/test/range.spec.js +205 -0
  43. package/dist/collection/components/refresher-content/test/refresher-content.spec.js +46 -0
  44. package/dist/collection/components/router/test/matching.spec.js +250 -0
  45. package/dist/collection/components/router/test/parser.spec.js +133 -0
  46. package/dist/collection/components/router/test/path.spec.js +218 -0
  47. package/dist/collection/components/router/test/router.spec.js +55 -0
  48. package/dist/collection/components/searchbar/test/searchbar.spec.js +15 -0
  49. package/dist/collection/components/segment/test/segment.spec.js +37 -0
  50. package/dist/collection/components/select/test/select.spec.js +59 -0
  51. package/dist/collection/components/textarea/test/textarea.spec.js +59 -0
  52. package/dist/collection/components/toast/test/toast-id.spec.js +32 -0
  53. package/dist/collection/components/toast/test/toast.spec.js +120 -0
  54. package/dist/collection/components/toggle/test/toggle.spec.js +55 -0
  55. package/dist/collection/global/test/config-controller.spec.js +77 -0
  56. package/dist/collection/utils/animation/test/animation.spec.js +431 -0
  57. package/dist/collection/utils/keyboard/test/keyboard-controller.spec.js +21 -0
  58. package/dist/collection/utils/keyboard/test/keyboard.spec.js +214 -0
  59. package/dist/collection/utils/sanitization/test/sanitization.spec.js +43 -0
  60. package/dist/collection/utils/test/aria.spec.js +79 -0
  61. package/dist/collection/utils/test/attributes.spec.js +53 -0
  62. package/dist/collection/utils/test/hardware-back-button.spec.js +53 -0
  63. package/dist/collection/utils/test/overlays/overlays.spec.js +102 -0
  64. package/dist/collection/utils/test/platform.spec.js +132 -0
  65. package/dist/collection/utils/test/ready.spec.js +39 -0
  66. package/dist/collection/utils/test/theme.spec.js +56 -0
  67. package/dist/docs.json +21 -21
  68. package/package.json +2 -1
@@ -0,0 +1,43 @@
1
+ /*!
2
+ * (C) Ionic http://ionicframework.com - MIT License
3
+ */
4
+ import { isSameDay, isBefore, isAfter } from "../utils/comparison";
5
+ describe('isSameDay()', () => {
6
+ it('should return correct results for month, day, and year', () => {
7
+ const reference = { month: 1, day: 1, year: 2021 };
8
+ expect(isSameDay(reference, { month: 1, day: 1, year: 2021 })).toEqual(true);
9
+ expect(isSameDay(reference, { month: 2, day: 1, year: 2021 })).toEqual(false);
10
+ expect(isSameDay(reference, { month: 1, day: 2, year: 2021 })).toEqual(false);
11
+ expect(isSameDay(reference, { month: 1, day: 1, year: 2022 })).toEqual(false);
12
+ expect(isSameDay(reference, { month: 0, day: 0, year: 0 })).toEqual(false);
13
+ expect(isSameDay(reference, { month: null, day: null, year: null })).toEqual(false);
14
+ });
15
+ });
16
+ describe('isBefore()', () => {
17
+ it('should return correct results for month, day, and year', () => {
18
+ const reference = { month: 1, day: 1, year: 2021 };
19
+ expect(isBefore(reference, { month: 1, day: 1, year: 2021 })).toEqual(false);
20
+ expect(isBefore(reference, { month: 2, day: 1, year: 2021 })).toEqual(true);
21
+ expect(isBefore(reference, { month: 1, day: 2, year: 2021 })).toEqual(true);
22
+ expect(isBefore(reference, { month: 1, day: 1, year: 2022 })).toEqual(true);
23
+ expect(isBefore(reference, { month: 1, day: 1, year: 2020 })).toEqual(false);
24
+ expect(isBefore(reference, { month: 0, day: 0, year: 0 })).toEqual(false);
25
+ expect(isBefore(reference, { month: null, day: null, year: null })).toEqual(false);
26
+ });
27
+ });
28
+ describe('isAfter()', () => {
29
+ it('should return correct results for month, day, and year', () => {
30
+ const reference = { month: 2, day: 2, year: 2021 };
31
+ expect(isAfter(reference, { month: 2, day: 2, year: 2021 })).toEqual(false);
32
+ expect(isAfter(reference, { month: 2, day: 1, year: 2021 })).toEqual(true);
33
+ expect(isAfter(reference, { month: 1, day: 2, year: 2021 })).toEqual(true);
34
+ expect(isAfter(reference, { month: 1, day: 1, year: 2020 })).toEqual(true);
35
+ expect(isAfter(reference, { month: 1, day: 1, year: 2022 })).toEqual(false);
36
+ expect(isAfter(reference, { month: 0, day: 0, year: 0 })).toEqual(true);
37
+ /**
38
+ * 2021 > undefined === false
39
+ * 2021 > null === true
40
+ */
41
+ expect(isAfter(reference, { month: null, day: null, year: null })).toEqual(true);
42
+ });
43
+ });
@@ -0,0 +1,456 @@
1
+ /*!
2
+ * (C) Ionic http://ionicframework.com - MIT License
3
+ */
4
+ import { generateMonths, getDaysOfWeek, generateTime, getToday, getCombinedDateColumnData, getTimeColumnsData, } from "../utils/data";
5
+ // The minutes are the same across all hour cycles, so we don't check those
6
+ describe('getTimeColumnsData()', () => {
7
+ it('should generate formatted h12 hours and AM/PM data data', () => {
8
+ const refParts = { month: 5, year: 2021, day: 1, hour: 4, minute: 30 };
9
+ const results = getTimeColumnsData('en-US', refParts, 'h12');
10
+ expect(results.hoursData).toEqual([
11
+ { text: '12', value: 0 },
12
+ { text: '1', value: 1 },
13
+ { text: '2', value: 2 },
14
+ { text: '3', value: 3 },
15
+ { text: '4', value: 4 },
16
+ { text: '5', value: 5 },
17
+ { text: '6', value: 6 },
18
+ { text: '7', value: 7 },
19
+ { text: '8', value: 8 },
20
+ { text: '9', value: 9 },
21
+ { text: '10', value: 10 },
22
+ { text: '11', value: 11 },
23
+ ]);
24
+ expect(results.dayPeriodData).toEqual([
25
+ { text: 'AM', value: 'am' },
26
+ { text: 'PM', value: 'pm' },
27
+ ]);
28
+ });
29
+ it('should generate formatted h23 hours and AM/PM data data', () => {
30
+ const refParts = { month: 5, year: 2021, day: 1, hour: 4, minute: 30 };
31
+ const results = getTimeColumnsData('en-US', refParts, 'h23');
32
+ expect(results.hoursData).toEqual([
33
+ { text: '00', value: 0 },
34
+ { text: '01', value: 1 },
35
+ { text: '02', value: 2 },
36
+ { text: '03', value: 3 },
37
+ { text: '04', value: 4 },
38
+ { text: '05', value: 5 },
39
+ { text: '06', value: 6 },
40
+ { text: '07', value: 7 },
41
+ { text: '08', value: 8 },
42
+ { text: '09', value: 9 },
43
+ { text: '10', value: 10 },
44
+ { text: '11', value: 11 },
45
+ { text: '12', value: 12 },
46
+ { text: '13', value: 13 },
47
+ { text: '14', value: 14 },
48
+ { text: '15', value: 15 },
49
+ { text: '16', value: 16 },
50
+ { text: '17', value: 17 },
51
+ { text: '18', value: 18 },
52
+ { text: '19', value: 19 },
53
+ { text: '20', value: 20 },
54
+ { text: '21', value: 21 },
55
+ { text: '22', value: 22 },
56
+ { text: '23', value: 23 },
57
+ ]);
58
+ expect(results.dayPeriodData).toEqual([]);
59
+ });
60
+ it('should generate formatted h11 hours and AM/PM data data', () => {
61
+ const refParts = { month: 5, year: 2021, day: 1, hour: 4, minute: 30 };
62
+ const results = getTimeColumnsData('en-US', refParts, 'h11');
63
+ expect(results.hoursData).toEqual([
64
+ { text: '0', value: 0 },
65
+ { text: '1', value: 1 },
66
+ { text: '2', value: 2 },
67
+ { text: '3', value: 3 },
68
+ { text: '4', value: 4 },
69
+ { text: '5', value: 5 },
70
+ { text: '6', value: 6 },
71
+ { text: '7', value: 7 },
72
+ { text: '8', value: 8 },
73
+ { text: '9', value: 9 },
74
+ { text: '10', value: 10 },
75
+ { text: '11', value: 11 },
76
+ ]);
77
+ expect(results.dayPeriodData).toEqual([
78
+ { text: 'AM', value: 'am' },
79
+ { text: 'PM', value: 'pm' },
80
+ ]);
81
+ });
82
+ it('should generate formatted h24 hours and AM/PM data data', () => {
83
+ const refParts = { month: 5, year: 2021, day: 1, hour: 4, minute: 30 };
84
+ const results = getTimeColumnsData('en-US', refParts, 'h24');
85
+ expect(results.hoursData).toEqual([
86
+ { text: '01', value: 1 },
87
+ { text: '02', value: 2 },
88
+ { text: '03', value: 3 },
89
+ { text: '04', value: 4 },
90
+ { text: '05', value: 5 },
91
+ { text: '06', value: 6 },
92
+ { text: '07', value: 7 },
93
+ { text: '08', value: 8 },
94
+ { text: '09', value: 9 },
95
+ { text: '10', value: 10 },
96
+ { text: '11', value: 11 },
97
+ { text: '12', value: 12 },
98
+ { text: '13', value: 13 },
99
+ { text: '14', value: 14 },
100
+ { text: '15', value: 15 },
101
+ { text: '16', value: 16 },
102
+ { text: '17', value: 17 },
103
+ { text: '18', value: 18 },
104
+ { text: '19', value: 19 },
105
+ { text: '20', value: 20 },
106
+ { text: '21', value: 21 },
107
+ { text: '22', value: 22 },
108
+ { text: '23', value: 23 },
109
+ { text: '24', value: 0 },
110
+ ]);
111
+ expect(results.dayPeriodData).toEqual([]);
112
+ });
113
+ });
114
+ describe('generateMonths()', () => {
115
+ it('should generate correct month data', () => {
116
+ expect(generateMonths({ month: 5, year: 2021, day: 1 })).toEqual([
117
+ { month: 4, year: 2021, day: 1 },
118
+ { month: 5, year: 2021, day: 1 },
119
+ { month: 6, year: 2021, day: 1 },
120
+ ]);
121
+ });
122
+ });
123
+ describe('getDaysOfWeek()', () => {
124
+ it('should return English short names given a locale and mode', () => {
125
+ expect(getDaysOfWeek('en-US', 'ios')).toEqual(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);
126
+ });
127
+ it('should return English narrow names given a locale and mode', () => {
128
+ expect(getDaysOfWeek('en-US', 'md')).toEqual(['S', 'M', 'T', 'W', 'T', 'F', 'S']);
129
+ });
130
+ it('should return Spanish short names given a locale and mode', () => {
131
+ expect(getDaysOfWeek('es-ES', 'ios')).toEqual(['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb']);
132
+ });
133
+ it('should return Spanish narrow names given a locale and mode', () => {
134
+ expect(getDaysOfWeek('es-ES', 'md')).toEqual(['D', 'L', 'M', 'X', 'J', 'V', 'S']);
135
+ });
136
+ it('should return English short names given a locale, mode and startOfWeek', () => {
137
+ expect(getDaysOfWeek('en-US', 'ios', 1)).toEqual(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']);
138
+ });
139
+ });
140
+ describe('generateTime()', () => {
141
+ it('should not filter and hours/minutes when no bounds set', () => {
142
+ const today = {
143
+ day: 19,
144
+ month: 5,
145
+ year: 2021,
146
+ hour: 5,
147
+ minute: 43,
148
+ };
149
+ const { hours, minutes } = generateTime('en-US', today);
150
+ expect(hours.length).toEqual(12);
151
+ expect(minutes.length).toEqual(60);
152
+ });
153
+ it('should filter according to min', () => {
154
+ const today = {
155
+ day: 19,
156
+ month: 5,
157
+ year: 2021,
158
+ hour: 5,
159
+ minute: 43,
160
+ };
161
+ const min = {
162
+ day: 19,
163
+ month: 5,
164
+ year: 2021,
165
+ hour: 2,
166
+ minute: 40,
167
+ };
168
+ const { hours, minutes } = generateTime('en-US', today, 'h12', min);
169
+ expect(hours.length).toEqual(10);
170
+ expect(minutes.length).toEqual(60);
171
+ });
172
+ it('should not filter according to min if not on reference day', () => {
173
+ const today = {
174
+ day: 20,
175
+ month: 5,
176
+ year: 2021,
177
+ hour: 5,
178
+ minute: 43,
179
+ };
180
+ const min = {
181
+ day: 19,
182
+ month: 5,
183
+ year: 2021,
184
+ hour: 2,
185
+ minute: 40,
186
+ };
187
+ const { hours, minutes } = generateTime('en-US', today, 'h12', min);
188
+ expect(hours.length).toEqual(12);
189
+ expect(minutes.length).toEqual(60);
190
+ });
191
+ it('should filter according to max', () => {
192
+ const today = {
193
+ day: 19,
194
+ month: 5,
195
+ year: 2021,
196
+ hour: 7,
197
+ minute: 43,
198
+ };
199
+ const max = {
200
+ day: 19,
201
+ month: 5,
202
+ year: 2021,
203
+ hour: 7,
204
+ minute: 44,
205
+ };
206
+ const { hours, minutes } = generateTime('en-US', today, 'h12', undefined, max);
207
+ expect(hours.length).toEqual(8);
208
+ expect(minutes.length).toEqual(45);
209
+ });
210
+ it('should not filter according to min if not on reference day', () => {
211
+ const today = {
212
+ day: 20,
213
+ month: 5,
214
+ year: 2021,
215
+ hour: 5,
216
+ minute: 43,
217
+ };
218
+ const max = {
219
+ day: 21,
220
+ month: 5,
221
+ year: 2021,
222
+ hour: 2,
223
+ minute: 40,
224
+ };
225
+ const { hours, minutes } = generateTime('en-US', today, 'h12', undefined, max);
226
+ expect(hours.length).toEqual(12);
227
+ expect(minutes.length).toEqual(60);
228
+ });
229
+ it('should return no values for a day less than the min', () => {
230
+ const today = {
231
+ day: 20,
232
+ month: 5,
233
+ year: 2021,
234
+ hour: 5,
235
+ minute: 43,
236
+ };
237
+ const min = {
238
+ day: 21,
239
+ month: 5,
240
+ year: 2021,
241
+ hour: 2,
242
+ minute: 40,
243
+ };
244
+ const { hours, minutes } = generateTime('en-US', today, 'h12', min);
245
+ expect(hours.length).toEqual(0);
246
+ expect(minutes.length).toEqual(0);
247
+ });
248
+ it('should return no values for a day greater than the max', () => {
249
+ const today = {
250
+ day: 22,
251
+ month: 5,
252
+ year: 2021,
253
+ hour: 5,
254
+ minute: 43,
255
+ };
256
+ const max = {
257
+ day: 21,
258
+ month: 5,
259
+ year: 2021,
260
+ hour: 2,
261
+ minute: 40,
262
+ };
263
+ const { hours, minutes } = generateTime('en-US', today, 'h12', undefined, max);
264
+ expect(hours.length).toEqual(0);
265
+ expect(minutes.length).toEqual(0);
266
+ });
267
+ it('should allow all hours and minutes if not set in min/max', () => {
268
+ const today = {
269
+ day: 22,
270
+ month: 5,
271
+ year: 2021,
272
+ hour: 5,
273
+ minute: 43,
274
+ };
275
+ const min = {
276
+ day: 22,
277
+ month: 5,
278
+ year: 2021,
279
+ };
280
+ const max = {
281
+ day: 22,
282
+ month: 5,
283
+ year: 2021,
284
+ };
285
+ const { hours, minutes } = generateTime('en-US', today, 'h12', min, max);
286
+ expect(hours.length).toEqual(12);
287
+ expect(minutes.length).toEqual(60);
288
+ });
289
+ it('should allow certain hours and minutes based on minuteValues and hourValues', () => {
290
+ const today = {
291
+ day: 22,
292
+ month: 5,
293
+ year: 2021,
294
+ hour: 5,
295
+ minute: 43,
296
+ };
297
+ const { hours, minutes } = generateTime('en-US', today, 'h12', undefined, undefined, [1, 2, 3], [10, 15, 20]);
298
+ expect(hours).toStrictEqual([1, 2, 3]);
299
+ expect(minutes).toStrictEqual([10, 15, 20]);
300
+ });
301
+ it('should allow both am/pm when min is am and max is pm', () => {
302
+ // https://github.com/ionic-team/ionic-framework/issues/26216
303
+ const today = {
304
+ day: 22,
305
+ month: 5,
306
+ year: 2021,
307
+ hour: 5,
308
+ minute: 43,
309
+ };
310
+ const min = {
311
+ day: 22,
312
+ month: 5,
313
+ year: 2021,
314
+ hour: 11,
315
+ minute: 14,
316
+ };
317
+ const max = {
318
+ day: 22,
319
+ month: 5,
320
+ year: 2021,
321
+ hour: 12,
322
+ minute: 14,
323
+ };
324
+ const { am, pm } = generateTime('en-US', today, 'h12', min, max);
325
+ expect(am).toBe(true);
326
+ expect(pm).toBe(true);
327
+ });
328
+ describe('hourCycle is 23', () => {
329
+ it('should return hours in 24 hour format', () => {
330
+ const refValue = {
331
+ day: undefined,
332
+ month: undefined,
333
+ year: undefined,
334
+ hour: 19,
335
+ minute: 50,
336
+ };
337
+ const minParts = {
338
+ day: undefined,
339
+ month: undefined,
340
+ year: undefined,
341
+ hour: 19,
342
+ minute: 50,
343
+ };
344
+ const { hours } = generateTime('en-US', refValue, 'h23', minParts);
345
+ expect(hours).toStrictEqual([19, 20, 21, 22, 23]);
346
+ });
347
+ describe('current hour is above min hour range', () => {
348
+ it('should return minutes above the min minute range', () => {
349
+ const refValue = {
350
+ day: undefined,
351
+ month: undefined,
352
+ year: undefined,
353
+ hour: 20,
354
+ minute: 22,
355
+ };
356
+ const minParts = {
357
+ day: undefined,
358
+ month: undefined,
359
+ year: undefined,
360
+ hour: 19,
361
+ minute: 30,
362
+ };
363
+ const { hours, minutes } = generateTime('en-US', refValue, 'h23', minParts);
364
+ expect(hours).toStrictEqual([19, 20, 21, 22, 23]);
365
+ expect(minutes.length).toEqual(60);
366
+ });
367
+ });
368
+ it('should respect the min & max bounds', () => {
369
+ const refValue = {
370
+ day: undefined,
371
+ month: undefined,
372
+ year: undefined,
373
+ hour: 20,
374
+ minute: 30,
375
+ };
376
+ const minParts = {
377
+ day: undefined,
378
+ month: undefined,
379
+ year: undefined,
380
+ hour: 19,
381
+ minute: 30,
382
+ };
383
+ const maxParts = {
384
+ day: undefined,
385
+ month: undefined,
386
+ year: undefined,
387
+ hour: 20,
388
+ minute: 40,
389
+ };
390
+ const { hours } = generateTime('en-US', refValue, 'h23', minParts, maxParts);
391
+ expect(hours).toStrictEqual([19, 20]);
392
+ });
393
+ it('should return the filtered minutes when the max bound is set', () => {
394
+ const refValue = {
395
+ day: undefined,
396
+ month: undefined,
397
+ year: undefined,
398
+ hour: 13,
399
+ minute: 0,
400
+ };
401
+ const maxParts = {
402
+ day: undefined,
403
+ month: undefined,
404
+ year: undefined,
405
+ hour: 13,
406
+ minute: 2,
407
+ };
408
+ const { minutes } = generateTime('en-US', refValue, 'h23', undefined, maxParts);
409
+ expect(minutes).toStrictEqual([0, 1, 2]);
410
+ });
411
+ it('should not filter minutes when the current hour is less than the max hour bound', () => {
412
+ const refValue = {
413
+ day: undefined,
414
+ month: undefined,
415
+ year: undefined,
416
+ hour: 12,
417
+ minute: 0,
418
+ };
419
+ const maxParts = {
420
+ day: undefined,
421
+ month: undefined,
422
+ year: undefined,
423
+ hour: 13,
424
+ minute: 2,
425
+ };
426
+ const { minutes } = generateTime('en-US', refValue, 'h23', undefined, maxParts);
427
+ expect(minutes.length).toEqual(60);
428
+ });
429
+ });
430
+ });
431
+ describe('getToday', () => {
432
+ beforeAll(() => {
433
+ jest.useFakeTimers();
434
+ // System time is zero based, 1 = February
435
+ jest.setSystemTime(new Date(2022, 1, 21, 18, 30));
436
+ });
437
+ it('should return today without converting to UTC time', () => {
438
+ const res = getToday();
439
+ expect(res).toEqual('2022-02-21T18:30:00.000Z');
440
+ });
441
+ });
442
+ describe('getCombinedDateColumnData', () => {
443
+ it('should return correct data with dates across years', () => {
444
+ const { parts, items } = getCombinedDateColumnData('en-US', { day: 1, month: 1, year: 2021 }, { day: 31, month: 12, year: 2020 }, { day: 2, month: 1, year: 2021 });
445
+ expect(parts).toEqual([
446
+ { month: 12, year: 2020, day: 31 },
447
+ { month: 1, year: 2021, day: 1 },
448
+ { month: 1, year: 2021, day: 2 },
449
+ ]);
450
+ expect(items).toEqual([
451
+ { text: 'Thu, Dec 31', value: '2020-12-31' },
452
+ { text: 'Today', value: '2021-1-1' },
453
+ { text: 'Sat, Jan 2', value: '2021-1-2' },
454
+ ]);
455
+ });
456
+ });
@@ -0,0 +1,124 @@
1
+ /*!
2
+ * (C) Ionic http://ionicframework.com - MIT License
3
+ */
4
+ import { generateDayAriaLabel, getMonthAndDay, getFormattedHour, addTimePadding, getMonthAndYear, getLocalizedDayPeriod, getLocalizedTime, } from "../utils/format";
5
+ describe('generateDayAriaLabel()', () => {
6
+ it('should return Wednesday, May 12', () => {
7
+ const reference = { month: 5, day: 12, year: 2021 };
8
+ expect(generateDayAriaLabel('en-US', false, reference)).toEqual('Wednesday, May 12');
9
+ });
10
+ it('should return Today, Wednesday, May 12', () => {
11
+ const reference = { month: 5, day: 12, year: 2021 };
12
+ expect(generateDayAriaLabel('en-US', true, reference)).toEqual('Today, Wednesday, May 12');
13
+ });
14
+ it('should return Saturday, May 1', () => {
15
+ const reference = { month: 5, day: 1, year: 2021 };
16
+ expect(generateDayAriaLabel('en-US', false, reference)).toEqual('Saturday, May 1');
17
+ });
18
+ it('should return Monday, May 31', () => {
19
+ const reference = { month: 5, day: 31, year: 2021 };
20
+ expect(generateDayAriaLabel('en-US', false, reference)).toEqual('Monday, May 31');
21
+ });
22
+ it('should return Saturday, April 1', () => {
23
+ const reference = { month: 4, day: 1, year: 2006 };
24
+ expect(generateDayAriaLabel('en-US', false, reference)).toEqual('Saturday, April 1');
25
+ });
26
+ });
27
+ describe('getMonthAndDay()', () => {
28
+ it('should return Tue, May 11', () => {
29
+ expect(getMonthAndDay('en-US', { month: 5, day: 11, year: 2021 })).toEqual('Tue, May 11');
30
+ });
31
+ it('should return mar, 11 may', () => {
32
+ expect(getMonthAndDay('es-ES', { month: 5, day: 11, year: 2021 })).toEqual('mar, 11 may');
33
+ });
34
+ it('should return Sat, Apr 1', () => {
35
+ expect(getMonthAndDay('en-US', { month: 4, day: 1, year: 2006 })).toEqual('Sat, Apr 1');
36
+ });
37
+ it('should return sáb, 1 abr', () => {
38
+ expect(getMonthAndDay('es-ES', { month: 4, day: 1, year: 2006 })).toEqual('sáb, 1 abr');
39
+ });
40
+ });
41
+ describe('getFormattedHour()', () => {
42
+ it('should only add padding if using 24 hour time', () => {
43
+ expect(getFormattedHour(1, 'h11')).toEqual('1');
44
+ expect(getFormattedHour(1, 'h12')).toEqual('1');
45
+ expect(getFormattedHour(1, 'h23')).toEqual('01');
46
+ expect(getFormattedHour(1, 'h24')).toEqual('01');
47
+ });
48
+ it('should return correct hour value for hour cycle', () => {
49
+ expect(getFormattedHour(0, 'h11')).toEqual('0');
50
+ expect(getFormattedHour(0, 'h12')).toEqual('12');
51
+ expect(getFormattedHour(0, 'h23')).toEqual('00');
52
+ expect(getFormattedHour(0, 'h24')).toEqual('24');
53
+ });
54
+ });
55
+ describe('addTimePadding()', () => {
56
+ it('should add correct amount of padding', () => {
57
+ expect(addTimePadding(0)).toEqual('00');
58
+ expect(addTimePadding(9)).toEqual('09');
59
+ expect(addTimePadding(10)).toEqual('10');
60
+ expect(addTimePadding(100)).toEqual('100');
61
+ });
62
+ });
63
+ describe('getMonthAndYear()', () => {
64
+ it('should return May 2021', () => {
65
+ expect(getMonthAndYear('en-US', { month: 5, day: 11, year: 2021 })).toEqual('May 2021');
66
+ });
67
+ it('should return mayo de 2021', () => {
68
+ expect(getMonthAndYear('es-ES', { month: 5, day: 11, year: 2021 })).toEqual('mayo de 2021');
69
+ });
70
+ it('should return April 2006', () => {
71
+ expect(getMonthAndYear('en-US', { month: 4, day: 1, year: 2006 })).toEqual('April 2006');
72
+ });
73
+ it('should return abril de 2006', () => {
74
+ expect(getMonthAndYear('es-ES', { month: 4, day: 1, year: 2006 })).toEqual('abril de 2006');
75
+ });
76
+ });
77
+ describe('getLocalizedDayPeriod', () => {
78
+ it('should return AM when the date is in the morning', () => {
79
+ expect(getLocalizedDayPeriod('en-US', 'am'));
80
+ });
81
+ it('should return PM when the date is in the afternoon', () => {
82
+ expect(getLocalizedDayPeriod('en-US', 'pm'));
83
+ });
84
+ });
85
+ describe('getLocalizedTime', () => {
86
+ it('should localize the time to PM', () => {
87
+ const datetimeParts = {
88
+ day: 1,
89
+ month: 1,
90
+ year: 2022,
91
+ hour: 13,
92
+ minute: 40,
93
+ };
94
+ expect(getLocalizedTime('en-US', datetimeParts, 'h12')).toEqual('1:40 PM');
95
+ });
96
+ it('should localize the time to AM', () => {
97
+ const datetimeParts = {
98
+ day: 1,
99
+ month: 1,
100
+ year: 2022,
101
+ hour: 9,
102
+ minute: 40,
103
+ };
104
+ expect(getLocalizedTime('en-US', datetimeParts, 'h12')).toEqual('9:40 AM');
105
+ });
106
+ it('should avoid Chromium bug when using 12 hour time in a 24 hour locale', () => {
107
+ const datetimeParts = {
108
+ day: 1,
109
+ month: 1,
110
+ year: 2022,
111
+ hour: 0,
112
+ minute: 0,
113
+ };
114
+ expect(getLocalizedTime('en-GB', datetimeParts, 'h12')).toEqual('12:00 am');
115
+ });
116
+ it('should parse time-only values correctly', () => {
117
+ const datetimeParts = {
118
+ hour: 22,
119
+ minute: 40,
120
+ };
121
+ expect(getLocalizedTime('en-US', datetimeParts, 'h12')).toEqual('10:40 PM');
122
+ expect(getLocalizedTime('en-US', datetimeParts, 'h23')).toEqual('22:40');
123
+ });
124
+ });
@@ -0,0 +1,72 @@
1
+ /*!
2
+ * (C) Ionic http://ionicframework.com - MIT License
3
+ */
4
+ import { isLeapYear, getNumDaysInMonth, is24Hour, isMonthFirstLocale, getHourCycle } from "../utils/helpers";
5
+ describe('daysInMonth()', () => {
6
+ it('should return correct days in month for month and year', () => {
7
+ expect(getNumDaysInMonth(1, 2019)).toBe(31);
8
+ expect(getNumDaysInMonth(2, 2019)).toBe(28);
9
+ expect(getNumDaysInMonth(3, 2019)).toBe(31);
10
+ expect(getNumDaysInMonth(4, 2019)).toBe(30);
11
+ expect(getNumDaysInMonth(5, 2019)).toBe(31);
12
+ expect(getNumDaysInMonth(6, 2019)).toBe(30);
13
+ expect(getNumDaysInMonth(7, 2019)).toBe(31);
14
+ expect(getNumDaysInMonth(8, 2019)).toBe(31);
15
+ expect(getNumDaysInMonth(9, 2019)).toBe(30);
16
+ expect(getNumDaysInMonth(10, 2019)).toBe(31);
17
+ expect(getNumDaysInMonth(11, 2019)).toBe(30);
18
+ expect(getNumDaysInMonth(12, 2019)).toBe(31);
19
+ expect(getNumDaysInMonth(2, 2020)).toBe(29);
20
+ expect(getNumDaysInMonth(2, 2021)).toBe(28);
21
+ expect(getNumDaysInMonth(2, 1900)).toBe(28);
22
+ expect(getNumDaysInMonth(2, 1800)).toBe(28);
23
+ expect(getNumDaysInMonth(2, 2400)).toBe(29);
24
+ });
25
+ });
26
+ describe('isLeapYear()', () => {
27
+ it('should return true if year is leapyear', () => {
28
+ expect(isLeapYear(2096)).toBe(true);
29
+ expect(isLeapYear(2021)).toBe(false);
30
+ expect(isLeapYear(2012)).toBe(true);
31
+ expect(isLeapYear(2000)).toBe(true);
32
+ expect(isLeapYear(1900)).toBe(false);
33
+ expect(isLeapYear(1800)).toBe(false);
34
+ });
35
+ });
36
+ describe('is24Hour()', () => {
37
+ it('should return true if the locale uses 24 hour time', () => {
38
+ expect(is24Hour('h11')).toBe(false);
39
+ expect(is24Hour('h12')).toBe(false);
40
+ expect(is24Hour('h23')).toBe(true);
41
+ expect(is24Hour('h24')).toBe(true);
42
+ });
43
+ });
44
+ describe('getHourCycle()', () => {
45
+ it('should return the correct hour cycle', () => {
46
+ expect(getHourCycle('en-US')).toBe('h12');
47
+ expect(getHourCycle('en-US', 'h23')).toBe('h23');
48
+ expect(getHourCycle('en-US', 'h12')).toBe('h12');
49
+ expect(getHourCycle('en-US-u-hc-h23')).toBe('h23');
50
+ expect(getHourCycle('en-GB')).toBe('h23');
51
+ expect(getHourCycle('en-GB', 'h23')).toBe('h23');
52
+ expect(getHourCycle('en-GB', 'h12')).toBe('h12');
53
+ expect(getHourCycle('en-GB-u-hc-h12')).toBe('h12');
54
+ expect(getHourCycle('en-GB', 'h11')).toBe('h11');
55
+ expect(getHourCycle('en-GB-u-hc-h11')).toBe('h11');
56
+ expect(getHourCycle('en-GB', 'h24')).toBe('h24');
57
+ expect(getHourCycle('en-GB-u-hc-h24')).toBe('h24');
58
+ });
59
+ });
60
+ describe('isMonthFirstLocale()', () => {
61
+ it('should return true if the locale shows months first', () => {
62
+ expect(isMonthFirstLocale('en-US')).toBe(true);
63
+ expect(isMonthFirstLocale('en-GB')).toBe(true);
64
+ expect(isMonthFirstLocale('es-ES')).toBe(true);
65
+ expect(isMonthFirstLocale('ro-RO')).toBe(true);
66
+ });
67
+ it('should return false if the locale shows years first', () => {
68
+ expect(isMonthFirstLocale('zh-CN')).toBe(false);
69
+ expect(isMonthFirstLocale('ja-JP')).toBe(false);
70
+ expect(isMonthFirstLocale('ko-KR')).toBe(false);
71
+ });
72
+ });