@ncds/ui-admin 1.8.17 → 1.8.19-alpha.0

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 (35) hide show
  1. package/dist/cjs/src/components/feedback-and-status/badge/Badge.js +1 -1
  2. package/dist/cjs/src/components/forms-and-input/date-picker/DatePicker.js +174 -38
  3. package/dist/cjs/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +410 -0
  4. package/dist/cjs/src/components/forms-and-input/input-base/InputBase.js +4 -2
  5. package/dist/cjs/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +72 -0
  6. package/dist/cjs/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
  7. package/dist/cjs/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +61 -0
  8. package/dist/cjs/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +249 -0
  9. package/dist/cjs/vitest.config.js +23 -1
  10. package/dist/esm/src/components/feedback-and-status/badge/Badge.js +1 -1
  11. package/dist/esm/src/components/forms-and-input/date-picker/DatePicker.js +174 -38
  12. package/dist/esm/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +410 -0
  13. package/dist/esm/src/components/forms-and-input/input-base/InputBase.js +4 -2
  14. package/dist/esm/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +69 -0
  15. package/dist/esm/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
  16. package/dist/esm/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +61 -0
  17. package/dist/esm/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +250 -1
  18. package/dist/esm/vitest.config.js +22 -1
  19. package/dist/temp/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  20. package/dist/temp/src/components/feedback-and-status/badge/Badge.js +1 -1
  21. package/dist/temp/src/components/forms-and-input/date-picker/DatePicker.js +184 -36
  22. package/dist/temp/src/components/forms-and-input/date-picker/__tests__/DatePicker.test.js +323 -0
  23. package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +3 -3
  24. package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.d.ts +1 -0
  25. package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +59 -0
  26. package/dist/temp/src/components/forms-and-input/range-date-picker/RangeDatePicker.d.ts +9 -0
  27. package/dist/temp/src/components/forms-and-input/range-date-picker/RangeDatePicker.js +9 -6
  28. package/dist/temp/src/components/forms-and-input/range-date-picker/__tests__/RangeDatePicker.test.js +40 -0
  29. package/dist/temp/src/components/forms-and-input/range-date-picker-with-buttons/__tests__/RangeDatePickerWithButtons.test.js +190 -1
  30. package/dist/temp/vitest.config.js +24 -0
  31. package/dist/types/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  32. package/dist/types/src/components/forms-and-input/input-base/__tests__/InputBase.test.d.ts +1 -0
  33. package/dist/types/src/components/forms-and-input/range-date-picker/RangeDatePicker.d.ts +9 -0
  34. package/dist/ui-admin/assets/styles/style.css +4 -3
  35. package/package.json +5 -3
@@ -107,3 +107,326 @@ describe('#3 onValidationError.previousDate', () => {
107
107
  expect(arg.previousDate?.getTime()).not.toBe(arg.date.getTime());
108
108
  });
109
109
  });
110
+ describe('#5 blur 동기화 — flatpickr가 통지하지 않은 값 보정 (#410)', () => {
111
+ const getInstance = (container) => {
112
+ const input = container.querySelector('input');
113
+ expect(input._flatpickr).toBeTruthy();
114
+ return { input, instance: input._flatpickr };
115
+ };
116
+ /** blur 동기화는 한 틱 뒤에 실행되므로 매크로태스크를 한 번 흘려보낸다 */
117
+ const flushBlurSync = async () => {
118
+ await act(async () => {
119
+ await new Promise((resolve) => setTimeout(resolve, 0));
120
+ });
121
+ };
122
+ it('onChange 없이 값만 반영된 채 blur 되면 onChangeDate 로 통지한다', async () => {
123
+ const onChangeDate = vi.fn();
124
+ const container = mount({
125
+ currentDate: '2024-03-01',
126
+ onChangeDate,
127
+ datePickerOptions: { allowInput: true },
128
+ });
129
+ const { input, instance } = getInstance(container);
130
+ // flatpickr documentClick 이 하는 것과 동일하게, onChange 를 발화시키지 않고 값만 반영한다
131
+ act(() => {
132
+ instance.setDate('2024-03-20', false);
133
+ });
134
+ onChangeDate.mockClear();
135
+ act(() => {
136
+ input.dispatchEvent(new Event('blur'));
137
+ });
138
+ await flushBlurSync();
139
+ expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
140
+ });
141
+ it('flatpickr가 이미 onChange 로 통지했으면 blur 가 중복 통지하지 않는다', async () => {
142
+ const onChangeDate = vi.fn();
143
+ const container = mount({
144
+ currentDate: '2024-03-01',
145
+ onChangeDate,
146
+ datePickerOptions: { allowInput: true },
147
+ });
148
+ const { input, instance } = getInstance(container);
149
+ act(() => {
150
+ instance.setDate('2024-03-20', true);
151
+ });
152
+ expect(onChangeDate).toHaveBeenCalledTimes(1);
153
+ act(() => {
154
+ input.dispatchEvent(new Event('blur'));
155
+ });
156
+ await flushBlurSync();
157
+ expect(onChangeDate).toHaveBeenCalledTimes(1);
158
+ });
159
+ it('min/max 위반 값은 blur 로도 통지하지 않고 onValidationError 로 보고한다', async () => {
160
+ const onChangeDate = vi.fn();
161
+ const onValidationError = vi.fn();
162
+ const container = mount({
163
+ currentDate: '2024-03-15',
164
+ onChangeDate,
165
+ onValidationError,
166
+ datePickerOptions: { minDate: '2024-03-10', maxDate: '2024-03-25', allowInput: true },
167
+ });
168
+ const { input, instance } = getInstance(container);
169
+ // 범위 밖 날짜가 onChange 없이 값만 반영된 상태 (마우스로 캘린더 밖 클릭 시 flatpickr 동작)
170
+ act(() => {
171
+ instance.setDate('2024-04-30', false);
172
+ });
173
+ onChangeDate.mockClear();
174
+ onValidationError.mockClear();
175
+ act(() => {
176
+ input.dispatchEvent(new Event('blur'));
177
+ });
178
+ await flushBlurSync();
179
+ expect(onChangeDate).not.toHaveBeenCalled();
180
+ expect(onValidationError).toHaveBeenCalledTimes(1);
181
+ expect(onValidationError.mock.calls[0][0].violations).toContain('maxDate');
182
+ });
183
+ it('enableTime 모드에서 값 변경 없이 blur 해도 통지하지 않는다', async () => {
184
+ const onChangeDate = vi.fn();
185
+ const container = mount({
186
+ currentDate: '2024-03-20',
187
+ onChangeDate,
188
+ datePickerOptions: { enableTime: true, dateFormat: 'Y-m-d H:i', allowInput: true },
189
+ });
190
+ const { input } = getInstance(container);
191
+ onChangeDate.mockClear();
192
+ act(() => {
193
+ input.dispatchEvent(new Event('blur'));
194
+ });
195
+ await flushBlurSync();
196
+ expect(onChangeDate).not.toHaveBeenCalled();
197
+ });
198
+ it('noCalendar(시간 전용) 모드에서 값 변경 없이 blur 해도 통지하지 않는다', async () => {
199
+ const onChangeDate = vi.fn();
200
+ const container = mount({
201
+ currentDate: '',
202
+ onChangeDate,
203
+ datePickerOptions: { enableTime: true, noCalendar: true, dateFormat: 'H:i', allowInput: true },
204
+ });
205
+ const { input } = getInstance(container);
206
+ onChangeDate.mockClear();
207
+ act(() => {
208
+ input.dispatchEvent(new Event('blur'));
209
+ });
210
+ await flushBlurSync();
211
+ expect(onChangeDate).not.toHaveBeenCalled();
212
+ });
213
+ it('noCalendar(시간 전용) 모드에서 통지 없이 시간만 바뀐 채 blur 되면 통지한다', async () => {
214
+ const onChangeDate = vi.fn();
215
+ const container = mount({
216
+ currentDate: '',
217
+ onChangeDate,
218
+ datePickerOptions: { enableTime: true, noCalendar: true, dateFormat: 'H:i', allowInput: true },
219
+ });
220
+ const { input, instance } = getInstance(container);
221
+ act(() => {
222
+ instance.setDate('14:30', false);
223
+ });
224
+ onChangeDate.mockClear();
225
+ act(() => {
226
+ input.dispatchEvent(new Event('blur'));
227
+ });
228
+ await flushBlurSync();
229
+ expect(onChangeDate).toHaveBeenCalledWith('14:30');
230
+ });
231
+ it('portal 모드에서도 통지 없이 값만 반영된 채 blur 되면 통지한다', async () => {
232
+ const onChangeDate = vi.fn();
233
+ const container = mount({
234
+ currentDate: '2024-03-01',
235
+ onChangeDate,
236
+ portal: true,
237
+ datePickerOptions: { allowInput: true },
238
+ });
239
+ const { input, instance } = getInstance(container);
240
+ act(() => {
241
+ instance.setDate('2024-03-20', false);
242
+ });
243
+ onChangeDate.mockClear();
244
+ act(() => {
245
+ input.dispatchEvent(new Event('blur'));
246
+ });
247
+ await flushBlurSync();
248
+ expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
249
+ });
250
+ it('값이 바뀌지 않았으면 blur 만으로는 통지하지 않는다', async () => {
251
+ const onChangeDate = vi.fn();
252
+ const container = mount({
253
+ currentDate: '2024-03-01',
254
+ onChangeDate,
255
+ datePickerOptions: { allowInput: true },
256
+ });
257
+ const { input } = getInstance(container);
258
+ onChangeDate.mockClear();
259
+ act(() => {
260
+ input.dispatchEvent(new Event('blur'));
261
+ });
262
+ await flushBlurSync();
263
+ expect(onChangeDate).not.toHaveBeenCalled();
264
+ });
265
+ });
266
+ describe('#7 타이핑 즉시 통지 — blur 를 기다리지 않는다 (#410)', () => {
267
+ const getInput = (container) => container.querySelector('input.flatpickr-input');
268
+ /** 사용자가 한 글자씩 타이핑하는 것과 동일하게 input 이벤트를 발생시킨다 */
269
+ const typeInto = (input, text) => {
270
+ input.value = '';
271
+ for (const char of text) {
272
+ act(() => {
273
+ input.value = `${input.value}${char}`;
274
+ input.dispatchEvent(new Event('input', { bubbles: true }));
275
+ });
276
+ }
277
+ };
278
+ const flushBlurSync = async () => {
279
+ await act(async () => {
280
+ await new Promise((resolve) => setTimeout(resolve, 0));
281
+ });
282
+ };
283
+ it('완성된 유효 날짜를 타이핑하면 blur 전에 통지한다', () => {
284
+ const onChangeDate = vi.fn();
285
+ const container = mount({
286
+ currentDate: '2024-03-01',
287
+ onChangeDate,
288
+ datePickerOptions: { allowInput: true },
289
+ });
290
+ typeInto(getInput(container), '2024-03-20');
291
+ expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
292
+ });
293
+ it('구분자 없이 8자리 숫자만 타이핑해도 통지한다', () => {
294
+ const onChangeDate = vi.fn();
295
+ const container = mount({
296
+ currentDate: '2024-03-01',
297
+ onChangeDate,
298
+ datePickerOptions: { allowInput: true },
299
+ });
300
+ // 8자리를 다 치는 순간 핸들러가 값을 '2024-03-20' 으로 다시 쓴다.
301
+ // 그 뒤로는 브라우저가 input 이벤트를 더 주지 않으므로 이 시점에 통지해야 한다.
302
+ typeInto(getInput(container), '20240320');
303
+ expect(onChangeDate).toHaveBeenCalledWith('2024-03-20');
304
+ });
305
+ it('아직 완성되지 않은 입력은 통지하지 않는다', () => {
306
+ const onChangeDate = vi.fn();
307
+ const container = mount({
308
+ currentDate: '2024-03-01',
309
+ onChangeDate,
310
+ datePickerOptions: { allowInput: true },
311
+ });
312
+ typeInto(getInput(container), '2024-03-');
313
+ expect(onChangeDate).not.toHaveBeenCalled();
314
+ });
315
+ it('타이핑으로 이미 통지했으면 blur 가 중복 통지하지 않는다', async () => {
316
+ const onChangeDate = vi.fn();
317
+ const container = mount({
318
+ currentDate: '2024-03-01',
319
+ onChangeDate,
320
+ datePickerOptions: { allowInput: true },
321
+ });
322
+ const input = getInput(container);
323
+ typeInto(input, '2024-03-20');
324
+ expect(onChangeDate).toHaveBeenCalledTimes(1);
325
+ act(() => {
326
+ input.dispatchEvent(new Event('blur'));
327
+ });
328
+ await flushBlurSync();
329
+ expect(onChangeDate).toHaveBeenCalledTimes(1);
330
+ });
331
+ it('min/max 범위 밖 날짜는 타이핑 중에 통지하지 않는다 (blur 시점에 한 번만 보고)', () => {
332
+ const onChangeDate = vi.fn();
333
+ const onValidationError = vi.fn();
334
+ const container = mount({
335
+ currentDate: '2024-03-15',
336
+ onChangeDate,
337
+ onValidationError,
338
+ datePickerOptions: { minDate: '2024-03-10', maxDate: '2024-03-25', allowInput: true },
339
+ });
340
+ typeInto(getInput(container), '2024-04-30');
341
+ expect(onChangeDate).not.toHaveBeenCalled();
342
+ expect(onValidationError).not.toHaveBeenCalled();
343
+ });
344
+ it('같은 값은 경로가 달라도 두 번 통지하지 않는다', () => {
345
+ const onChangeDate = vi.fn();
346
+ const container = mount({
347
+ currentDate: '2024-03-01',
348
+ onChangeDate,
349
+ datePickerOptions: { allowInput: true },
350
+ });
351
+ const input = getInput(container);
352
+ // 타이핑으로 통지한 뒤, 캘린더가 같은 날짜로 onChange 를 다시 발화시키는 상황
353
+ typeInto(input, '2024-03-20');
354
+ act(() => {
355
+ input._flatpickr.setDate('2024-03-20', true);
356
+ });
357
+ expect(onChangeDate).toHaveBeenCalledTimes(1);
358
+ });
359
+ it('enableTime 모드에서 날짜만 입력한 상태는 타이핑 중에 통지하지 않는다', () => {
360
+ const onChangeDate = vi.fn();
361
+ const container = mount({
362
+ currentDate: '2024-03-01 00:00',
363
+ onChangeDate,
364
+ datePickerOptions: { enableTime: true, dateFormat: 'Y-m-d H:i', allowInput: true },
365
+ });
366
+ // '2024-03-20' 은 최종 표기('2024-03-20 00:00')와 다르다.
367
+ // 여기서 통지하면 setDate 가 input 을 다시 써서 타이핑 중 커서가 튄다.
368
+ typeInto(getInput(container), '2024-03-20');
369
+ expect(onChangeDate).not.toHaveBeenCalled();
370
+ });
371
+ });
372
+ describe('#8 완성 판정·파싱을 dateFormat 기준으로 한다', () => {
373
+ const getInput = (container) => container.querySelector('input.flatpickr-input');
374
+ const typeInto = (input, text) => {
375
+ input.value = '';
376
+ for (const char of text) {
377
+ act(() => {
378
+ input.value = `${input.value}${char}`;
379
+ input.dispatchEvent(new Event('input', { bubbles: true }));
380
+ });
381
+ }
382
+ };
383
+ it('enableTime 에서 한 글자씩 쳐도 입력이 유지되고 통지된다', () => {
384
+ const onChangeDate = vi.fn();
385
+ const container = mount({
386
+ currentDate: '2026-03-20 23:59',
387
+ onChangeDate,
388
+ datePickerOptions: { allowInput: true, enableTime: true, dateFormat: 'Y-m-d H:i' },
389
+ });
390
+ const input = getInput(container);
391
+ // 완성 길이를 10 으로 고정하면 '2026-03-01 0' 을 완성으로 오판해
392
+ // moment 검증에 걸리고, 입력이 이전 값('2026-03-20 23:59')으로 되돌아갔다
393
+ typeInto(input, '2026-03-01 00:00');
394
+ expect(input.value).toBe('2026-03-01 00:00');
395
+ expect(onChangeDate).toHaveBeenCalledWith('2026-03-01 00:00');
396
+ });
397
+ it('enableTime 에서 시간을 아직 안 친 중간 상태는 통지하지 않는다', () => {
398
+ const onChangeDate = vi.fn();
399
+ const container = mount({
400
+ currentDate: '2026-03-20 23:59',
401
+ onChangeDate,
402
+ datePickerOptions: { allowInput: true, enableTime: true, dateFormat: 'Y-m-d H:i' },
403
+ });
404
+ typeInto(getInput(container), '2026-03-01 00');
405
+ expect(onChangeDate).not.toHaveBeenCalled();
406
+ });
407
+ it('시간 전용(noCalendar) 모드에서 타이핑한 값이 되돌려지지 않는다', () => {
408
+ const onChangeDate = vi.fn();
409
+ const container = mount({
410
+ currentDate: '23:59',
411
+ onChangeDate,
412
+ datePickerOptions: { allowInput: true, enableTime: true, noCalendar: true, dateFormat: 'H:i' },
413
+ });
414
+ const input = getInput(container);
415
+ // 포맷 없이 moment('14:30') 으로 파싱하면 invalid 라 이전 값으로 복원됐다
416
+ typeInto(input, '14:30');
417
+ expect(input.value).toBe('14:30');
418
+ expect(onChangeDate).toHaveBeenCalledWith('14:30');
419
+ });
420
+ it('완성 길이에 도달했지만 실재하지 않는 날짜는 이전 값으로 복원한다', () => {
421
+ const onChangeDate = vi.fn();
422
+ const container = mount({
423
+ currentDate: '2026-03-20',
424
+ onChangeDate,
425
+ datePickerOptions: { allowInput: true },
426
+ });
427
+ const input = getInput(container);
428
+ typeInto(input, '2026-13-45');
429
+ expect(input.value).not.toBe('2026-13-45');
430
+ expect(onChangeDate).not.toHaveBeenCalledWith('2026-13-45');
431
+ });
432
+ });
@@ -13,7 +13,7 @@ const generalSvgSize = {
13
13
  xs: 14,
14
14
  sm: 20,
15
15
  };
16
- const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled, fullWidth = false, validation, destructive, leadingElement, trailingElement, showHelpIcon, maxLength, showTextCount, className, ...props }, ref) => {
16
+ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled, fullWidth = false, validation, destructive, leadingElement, trailingElement, showHelpIcon, maxLength, showTextCount, clearText, onClearText, className, ...props }, ref) => {
17
17
  const inputRef = useRef(null);
18
18
  const [textCount, setTextCount] = useState(0);
19
19
  useEffect(() => {
@@ -59,9 +59,9 @@ const InputBase = forwardRef(({ size = 'xs', required, label, hintText, disabled
59
59
  }
60
60
  };
61
61
  const renderClearButton = () => {
62
- if (!props.clearText)
62
+ if (!clearText)
63
63
  return null;
64
- return (_jsx("button", { type: "button", className: classNames('ncua-input__icon-wrap', 'ncua-input__right-icon', 'ncua-input__clear'), onClick: props.onClearText, children: _jsx(X, { className: "ncua-input__clear-icon", width: validationSvgSize[size], height: validationSvgSize[size] }) }));
64
+ return (_jsx("button", { type: "button", className: classNames('ncua-input__icon-wrap', 'ncua-input__right-icon', 'ncua-input__clear'), onClick: onClearText, children: _jsx(X, { className: "ncua-input__clear-icon", width: validationSvgSize[size], height: validationSvgSize[size] }) }));
65
65
  };
66
66
  const renderStatusIcon = () => {
67
67
  if (destructive) {
@@ -0,0 +1,59 @@
1
+ // @vitest-environment jsdom
2
+ import { createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { act } from 'react-dom/test-utils';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { InputBase } from '../InputBase';
7
+ // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
8
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
9
+ function mountInputBase(props = {}) {
10
+ const container = document.createElement('div');
11
+ document.body.appendChild(container);
12
+ const root = createRoot(container);
13
+ act(() => {
14
+ root.render(createElement(InputBase, props));
15
+ });
16
+ const unmount = () => {
17
+ act(() => {
18
+ root.unmount();
19
+ });
20
+ container.remove();
21
+ };
22
+ return { container, unmount };
23
+ }
24
+ describe('InputBase — clearText prop DOM 누출', () => {
25
+ it('clearText/onClearText가 DOM input 속성으로 전달되지 않는다', () => {
26
+ // Given: console.error를 감시하는 상태에서
27
+ const consoleErrorSpy = vi.spyOn(console, 'error');
28
+ // When: clearText, onClearText를 전달해 렌더하면
29
+ const view = mountInputBase({ clearText: true, onClearText: vi.fn() });
30
+ // Then: 렌더된 <input>에 cleartext 속성이 없고, unknown prop 경고도 발생하지 않는다
31
+ const input = view.container.querySelector('input');
32
+ expect(input).not.toBeNull();
33
+ expect(input?.hasAttribute('cleartext')).toBe(false);
34
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
35
+ consoleErrorSpy.mockRestore();
36
+ view.unmount();
37
+ });
38
+ it('clearText가 true면 clear 버튼이 렌더되고 클릭 시 onClearText가 호출된다', () => {
39
+ // Given: clearText와 onClearText를 전달해 렌더한 상태에서
40
+ const onClearText = vi.fn();
41
+ const view = mountInputBase({ clearText: true, onClearText });
42
+ // When: clear 버튼을 찾아 클릭하면
43
+ const clearButton = view.container.querySelector('.ncua-input__clear');
44
+ expect(clearButton).not.toBeNull();
45
+ act(() => {
46
+ clearButton?.click();
47
+ });
48
+ // Then: onClearText가 호출된다
49
+ expect(onClearText).toHaveBeenCalledTimes(1);
50
+ view.unmount();
51
+ });
52
+ it('clearText를 전달하지 않으면 clear 버튼이 렌더되지 않는다', () => {
53
+ // Given/When: clearText 없이 렌더하면
54
+ const view = mountInputBase();
55
+ // Then: clear 버튼이 존재하지 않는다
56
+ expect(view.container.querySelector('.ncua-input__clear')).toBeNull();
57
+ view.unmount();
58
+ });
59
+ });
@@ -13,6 +13,15 @@ type RangeDatePickerProps = {
13
13
  period: number;
14
14
  };
15
15
  };
16
+ /**
17
+ * 검증 결과 통지. 시작일·종료일 effect 가 각자 자기 쪽 변경만 검증하므로,
18
+ * 사용자가 한쪽 날짜를 바꾸면 그 한쪽(`type`)만 통지된다.
19
+ *
20
+ * 단 **마운트 시점에 이미 역전된 범위**가 들어오면 두 effect 가 함께 돌아
21
+ * `type:'start'` 과 `type:'end'` 가 각각 통지된다. 이때 `newDate` 는 서로 반대편 날짜이므로
22
+ * 양쪽을 모두 반영하면 시작일·종료일이 뒤바뀐다. 한쪽만 처리해야 한다.
23
+ * (validationOption.setting 을 넘기는 사용처에서는 종전부터 동일하게 동작했다.)
24
+ */
16
25
  onDateValidation?: (params: {
17
26
  type: 'start' | 'end';
18
27
  errorType: 'reset' | 'period' | 'overlap' | null;
@@ -90,17 +90,20 @@ const RangeDatePicker = forwardRef(({ startDateOptions, endDateOptions, validati
90
90
  if (!areBothDatesValid(startDateOptions.currentDate, endDateOptions.currentDate)) {
91
91
  return;
92
92
  }
93
- // 종료일이 '오늘'이면 종료측 검증을 건너뛴다: shopby 종료일=오늘이 정상 기본값이라
94
- // (고도몰=어제) 상태를 에러로 잡지 않기 위함. (도입 d1bd8751)
95
- const isNotTodayEndDate = !moment(endDateOptions.currentDate).isSame(moment(), 'day');
96
- if (!validationOption?.setting || !isNotTodayEndDate) {
97
- return;
98
- }
93
+ // overlap(종료일 < 시작일)은 시작일 effect 동일하게 setting 유무보다 먼저 검증한다.
94
+ // 과거에는 아래 setting 가드 뒤에 있어서, setting 넘기지 않는 사용처가 종료일을 시작일보다
95
+ // 앞으로 두어도 onDateValidation 이 호출되지 않았다. (#410)
99
96
  const isOverDate = moment(endDateOptions.currentDate).isBefore(startDateOptions.currentDate);
100
97
  if (isOverDate) {
101
98
  changeSettingDateAndAlert('end');
102
99
  return;
103
100
  }
101
+ // 종료일이 '오늘'이면 기간(period) 검증은 건너뛴다: shopby 는 종료일=오늘이 정상 기본값이라
102
+ // (고도몰=어제) 이 상태를 에러로 잡지 않기 위함. (도입 d1bd8751)
103
+ const isNotTodayEndDate = !moment(endDateOptions.currentDate).isSame(moment(), 'day');
104
+ if (!validationOption?.setting || !isNotTodayEndDate) {
105
+ return;
106
+ }
104
107
  const { unit, period } = validationOption.setting;
105
108
  const isValidPeriod = moment(endDateOptions.currentDate).isSameOrBefore(moment(startDateOptions.currentDate).add(period, unit));
106
109
  if (isValidPeriod) {
@@ -58,3 +58,43 @@ describe('#1 빈/무효 날짜 검증 가드', () => {
58
58
  expect(onDateValidation).toHaveBeenCalled();
59
59
  });
60
60
  });
61
+ describe('#2 validationOption.setting 없이도 overlap 을 검증한다 (#410)', () => {
62
+ it('종료일이 시작일보다 이전이면 type:end / errorType:overlap 으로 통지한다', () => {
63
+ const onDateValidation = vi.fn();
64
+ mount({
65
+ startDateOptions: { currentDate: '2024-03-10', onChangeDate: () => undefined },
66
+ endDateOptions: { currentDate: '2024-03-05', onChangeDate: () => undefined },
67
+ onDateValidation,
68
+ });
69
+ expect(onDateValidation).toHaveBeenCalledWith({
70
+ type: 'end',
71
+ errorType: 'overlap',
72
+ newDate: '2024-03-10',
73
+ currentDate: '2024-03-05',
74
+ });
75
+ });
76
+ it('시작일이 종료일보다 이후이면 type:start / errorType:overlap 으로 통지한다', () => {
77
+ const onDateValidation = vi.fn();
78
+ mount({
79
+ startDateOptions: { currentDate: '2024-03-10', onChangeDate: () => undefined },
80
+ endDateOptions: { currentDate: '2024-03-05', onChangeDate: () => undefined },
81
+ onDateValidation,
82
+ });
83
+ expect(onDateValidation).toHaveBeenCalledWith({
84
+ type: 'start',
85
+ errorType: 'overlap',
86
+ newDate: '2024-03-05',
87
+ currentDate: '2024-03-10',
88
+ });
89
+ });
90
+ it('정상 범위(시작일 <= 종료일)면 setting 없이 overlap 을 통지하지 않는다', () => {
91
+ const onDateValidation = vi.fn();
92
+ mount({
93
+ startDateOptions: { currentDate: '2024-03-01', onChangeDate: () => undefined },
94
+ endDateOptions: { currentDate: '2024-03-05', onChangeDate: () => undefined },
95
+ onDateValidation,
96
+ });
97
+ const overlapCalls = onDateValidation.mock.calls.filter(([arg]) => arg?.errorType === 'overlap');
98
+ expect(overlapCalls).toHaveLength(0);
99
+ });
100
+ });