@@ -57,7 +57,7 @@ import type { AllPropsType } from '@/props';
57
57
import { defaultMultiCalendars , defaultTransitions , mapPropDates } from '@/utils/defaults' ;
58
58
import { de } from 'date-fns/locale' ;
59
59
import { localToTz } from '@/utils/timezone' ;
60
- import type { TimeZoneConfig } from '@/interfaces' ;
60
+ import type { IDefaultSelect , TimeZoneConfig } from '@/interfaces' ;
61
61
62
62
const getCurrentTime = ( ) => {
63
63
return {
@@ -85,6 +85,13 @@ const getMapDatesOpts = (date: Date, timezone: TimeZoneConfig, highlightFn: (dat
85
85
} ;
86
86
} ;
87
87
88
+ const validateMonthNames = ( months : IDefaultSelect [ ] , values : string [ ] ) => {
89
+ expect ( months ) . toHaveLength ( 12 ) ;
90
+ expect ( months [ 0 ] . text ) . toEqual ( values [ 0 ] ) ;
91
+ expect ( months [ 1 ] . text ) . toEqual ( values [ 1 ] ) ;
92
+ expect ( months [ 2 ] . text ) . toEqual ( values [ 2 ] ) ;
93
+ } ;
94
+
88
95
describe ( 'Utils and date utils formatting' , ( ) => {
89
96
it ( 'Should group array by 3' , ( ) => {
90
97
const items = getArrayInArray ( Array . from ( Array ( 10 ) . keys ( ) ) ) ;
@@ -124,58 +131,31 @@ describe('Utils and date utils formatting', () => {
124
131
125
132
it ( 'Should get long month values according to locale' , ( ) => {
126
133
const months = getMonths ( null , 'en' , 'long' ) ;
127
-
128
- expect ( months ) . toHaveLength ( 12 ) ;
129
- expect ( months [ 0 ] . text ) . toEqual ( 'January' ) ;
130
- expect ( months [ 1 ] . text ) . toEqual ( 'February' ) ;
131
- expect ( months [ 2 ] . text ) . toEqual ( 'March' ) ;
134
+ validateMonthNames ( months , [ 'January' , 'February' , 'March' ] ) ;
132
135
} ) ;
133
136
134
137
it ( 'Should get short month values according to locale' , ( ) => {
135
138
const months = getMonths ( null , 'en' , 'short' ) ;
136
-
137
- expect ( months ) . toHaveLength ( 12 ) ;
138
- expect ( months [ 0 ] . text ) . toEqual ( 'Jan' ) ;
139
- expect ( months [ 1 ] . text ) . toEqual ( 'Feb' ) ;
140
- expect ( months [ 2 ] . text ) . toEqual ( 'Mar' ) ;
139
+ validateMonthNames ( months , [ 'Jan' , 'Feb' , 'Mar' ] ) ;
141
140
} ) ;
142
141
143
- it ( 'Should get long month values according to formatLocale' , ( ) => {
142
+ it ( 'Should get long month values according to formatLocale and fallback locale ' , ( ) => {
144
143
const months = getMonths ( de , 'en' , 'long' ) ;
145
-
146
- expect ( months ) . toHaveLength ( 12 ) ;
147
- expect ( months [ 0 ] . text ) . toEqual ( 'Januar' ) ;
148
- expect ( months [ 1 ] . text ) . toEqual ( 'Februar' ) ;
149
- expect ( months [ 2 ] . text ) . toEqual ( 'März' ) ;
150
- } ) ;
151
-
152
- it ( 'Should get long month values by fallback to locale' , ( ) => {
153
- // Pass incorrect formatLocale
154
- const months = getMonths ( null , 'de' , 'long' ) ;
155
-
156
- expect ( months ) . toHaveLength ( 12 ) ;
157
- expect ( months [ 0 ] . text ) . toEqual ( 'Januar' ) ;
158
- expect ( months [ 1 ] . text ) . toEqual ( 'Februar' ) ;
159
- expect ( months [ 2 ] . text ) . toEqual ( 'März' ) ;
144
+ const namesArr = [ 'Januar' , 'Februar' , 'März' ] ;
145
+ validateMonthNames ( months , namesArr ) ;
146
+ const monthsWithFallback = getMonths ( null , 'de' , 'long' ) ;
147
+ validateMonthNames ( monthsWithFallback , namesArr ) ;
160
148
} ) ;
161
149
162
150
it ( 'Should get short month values according to formatLocale' , ( ) => {
163
151
const months = getMonths ( de , 'en' , 'short' ) ;
164
-
165
- expect ( months ) . toHaveLength ( 12 ) ;
166
- expect ( months [ 0 ] . text ) . toEqual ( 'Jan' ) ;
167
- expect ( months [ 1 ] . text ) . toEqual ( 'Feb' ) ;
168
- expect ( months [ 2 ] . text ) . toEqual ( 'Mär' ) ;
152
+ validateMonthNames ( months , [ 'Jan' , 'Feb' , 'Mär' ] ) ;
169
153
} ) ;
170
154
171
155
it ( 'Should get short month values by fallback to locale' , ( ) => {
172
156
// @ts -expect-error Pass incorrect formatLocale
173
157
const months = getMonths ( { } , 'de' , 'short' ) ;
174
-
175
- expect ( months ) . toHaveLength ( 12 ) ;
176
- expect ( months [ 0 ] . text ) . toEqual ( 'Jan' ) ;
177
- expect ( months [ 1 ] . text ) . toEqual ( 'Feb' ) ;
178
- expect ( months [ 2 ] . text ) . toEqual ( 'Mär' ) ;
158
+ validateMonthNames ( months , [ 'Jan' , 'Feb' , 'Mär' ] ) ;
179
159
} ) ;
180
160
181
161
it ( 'Should get default pattern' , ( ) => {
0 commit comments