@ncds/ui-admin 1.8.17 → 1.8.18
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.
- package/dist/cjs/src/components/forms-and-input/date-picker/DatePicker.js +174 -38
- package/dist/cjs/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +410 -0
- package/dist/cjs/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
- package/dist/cjs/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +61 -0
- package/dist/cjs/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +249 -0
- package/dist/cjs/vitest.config.js +23 -1
- package/dist/esm/src/components/forms-and-input/date-picker/DatePicker.js +174 -38
- package/dist/esm/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +410 -0
- package/dist/esm/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
- package/dist/esm/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +61 -0
- package/dist/esm/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +250 -1
- package/dist/esm/vitest.config.js +22 -1
- package/dist/temp/src/components/forms-and-input/date-picker/DatePicker.js +184 -36
- package/dist/temp/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +323 -0
- package/dist/temp/src/components/forms-and-input/range-date-picker/RangeDatePicker.d.ts +9 -0
- package/dist/temp/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
- package/dist/temp/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +40 -0
- package/dist/temp/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +190 -1
- package/dist/temp/vitest.config.js +24 -0
- package/dist/types/src/components/forms-and-input/range-date-picker/RangeDatePicker.d.ts +9 -0
- package/package.json +5 -3
|
@@ -123,4 +123,414 @@ describe('#3 onValidationError.previousDate', () => {
|
|
|
123
123
|
expect(arg.previousDate?.getDate()).toBe(LAST_VALID_DAY); // 직전 유효 날짜 (≠ 위반 날짜)
|
|
124
124
|
expect(arg.previousDate?.getTime()).not.toBe(arg.date.getTime());
|
|
125
125
|
});
|
|
126
|
+
});
|
|
127
|
+
describe('#5 blur 동기화 — flatpickr가 통지하지 않은 값 보정 (#410)', () => {
|
|
128
|
+
const getInstance = container => {
|
|
129
|
+
const input = container.querySelector('input');
|
|
130
|
+
expect(input._flatpickr).toBeTruthy();
|
|
131
|
+
return {
|
|
132
|
+
input,
|
|
133
|
+
instance: input._flatpickr
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/** blur 동기화는 한 틱 뒤에 실행되므로 매크로태스크를 한 번 흘려보낸다 */
|
|
137
|
+
const flushBlurSync = async () => {
|
|
138
|
+
await act(async () => {
|
|
139
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
it('onChange 없이 값만 반영된 채 blur 되면 onChangeDate 로 통지한다', async () => {
|
|
143
|
+
const onChangeDate = vi.fn();
|
|
144
|
+
const container = mount({
|
|
145
|
+
currentDate: '2024-03-01',
|
|
146
|
+
onChangeDate,
|
|
147
|
+
datePickerOptions: {
|
|
148
|
+
allowInput: true
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const {
|
|
152
|
+
input,
|
|
153
|
+
instance
|
|
154
|
+
} = getInstance(container);
|
|
155
|
+
// flatpickr documentClick 이 하는 것과 동일하게, onChange 를 발화시키지 않고 값만 반영한다
|
|
156
|
+
act(() => {
|
|
157
|
+
instance.setDate('2024-03-20', false);
|
|
158
|
+
});
|
|
159
|
+
onChangeDate.mockClear();
|
|
160
|
+
act(() => {
|
|
161
|
+
input.dispatchEvent(new Event('blur'));
|
|
162
|
+
});
|
|
163
|
+
await flushBlurSync();
|
|
164
|
+
expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
|
|
165
|
+
});
|
|
166
|
+
it('flatpickr가 이미 onChange 로 통지했으면 blur 가 중복 통지하지 않는다', async () => {
|
|
167
|
+
const onChangeDate = vi.fn();
|
|
168
|
+
const container = mount({
|
|
169
|
+
currentDate: '2024-03-01',
|
|
170
|
+
onChangeDate,
|
|
171
|
+
datePickerOptions: {
|
|
172
|
+
allowInput: true
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
const {
|
|
176
|
+
input,
|
|
177
|
+
instance
|
|
178
|
+
} = getInstance(container);
|
|
179
|
+
act(() => {
|
|
180
|
+
instance.setDate('2024-03-20', true);
|
|
181
|
+
});
|
|
182
|
+
expect(onChangeDate).toHaveBeenCalledTimes(1);
|
|
183
|
+
act(() => {
|
|
184
|
+
input.dispatchEvent(new Event('blur'));
|
|
185
|
+
});
|
|
186
|
+
await flushBlurSync();
|
|
187
|
+
expect(onChangeDate).toHaveBeenCalledTimes(1);
|
|
188
|
+
});
|
|
189
|
+
it('min/max 위반 값은 blur 로도 통지하지 않고 onValidationError 로 보고한다', async () => {
|
|
190
|
+
const onChangeDate = vi.fn();
|
|
191
|
+
const onValidationError = vi.fn();
|
|
192
|
+
const container = mount({
|
|
193
|
+
currentDate: '2024-03-15',
|
|
194
|
+
onChangeDate,
|
|
195
|
+
onValidationError,
|
|
196
|
+
datePickerOptions: {
|
|
197
|
+
minDate: '2024-03-10',
|
|
198
|
+
maxDate: '2024-03-25',
|
|
199
|
+
allowInput: true
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const {
|
|
203
|
+
input,
|
|
204
|
+
instance
|
|
205
|
+
} = getInstance(container);
|
|
206
|
+
// 범위 밖 날짜가 onChange 없이 값만 반영된 상태 (마우스로 캘린더 밖 클릭 시 flatpickr 동작)
|
|
207
|
+
act(() => {
|
|
208
|
+
instance.setDate('2024-04-30', false);
|
|
209
|
+
});
|
|
210
|
+
onChangeDate.mockClear();
|
|
211
|
+
onValidationError.mockClear();
|
|
212
|
+
act(() => {
|
|
213
|
+
input.dispatchEvent(new Event('blur'));
|
|
214
|
+
});
|
|
215
|
+
await flushBlurSync();
|
|
216
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
217
|
+
expect(onValidationError).toHaveBeenCalledTimes(1);
|
|
218
|
+
expect(onValidationError.mock.calls[0][0].violations).toContain('maxDate');
|
|
219
|
+
});
|
|
220
|
+
it('enableTime 모드에서 값 변경 없이 blur 해도 통지하지 않는다', async () => {
|
|
221
|
+
const onChangeDate = vi.fn();
|
|
222
|
+
const container = mount({
|
|
223
|
+
currentDate: '2024-03-20',
|
|
224
|
+
onChangeDate,
|
|
225
|
+
datePickerOptions: {
|
|
226
|
+
enableTime: true,
|
|
227
|
+
dateFormat: 'Y-m-d H:i',
|
|
228
|
+
allowInput: true
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const {
|
|
232
|
+
input
|
|
233
|
+
} = getInstance(container);
|
|
234
|
+
onChangeDate.mockClear();
|
|
235
|
+
act(() => {
|
|
236
|
+
input.dispatchEvent(new Event('blur'));
|
|
237
|
+
});
|
|
238
|
+
await flushBlurSync();
|
|
239
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
240
|
+
});
|
|
241
|
+
it('noCalendar(시간 전용) 모드에서 값 변경 없이 blur 해도 통지하지 않는다', async () => {
|
|
242
|
+
const onChangeDate = vi.fn();
|
|
243
|
+
const container = mount({
|
|
244
|
+
currentDate: '',
|
|
245
|
+
onChangeDate,
|
|
246
|
+
datePickerOptions: {
|
|
247
|
+
enableTime: true,
|
|
248
|
+
noCalendar: true,
|
|
249
|
+
dateFormat: 'H:i',
|
|
250
|
+
allowInput: true
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const {
|
|
254
|
+
input
|
|
255
|
+
} = getInstance(container);
|
|
256
|
+
onChangeDate.mockClear();
|
|
257
|
+
act(() => {
|
|
258
|
+
input.dispatchEvent(new Event('blur'));
|
|
259
|
+
});
|
|
260
|
+
await flushBlurSync();
|
|
261
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
262
|
+
});
|
|
263
|
+
it('noCalendar(시간 전용) 모드에서 통지 없이 시간만 바뀐 채 blur 되면 통지한다', async () => {
|
|
264
|
+
const onChangeDate = vi.fn();
|
|
265
|
+
const container = mount({
|
|
266
|
+
currentDate: '',
|
|
267
|
+
onChangeDate,
|
|
268
|
+
datePickerOptions: {
|
|
269
|
+
enableTime: true,
|
|
270
|
+
noCalendar: true,
|
|
271
|
+
dateFormat: 'H:i',
|
|
272
|
+
allowInput: true
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
const {
|
|
276
|
+
input,
|
|
277
|
+
instance
|
|
278
|
+
} = getInstance(container);
|
|
279
|
+
act(() => {
|
|
280
|
+
instance.setDate('14:30', false);
|
|
281
|
+
});
|
|
282
|
+
onChangeDate.mockClear();
|
|
283
|
+
act(() => {
|
|
284
|
+
input.dispatchEvent(new Event('blur'));
|
|
285
|
+
});
|
|
286
|
+
await flushBlurSync();
|
|
287
|
+
expect(onChangeDate).toHaveBeenCalledWith('14:30');
|
|
288
|
+
});
|
|
289
|
+
it('portal 모드에서도 통지 없이 값만 반영된 채 blur 되면 통지한다', async () => {
|
|
290
|
+
const onChangeDate = vi.fn();
|
|
291
|
+
const container = mount({
|
|
292
|
+
currentDate: '2024-03-01',
|
|
293
|
+
onChangeDate,
|
|
294
|
+
portal: true,
|
|
295
|
+
datePickerOptions: {
|
|
296
|
+
allowInput: true
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
const {
|
|
300
|
+
input,
|
|
301
|
+
instance
|
|
302
|
+
} = getInstance(container);
|
|
303
|
+
act(() => {
|
|
304
|
+
instance.setDate('2024-03-20', false);
|
|
305
|
+
});
|
|
306
|
+
onChangeDate.mockClear();
|
|
307
|
+
act(() => {
|
|
308
|
+
input.dispatchEvent(new Event('blur'));
|
|
309
|
+
});
|
|
310
|
+
await flushBlurSync();
|
|
311
|
+
expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
|
|
312
|
+
});
|
|
313
|
+
it('값이 바뀌지 않았으면 blur 만으로는 통지하지 않는다', async () => {
|
|
314
|
+
const onChangeDate = vi.fn();
|
|
315
|
+
const container = mount({
|
|
316
|
+
currentDate: '2024-03-01',
|
|
317
|
+
onChangeDate,
|
|
318
|
+
datePickerOptions: {
|
|
319
|
+
allowInput: true
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const {
|
|
323
|
+
input
|
|
324
|
+
} = getInstance(container);
|
|
325
|
+
onChangeDate.mockClear();
|
|
326
|
+
act(() => {
|
|
327
|
+
input.dispatchEvent(new Event('blur'));
|
|
328
|
+
});
|
|
329
|
+
await flushBlurSync();
|
|
330
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
describe('#7 타이핑 즉시 통지 — blur 를 기다리지 않는다 (#410)', () => {
|
|
334
|
+
const getInput = container => container.querySelector('input.flatpickr-input');
|
|
335
|
+
/** 사용자가 한 글자씩 타이핑하는 것과 동일하게 input 이벤트를 발생시킨다 */
|
|
336
|
+
const typeInto = (input, text) => {
|
|
337
|
+
input.value = '';
|
|
338
|
+
for (const char of text) {
|
|
339
|
+
act(() => {
|
|
340
|
+
input.value = `${input.value}${char}`;
|
|
341
|
+
input.dispatchEvent(new Event('input', {
|
|
342
|
+
bubbles: true
|
|
343
|
+
}));
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const flushBlurSync = async () => {
|
|
348
|
+
await act(async () => {
|
|
349
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
it('완성된 유효 날짜를 타이핑하면 blur 전에 통지한다', () => {
|
|
353
|
+
const onChangeDate = vi.fn();
|
|
354
|
+
const container = mount({
|
|
355
|
+
currentDate: '2024-03-01',
|
|
356
|
+
onChangeDate,
|
|
357
|
+
datePickerOptions: {
|
|
358
|
+
allowInput: true
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
typeInto(getInput(container), '2024-03-20');
|
|
362
|
+
expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
|
|
363
|
+
});
|
|
364
|
+
it('구분자 없이 8자리 숫자만 타이핑해도 통지한다', () => {
|
|
365
|
+
const onChangeDate = vi.fn();
|
|
366
|
+
const container = mount({
|
|
367
|
+
currentDate: '2024-03-01',
|
|
368
|
+
onChangeDate,
|
|
369
|
+
datePickerOptions: {
|
|
370
|
+
allowInput: true
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// 8자리를 다 치는 순간 핸들러가 값을 '2024-03-20' 으로 다시 쓴다.
|
|
374
|
+
// 그 뒤로는 브라우저가 input 이벤트를 더 주지 않으므로 이 시점에 통지해야 한다.
|
|
375
|
+
typeInto(getInput(container), '20240320');
|
|
376
|
+
expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
|
|
377
|
+
});
|
|
378
|
+
it('아직 완성되지 않은 입력은 통지하지 않는다', () => {
|
|
379
|
+
const onChangeDate = vi.fn();
|
|
380
|
+
const container = mount({
|
|
381
|
+
currentDate: '2024-03-01',
|
|
382
|
+
onChangeDate,
|
|
383
|
+
datePickerOptions: {
|
|
384
|
+
allowInput: true
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
typeInto(getInput(container), '2024-03-');
|
|
388
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
389
|
+
});
|
|
390
|
+
it('타이핑으로 이미 통지했으면 blur 가 중복 통지하지 않는다', async () => {
|
|
391
|
+
const onChangeDate = vi.fn();
|
|
392
|
+
const container = mount({
|
|
393
|
+
currentDate: '2024-03-01',
|
|
394
|
+
onChangeDate,
|
|
395
|
+
datePickerOptions: {
|
|
396
|
+
allowInput: true
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
const input = getInput(container);
|
|
400
|
+
typeInto(input, '2024-03-20');
|
|
401
|
+
expect(onChangeDate).toHaveBeenCalledTimes(1);
|
|
402
|
+
act(() => {
|
|
403
|
+
input.dispatchEvent(new Event('blur'));
|
|
404
|
+
});
|
|
405
|
+
await flushBlurSync();
|
|
406
|
+
expect(onChangeDate).toHaveBeenCalledTimes(1);
|
|
407
|
+
});
|
|
408
|
+
it('min/max 범위 밖 날짜는 타이핑 중에 통지하지 않는다 (blur 시점에 한 번만 보고)', () => {
|
|
409
|
+
const onChangeDate = vi.fn();
|
|
410
|
+
const onValidationError = vi.fn();
|
|
411
|
+
const container = mount({
|
|
412
|
+
currentDate: '2024-03-15',
|
|
413
|
+
onChangeDate,
|
|
414
|
+
onValidationError,
|
|
415
|
+
datePickerOptions: {
|
|
416
|
+
minDate: '2024-03-10',
|
|
417
|
+
maxDate: '2024-03-25',
|
|
418
|
+
allowInput: true
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
typeInto(getInput(container), '2024-04-30');
|
|
422
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
423
|
+
expect(onValidationError).not.toHaveBeenCalled();
|
|
424
|
+
});
|
|
425
|
+
it('같은 값은 경로가 달라도 두 번 통지하지 않는다', () => {
|
|
426
|
+
const onChangeDate = vi.fn();
|
|
427
|
+
const container = mount({
|
|
428
|
+
currentDate: '2024-03-01',
|
|
429
|
+
onChangeDate,
|
|
430
|
+
datePickerOptions: {
|
|
431
|
+
allowInput: true
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
const input = getInput(container);
|
|
435
|
+
// 타이핑으로 통지한 뒤, 캘린더가 같은 날짜로 onChange 를 다시 발화시키는 상황
|
|
436
|
+
typeInto(input, '2024-03-20');
|
|
437
|
+
act(() => {
|
|
438
|
+
input._flatpickr.setDate('2024-03-20', true);
|
|
439
|
+
});
|
|
440
|
+
expect(onChangeDate).toHaveBeenCalledTimes(1);
|
|
441
|
+
});
|
|
442
|
+
it('enableTime 모드에서 날짜만 입력한 상태는 타이핑 중에 통지하지 않는다', () => {
|
|
443
|
+
const onChangeDate = vi.fn();
|
|
444
|
+
const container = mount({
|
|
445
|
+
currentDate: '2024-03-01 00:00',
|
|
446
|
+
onChangeDate,
|
|
447
|
+
datePickerOptions: {
|
|
448
|
+
enableTime: true,
|
|
449
|
+
dateFormat: 'Y-m-d H:i',
|
|
450
|
+
allowInput: true
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
// '2024-03-20' 은 최종 표기('2024-03-20 00:00')와 다르다.
|
|
454
|
+
// 여기서 통지하면 setDate 가 input 을 다시 써서 타이핑 중 커서가 튄다.
|
|
455
|
+
typeInto(getInput(container), '2024-03-20');
|
|
456
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
describe('#8 완성 판정·파싱을 dateFormat 기준으로 한다', () => {
|
|
460
|
+
const getInput = container => container.querySelector('input.flatpickr-input');
|
|
461
|
+
const typeInto = (input, text) => {
|
|
462
|
+
input.value = '';
|
|
463
|
+
for (const char of text) {
|
|
464
|
+
act(() => {
|
|
465
|
+
input.value = `${input.value}${char}`;
|
|
466
|
+
input.dispatchEvent(new Event('input', {
|
|
467
|
+
bubbles: true
|
|
468
|
+
}));
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
it('enableTime 에서 한 글자씩 쳐도 입력이 유지되고 통지된다', () => {
|
|
473
|
+
const onChangeDate = vi.fn();
|
|
474
|
+
const container = mount({
|
|
475
|
+
currentDate: '2026-03-20 23:59',
|
|
476
|
+
onChangeDate,
|
|
477
|
+
datePickerOptions: {
|
|
478
|
+
allowInput: true,
|
|
479
|
+
enableTime: true,
|
|
480
|
+
dateFormat: 'Y-m-d H:i'
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
const input = getInput(container);
|
|
484
|
+
// 완성 길이를 10 으로 고정하면 '2026-03-01 0' 을 완성으로 오판해
|
|
485
|
+
// moment 검증에 걸리고, 입력이 이전 값('2026-03-20 23:59')으로 되돌아갔다
|
|
486
|
+
typeInto(input, '2026-03-01 00:00');
|
|
487
|
+
expect(input.value).toBe('2026-03-01 00:00');
|
|
488
|
+
expect(onChangeDate).toHaveBeenCalledWith('2026-03-01 00:00');
|
|
489
|
+
});
|
|
490
|
+
it('enableTime 에서 시간을 아직 안 친 중간 상태는 통지하지 않는다', () => {
|
|
491
|
+
const onChangeDate = vi.fn();
|
|
492
|
+
const container = mount({
|
|
493
|
+
currentDate: '2026-03-20 23:59',
|
|
494
|
+
onChangeDate,
|
|
495
|
+
datePickerOptions: {
|
|
496
|
+
allowInput: true,
|
|
497
|
+
enableTime: true,
|
|
498
|
+
dateFormat: 'Y-m-d H:i'
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
typeInto(getInput(container), '2026-03-01 00');
|
|
502
|
+
expect(onChangeDate).not.toHaveBeenCalled();
|
|
503
|
+
});
|
|
504
|
+
it('시간 전용(noCalendar) 모드에서 타이핑한 값이 되돌려지지 않는다', () => {
|
|
505
|
+
const onChangeDate = vi.fn();
|
|
506
|
+
const container = mount({
|
|
507
|
+
currentDate: '23:59',
|
|
508
|
+
onChangeDate,
|
|
509
|
+
datePickerOptions: {
|
|
510
|
+
allowInput: true,
|
|
511
|
+
enableTime: true,
|
|
512
|
+
noCalendar: true,
|
|
513
|
+
dateFormat: 'H:i'
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
const input = getInput(container);
|
|
517
|
+
// 포맷 없이 moment('14:30') 으로 파싱하면 invalid 라 이전 값으로 복원됐다
|
|
518
|
+
typeInto(input, '14:30');
|
|
519
|
+
expect(input.value).toBe('14:30');
|
|
520
|
+
expect(onChangeDate).toHaveBeenCalledWith('14:30');
|
|
521
|
+
});
|
|
522
|
+
it('완성 길이에 도달했지만 실재하지 않는 날짜는 이전 값으로 복원한다', () => {
|
|
523
|
+
const onChangeDate = vi.fn();
|
|
524
|
+
const container = mount({
|
|
525
|
+
currentDate: '2026-03-20',
|
|
526
|
+
onChangeDate,
|
|
527
|
+
datePickerOptions: {
|
|
528
|
+
allowInput: true
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
const input = getInput(container);
|
|
532
|
+
typeInto(input, '2026-13-45');
|
|
533
|
+
expect(input.value).not.toBe('2026-13-45');
|
|
534
|
+
expect(onChangeDate).not.toHaveBeenCalledWith('2026-13-45');
|
|
535
|
+
});
|
|
126
536
|
});
|
|
@@ -112,17 +112,20 @@ const RangeDatePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
112
112
|
if (!areBothDatesValid(startDateOptions.currentDate, endDateOptions.currentDate)) {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
if (!validationOption?.setting || !isNotTodayEndDate) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
115
|
+
// overlap(종료일 < 시작일)은 시작일 effect 와 동일하게 setting 유무보다 먼저 검증한다.
|
|
116
|
+
// 과거에는 아래 setting 가드 뒤에 있어서, setting 을 넘기지 않는 사용처가 종료일을 시작일보다
|
|
117
|
+
// 앞으로 두어도 onDateValidation 이 호출되지 않았다. (#410)
|
|
121
118
|
const isOverDate = moment(endDateOptions.currentDate).isBefore(startDateOptions.currentDate);
|
|
122
119
|
if (isOverDate) {
|
|
123
120
|
changeSettingDateAndAlert('end');
|
|
124
121
|
return;
|
|
125
122
|
}
|
|
123
|
+
// 종료일이 '오늘'이면 기간(period) 검증은 건너뛴다: shopby 는 종료일=오늘이 정상 기본값이라
|
|
124
|
+
// (고도몰=어제) 이 상태를 에러로 잡지 않기 위함. (도입 d1bd8751)
|
|
125
|
+
const isNotTodayEndDate = !moment(endDateOptions.currentDate).isSame(moment(), 'day');
|
|
126
|
+
if (!validationOption?.setting || !isNotTodayEndDate) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
126
129
|
const {
|
|
127
130
|
unit,
|
|
128
131
|
period
|
package/dist/esm/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js
CHANGED
|
@@ -89,4 +89,65 @@ describe('#1 빈/무효 날짜 검증 가드', () => {
|
|
|
89
89
|
});
|
|
90
90
|
expect(onDateValidation).toHaveBeenCalled();
|
|
91
91
|
});
|
|
92
|
+
});
|
|
93
|
+
describe('#2 validationOption.setting 없이도 overlap 을 검증한다 (#410)', () => {
|
|
94
|
+
it('종료일이 시작일보다 이전이면 type:end / errorType:overlap 으로 통지한다', () => {
|
|
95
|
+
const onDateValidation = vi.fn();
|
|
96
|
+
mount({
|
|
97
|
+
startDateOptions: {
|
|
98
|
+
currentDate: '2024-03-10',
|
|
99
|
+
onChangeDate: () => undefined
|
|
100
|
+
},
|
|
101
|
+
endDateOptions: {
|
|
102
|
+
currentDate: '2024-03-05',
|
|
103
|
+
onChangeDate: () => undefined
|
|
104
|
+
},
|
|
105
|
+
onDateValidation
|
|
106
|
+
});
|
|
107
|
+
expect(onDateValidation).toHaveBeenCalledWith({
|
|
108
|
+
type: 'end',
|
|
109
|
+
errorType: 'overlap',
|
|
110
|
+
newDate: '2024-03-10',
|
|
111
|
+
currentDate: '2024-03-05'
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
it('시작일이 종료일보다 이후이면 type:start / errorType:overlap 으로 통지한다', () => {
|
|
115
|
+
const onDateValidation = vi.fn();
|
|
116
|
+
mount({
|
|
117
|
+
startDateOptions: {
|
|
118
|
+
currentDate: '2024-03-10',
|
|
119
|
+
onChangeDate: () => undefined
|
|
120
|
+
},
|
|
121
|
+
endDateOptions: {
|
|
122
|
+
currentDate: '2024-03-05',
|
|
123
|
+
onChangeDate: () => undefined
|
|
124
|
+
},
|
|
125
|
+
onDateValidation
|
|
126
|
+
});
|
|
127
|
+
expect(onDateValidation).toHaveBeenCalledWith({
|
|
128
|
+
type: 'start',
|
|
129
|
+
errorType: 'overlap',
|
|
130
|
+
newDate: '2024-03-05',
|
|
131
|
+
currentDate: '2024-03-10'
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it('정상 범위(시작일 <= 종료일)면 setting 없이 overlap 을 통지하지 않는다', () => {
|
|
135
|
+
const onDateValidation = vi.fn();
|
|
136
|
+
mount({
|
|
137
|
+
startDateOptions: {
|
|
138
|
+
currentDate: '2024-03-01',
|
|
139
|
+
onChangeDate: () => undefined
|
|
140
|
+
},
|
|
141
|
+
endDateOptions: {
|
|
142
|
+
currentDate: '2024-03-05',
|
|
143
|
+
onChangeDate: () => undefined
|
|
144
|
+
},
|
|
145
|
+
onDateValidation
|
|
146
|
+
});
|
|
147
|
+
const overlapCalls = onDateValidation.mock.calls.filter(_ref2 => {
|
|
148
|
+
let [arg] = _ref2;
|
|
149
|
+
return arg?.errorType === 'overlap';
|
|
150
|
+
});
|
|
151
|
+
expect(overlapCalls).toHaveLength(0);
|
|
152
|
+
});
|
|
92
153
|
});
|