@@ -12,6 +12,19 @@ import {
12
12
openPicker ,
13
13
} from './util/commonUtil' ;
14
14
15
+ import dayjs from 'dayjs' ;
16
+ import customParseFormat from 'dayjs/plugin/customParseFormat' ;
17
+ import KeyCode from 'rc-util/lib/KeyCode' ;
18
+ dayjs . extend ( customParseFormat ) ;
19
+
20
+ function keyDown ( keyCode : number ) {
21
+ fireEvent . keyDown ( document . querySelector ( 'input' ) , {
22
+ keyCode,
23
+ which : keyCode ,
24
+ charCode : keyCode ,
25
+ } ) ;
26
+ }
27
+
15
28
describe ( 'Picker.DisabledTime' , ( ) => {
16
29
it ( 'disabledTime on TimePicker' , ( ) => {
17
30
render (
@@ -153,11 +166,15 @@ describe('Picker.DisabledTime', () => {
153
166
/> ,
154
167
) ;
155
168
156
- expect ( document . querySelector ( '.rc-picker-input > input' ) . getAttribute ( 'value' ) ) . toEqual ( '1989-11-28 00:00:00' ) ;
169
+ expect ( document . querySelector ( '.rc-picker-input > input' ) . getAttribute ( 'value' ) ) . toEqual (
170
+ '1989-11-28 00:00:00' ,
171
+ ) ;
157
172
158
173
fireEvent . click ( document . querySelectorAll ( '.rc-picker-cell-inner' ) [ 2 ] ) ;
159
174
160
- expect ( document . querySelector ( '.rc-picker-input > input' ) . getAttribute ( 'value' ) ) . toEqual ( '1989-10-31 05:00:00' ) ;
175
+ expect ( document . querySelector ( '.rc-picker-input > input' ) . getAttribute ( 'value' ) ) . toEqual (
176
+ '1989-10-31 05:00:00' ,
177
+ ) ;
161
178
} ) ;
162
179
163
180
it ( 'disabledTime should reset correctly when date changed by click for no default value' , function ( ) {
@@ -174,8 +191,12 @@ describe('Picker.DisabledTime', () => {
174
191
175
192
const firstDayInMonth = now . startOf ( 'month' ) ;
176
193
const firstDayInCalendar = firstDayInMonth . clone ( ) . subtract ( firstDayInMonth . days ( ) , 'days' ) ;
177
- const expected = firstDayInCalendar . clone ( ) . hour ( h + 1 % 24 ) . minute ( m + 1 % 60 ) . second ( s + 1 % 60 ) ;
178
-
194
+ const expected = firstDayInCalendar
195
+ . clone ( )
196
+ . hour ( h + ( 1 % 24 ) )
197
+ . minute ( m + ( 1 % 60 ) )
198
+ . second ( s + ( 1 % 60 ) ) ;
199
+
179
200
render ( < MomentRangePicker open showTime disabledTime = { disabledTime } /> ) ;
180
201
181
202
fireEvent . click ( document . querySelectorAll ( '.rc-picker-cell-inner' ) [ 0 ] ) ;
@@ -184,6 +205,72 @@ describe('Picker.DisabledTime', () => {
184
205
expected . format ( 'YYYY-MM-DD HH:mm:ss' ) ,
185
206
) ;
186
207
} ) ;
208
+ // https://github.com/ant-design/ant-design/issues/45489
209
+ it ( 'disabledTime should reset correctly when date time change by input enter' , ( ) => {
210
+ resetWarned ( ) ;
211
+ const errSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
212
+ const range = ( start , end ) => {
213
+ const result = [ ] ;
214
+ for ( let i = start ; i < end ; i ++ ) {
215
+ result . push ( i ) ;
216
+ }
217
+ return result ;
218
+ } ;
219
+ const disabledDate = ( current ) => {
220
+ return current && current . isBefore ( Date . now ( ) ) ;
221
+ } ;
222
+ const disabledDateTime = ( ) => ( {
223
+ disabledHours : ( ) => range ( 0 , 24 ) . splice ( 4 , 20 ) ,
224
+ disabledMinutes : ( ) => range ( 30 , 60 ) ,
225
+ disabledSeconds : ( ) => [ 55 , 56 ] ,
226
+ } ) ;
227
+
228
+ const expectDate = '2023-10-26 00:00:00' ;
229
+ const changingDate = '2023-10-26 03:00:00' ;
230
+ const nowAllowDate = '2023-10-26 06:00:00' ;
231
+
232
+ const { container } = render (
233
+ < MomentPicker
234
+ showTime
235
+ picker = "date"
236
+ format = "YYYY-MM-DD HH:mm:ss"
237
+ disabledDate = { disabledDate }
238
+ disabledTime = { disabledDateTime }
239
+ defaultValue = { moment ( expectDate ) }
240
+ /> ,
241
+ ) ;
242
+ openPicker ( container ) ;
243
+ const yearPanel = document . querySelector ( '.rc-picker-time-panel-column' ) ;
244
+ expect ( yearPanel . querySelectorAll ( 'li' ) [ 4 ] ) . toHaveClass ( 'rc-picker-time-panel-cell-disabled' ) ;
245
+ closePicker ( container ) ;
246
+
247
+ expect ( document . querySelector ( '.rc-picker-input input' ) . getAttribute ( 'value' ) ) . toEqual (
248
+ expectDate ,
249
+ ) ;
250
+
251
+ fireEvent . click ( document . querySelector ( '.rc-picker-input > input' ) ) ;
252
+ fireEvent . change ( document . querySelector ( '.rc-picker-input > input' ) , {
253
+ target : {
254
+ value : changingDate ,
255
+ } ,
256
+ } ) ;
257
+ keyDown ( KeyCode . ENTER ) ;
258
+ expect ( document . querySelector ( '.rc-picker-input input' ) . getAttribute ( 'value' ) ) . toEqual (
259
+ changingDate ,
260
+ ) ;
261
+ fireEvent . click ( document . querySelector ( '.rc-picker-input > input' ) ) ;
262
+ fireEvent . change ( document . querySelector ( '.rc-picker-input > input' ) , {
263
+ target : {
264
+ value : nowAllowDate ,
265
+ } ,
266
+ } ) ;
267
+
268
+ keyDown ( KeyCode . ENTER ) ;
269
+ expect ( document . querySelector ( '.rc-picker-input input' ) . getAttribute ( 'value' ) ) . toEqual (
270
+ changingDate ,
271
+ ) ;
272
+ errSpy . mockRestore ( ) ;
273
+ } ) ;
187
274
188
275
describe ( 'warning for legacy props' , ( ) => {
189
276
it ( 'single' , ( ) => {
0 commit comments