@ncds/ui-admin 1.8.21-alpha.5 → 1.8.21-alpha.7

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 (71) hide show
  1. package/dist/cjs/assets/scripts/notification/FullWidthNotification.js +17 -6
  2. package/dist/cjs/assets/scripts/notification/MessageNotification.js +4 -2
  3. package/dist/cjs/assets/scripts/notification/messageTemplate.js +37 -8
  4. package/dist/cjs/constant/notification.js +21 -0
  5. package/dist/cjs/src/components/forms-and-input/input-base/InputBase.js +20 -14
  6. package/dist/cjs/src/components/index.js +11 -0
  7. package/dist/cjs/src/components/overlays/notification/FullWidthNotification.js +3 -1
  8. package/dist/cjs/src/components/overlays/notification/MessageNotification.js +2 -0
  9. package/dist/cjs/src/components/overlays/notification/MessageNotificationParts.js +3 -1
  10. package/dist/cjs/src/components/overlays/notification/__tests__/hidePermanentlyLabel.test.js +209 -0
  11. package/dist/cjs/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +283 -0
  12. package/dist/cjs/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +566 -0
  13. package/dist/cjs/src/components/overlays/postcode-search-modal/index.js +16 -0
  14. package/dist/cjs/src/generated/scoped-css.js +1 -1
  15. package/dist/esm/assets/scripts/notification/FullWidthNotification.js +17 -6
  16. package/dist/esm/assets/scripts/notification/MessageNotification.js +4 -2
  17. package/dist/esm/assets/scripts/notification/messageTemplate.js +37 -8
  18. package/dist/esm/constant/notification.js +15 -0
  19. package/dist/esm/src/components/forms-and-input/input-base/InputBase.js +20 -14
  20. package/dist/esm/src/components/index.js +1 -0
  21. package/dist/esm/src/components/overlays/notification/FullWidthNotification.js +3 -1
  22. package/dist/esm/src/components/overlays/notification/MessageNotification.js +2 -0
  23. package/dist/esm/src/components/overlays/notification/MessageNotificationParts.js +3 -1
  24. package/dist/esm/src/components/overlays/notification/__tests__/hidePermanentlyLabel.test.js +206 -0
  25. package/dist/esm/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +276 -0
  26. package/dist/esm/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +563 -0
  27. package/dist/esm/src/components/overlays/postcode-search-modal/index.js +1 -0
  28. package/dist/esm/src/generated/scoped-css.js +1 -1
  29. package/dist/temp/assets/scripts/notification/FullWidthNotification.d.ts +6 -0
  30. package/dist/temp/assets/scripts/notification/FullWidthNotification.js +14 -5
  31. package/dist/temp/assets/scripts/notification/MessageNotification.js +2 -1
  32. package/dist/temp/assets/scripts/notification/const/types.d.ts +10 -0
  33. package/dist/temp/assets/scripts/notification/messageTemplate.d.ts +1 -0
  34. package/dist/temp/assets/scripts/notification/messageTemplate.js +18 -8
  35. package/dist/temp/constant/notification.d.ts +15 -0
  36. package/dist/temp/constant/notification.js +15 -0
  37. package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +18 -10
  38. package/dist/temp/src/components/index.d.ts +1 -0
  39. package/dist/temp/src/components/index.js +1 -0
  40. package/dist/temp/src/components/overlays/notification/FullWidthNotification.d.ts +6 -0
  41. package/dist/temp/src/components/overlays/notification/FullWidthNotification.js +3 -2
  42. package/dist/temp/src/components/overlays/notification/MessageNotification.d.ts +6 -0
  43. package/dist/temp/src/components/overlays/notification/MessageNotification.js +2 -2
  44. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.d.ts +2 -1
  45. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.js +3 -2
  46. package/dist/temp/src/components/overlays/notification/Notification.d.ts +8 -0
  47. package/dist/temp/src/components/overlays/notification/__tests__/hidePermanentlyLabel.test.d.ts +1 -0
  48. package/dist/temp/src/components/overlays/notification/__tests__/hidePermanentlyLabel.test.js +160 -0
  49. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModal.d.ts +49 -0
  50. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +118 -0
  51. package/dist/temp/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.d.ts +1 -0
  52. package/dist/temp/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +456 -0
  53. package/dist/temp/src/components/overlays/postcode-search-modal/index.d.ts +1 -0
  54. package/dist/temp/src/components/overlays/postcode-search-modal/index.js +1 -0
  55. package/dist/temp/src/generated/scoped-css.js +1 -1
  56. package/dist/types/assets/scripts/notification/FullWidthNotification.d.ts +6 -0
  57. package/dist/types/assets/scripts/notification/const/types.d.ts +10 -0
  58. package/dist/types/assets/scripts/notification/messageTemplate.d.ts +1 -0
  59. package/dist/types/constant/notification.d.ts +15 -0
  60. package/dist/types/src/components/index.d.ts +1 -0
  61. package/dist/types/src/components/overlays/notification/FullWidthNotification.d.ts +6 -0
  62. package/dist/types/src/components/overlays/notification/MessageNotification.d.ts +6 -0
  63. package/dist/types/src/components/overlays/notification/MessageNotificationParts.d.ts +2 -1
  64. package/dist/types/src/components/overlays/notification/Notification.d.ts +8 -0
  65. package/dist/types/src/components/overlays/notification/__tests__/hidePermanentlyLabel.test.d.ts +1 -0
  66. package/dist/types/src/components/overlays/postcode-search-modal/PostcodeSearchModal.d.ts +49 -0
  67. package/dist/types/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.d.ts +1 -0
  68. package/dist/types/src/components/overlays/postcode-search-modal/index.d.ts +1 -0
  69. package/dist/ui-admin/assets/styles/style.css +188 -13
  70. package/dist/ui-admin/assets/styles/style.scoped.css +188 -13
  71. package/package.json +1 -1
@@ -0,0 +1,118 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { AnnotationInfoFill } from '@ncds/ui-admin-icon';
3
+ import classnames from 'classnames';
4
+ import { useEffect, useState } from 'react';
5
+ import { Button } from '../../action/button';
6
+ import { EmptyState } from '../../feedback-and-status/empty-state';
7
+ import { InputBase } from '../../forms-and-input/input-base';
8
+ import { Radio } from '../../forms-and-input/radio';
9
+ import { Pagination } from '../../navigation/pagination';
10
+ import { Modal } from '../modal';
11
+ /** 기획서 기준값 */
12
+ const PAGE_SIZE = 15;
13
+ /** 페이지 번호 그룹 크기 — 초과 시 Pagination 이 점프 버튼을 노출한다 */
14
+ const PAGER_WINDOW = 10;
15
+ /** 이 건수를 넘으면 Tip 을 압축 버전으로 전환한다 (기획서 기준) */
16
+ const TIP_COMPACT_THRESHOLD = 30;
17
+ /** 반응형 전환 기준 — assets/styles/base/_variable.scss 의 $breakpoint 와 동일 */
18
+ const MOBILE_BREAKPOINT = 768;
19
+ const MODAL_TITLE = '주소 찾기';
20
+ const SEARCH_PLACEHOLDER = '도로명, 지번, 건물명 검색';
21
+ const SEARCH_BUTTON_LABEL = '검색';
22
+ const EMPTY_TITLE = '검색 결과가 없습니다.';
23
+ const EMPTY_DESCRIPTION = '검색어를 다시 확인해 주세요.';
24
+ const ROAD_BADGE_LABEL = '도로명';
25
+ const JIBUN_BADGE_LABEL = '지번';
26
+ const TIP_LABEL = 'Tip';
27
+ // 라디오 그룹 이름. `ncua-` 로 시작하면 MCP 의 BEM 추출기가 CSS 클래스로 오인하므로 접두사를 뺀다.
28
+ const RESULT_RADIO_NAME = 'postcode-search-modal-result';
29
+ /** E0006·E0008 외 나머지 코드는 모두 같은 문구를 쓴다(기획서: E0009~E0013 통합). */
30
+ const DEFAULT_ERROR_HINT = '검색어를 다시 입력해주세요.';
31
+ const ERROR_HINT = {
32
+ E0006: '시도명으로는 검색이 불가합니다.',
33
+ E0008: '검색어를 두 글자 이상 입력해주세요.',
34
+ };
35
+ /** Tip 카드 첫 줄 안내 문구 (기획서 TIPS.searchTitle) */
36
+ const TIP_TITLE = '아래 조합으로 검색하면 원하는 주소를 더 쉽게 찾을 수 있어요.';
37
+ /** Tip 상세 버전에 노출할 검색어 조합과 예시 주소 (기획서 TIPS.searchTips) */
38
+ const TIP_ITEMS = [
39
+ { combination: '도로명 + 건물번호', example: '디지털로26길 43' },
40
+ { combination: '지역명(동·리) + 번지', example: '구로동 235-3' },
41
+ { combination: '지역명(동·리) + 건물명(아파트명)', example: '구로동 대륭포스트타워8차' },
42
+ ];
43
+ /** Tip 압축 버전 문구 — 예시 주소를 빼고 조합만 한 줄로 (기획서 TIPS.searchTipsCompact) */
44
+ const TIP_COMPACT_TEXT = "'도로명+건물번호', '지역명+지번', '지역명+건물명(아파트명)'";
45
+ const TIP_EXAMPLE_PREFIX = '예)';
46
+ const TIP_ICON_SIZE = 16;
47
+ /** 선택 표시를 판정하는 키. 우편번호만으로는 같은 건물의 다른 지번을 구분하지 못한다. */
48
+ const resultKey = ({ zipCode, roadAddress, jibunAddress }) => `${zipCode}|${roadAddress}|${jibunAddress}`;
49
+ const resolveTipVariant = (hasResults, totalCount) => {
50
+ if (!hasResults)
51
+ return 'detail';
52
+ return totalCount > TIP_COMPACT_THRESHOLD ? 'compact' : null;
53
+ };
54
+ /** SSR(도큐사우루스 등)에서는 초기값을 false(=PC)로 두고 mount 이후 갱신한다. */
55
+ const useIsMobileViewport = () => {
56
+ const [isMobile, setIsMobile] = useState(false);
57
+ useEffect(() => {
58
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
59
+ return;
60
+ const mediaQuery = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT}px)`);
61
+ const sync = () => setIsMobile(mediaQuery.matches);
62
+ sync();
63
+ mediaQuery.addEventListener('change', sync);
64
+ return () => {
65
+ mediaQuery.removeEventListener('change', sync);
66
+ };
67
+ }, []);
68
+ return isMobile;
69
+ };
70
+ const Tip = ({ compact = false, className }) => {
71
+ return (_jsxs("div", { className: classnames('ncua-postcode-search-modal__tip', className), children: [!compact && (_jsxs("p", { className: "ncua-postcode-search-modal__tip-label", children: [_jsx(AnnotationInfoFill, { className: "ncua-postcode-search-modal__tip-icon", width: TIP_ICON_SIZE, height: TIP_ICON_SIZE }), TIP_LABEL] })), _jsx("p", { className: "ncua-postcode-search-modal__tip-title", children: TIP_TITLE }), compact ? (_jsx("p", { className: "ncua-postcode-search-modal__tip-compact-text", children: TIP_COMPACT_TEXT })) : (_jsx("ul", { className: "ncua-postcode-search-modal__tip-list", children: TIP_ITEMS.map(({ combination, example }) => (_jsxs("li", { className: "ncua-postcode-search-modal__tip-item", children: [_jsx("span", { className: "ncua-postcode-search-modal__tip-combination", children: combination }), _jsx("span", { className: "ncua-postcode-search-modal__tip-example", children: `${TIP_EXAMPLE_PREFIX} ${example}` })] }, combination))) }))] }));
72
+ };
73
+ Tip.displayName = 'PostcodeSearchModal.Tip';
74
+ const PostcodeSearchModal = ({ open, onClose, zIndex, className, searchQuery, onSearchQueryChange, onSearch, results, totalCount, currentPage, onPageChange, pageSize = PAGE_SIZE, loading = false, errorCode, onSelect, }) => {
75
+ const isMobile = useIsMobileViewport();
76
+ // 선택 표시는 컴포넌트가 직접 들고 있는다. 사용처는 onSelect 로 값만 받으면 된다.
77
+ // 우편번호는 한 페이지에 중복될 수 있어 주소 전체를 키로 쓴다.
78
+ const [selectedKey, setSelectedKey] = useState();
79
+ // 검색이 실행된 검색어. 입력 중에는 갱신되지 않는다.
80
+ // 초기값은 마운트 시점의 searchQuery — 사용처가 검색어를 채운 채로 열면 그 검색은 이미 실행된 것으로 본다.
81
+ const [searchedQuery, setSearchedQuery] = useState(searchQuery);
82
+ // Modal 은 닫혀도 이 컴포넌트를 언마운트하지 않아 내부 상태가 다음 열기까지 남는다.
83
+ // 열리는 순간 이전 세션의 선택·검색 상태를 지운다.
84
+ // biome-ignore lint/correctness/useExhaustiveDependencies: searchQuery 를 deps 에 넣으면 입력할 때마다 초기화된다
85
+ useEffect(() => {
86
+ if (!open)
87
+ return;
88
+ setSelectedKey(undefined);
89
+ setSearchedQuery(searchQuery);
90
+ }, [open]);
91
+ const hasError = Boolean(errorCode);
92
+ const hasResults = !hasError && results.length > 0;
93
+ // 검색을 실행한 검색어와 현재 입력값이 같을 때만 "결과 없음"으로 본다.
94
+ // 입력 중에는 두 값이 달라지고, 응답을 기다리는 동안에는 loading 이 막는다.
95
+ const showEmptyState = !hasError && !loading && results.length === 0 && searchQuery !== '' && searchQuery === searchedQuery;
96
+ const tipVariant = resolveTipVariant(hasResults, totalCount);
97
+ const handleSearchQueryChange = (event) => {
98
+ onSearchQueryChange(event.target.value);
99
+ };
100
+ const handleSearch = () => {
101
+ setSearchedQuery(searchQuery);
102
+ onSearch();
103
+ };
104
+ const handleSearchKeyDown = (event) => {
105
+ // 한글 조합 중의 Enter 는 글자 확정이므로 검색으로 보지 않는다.
106
+ if (event.key !== 'Enter' || event.nativeEvent.isComposing)
107
+ return;
108
+ event.preventDefault();
109
+ handleSearch();
110
+ };
111
+ return (_jsxs(Modal, { isOpen: open, onClose: onClose, size: "md", zIndex: zIndex, className: className, children: [_jsx(Modal.Header, { title: MODAL_TITLE, onClose: onClose, showDivider: true }), _jsx(Modal.Content, { children: _jsxs("div", { className: "ncua-postcode-search-modal", children: [_jsxs("div", { className: "ncua-postcode-search-modal__search", children: [_jsx(InputBase, { className: "ncua-postcode-search-modal__search-input", size: "sm", fullWidth: true, value: searchQuery, onChange: handleSearchQueryChange, onKeyDown: handleSearchKeyDown, placeholder: SEARCH_PLACEHOLDER, destructive: hasError, hintText: errorCode ? (ERROR_HINT[errorCode] ?? DEFAULT_ERROR_HINT) : undefined }), _jsx(Button, { className: "ncua-postcode-search-modal__search-button", label: SEARCH_BUTTON_LABEL, size: "sm", hierarchy: "secondary", onClick: handleSearch })] }), tipVariant && _jsx(PostcodeSearchModal.Tip, { compact: tipVariant === 'compact' }), hasResults && (_jsxs(_Fragment, { children: [_jsxs("p", { className: "ncua-postcode-search-modal__count", children: ["\uAC80\uC0C9 ", _jsx("b", { children: totalCount }), "\uAC1C"] }), _jsx("ul", { className: "ncua-postcode-search-modal__list", children: results.map((result, index) => (_jsx("li", { className: "ncua-postcode-search-modal__item", children: _jsx(Radio, { name: RESULT_RADIO_NAME, value: result.zipCode, checked: selectedKey === resultKey(result), onChange: () => {
112
+ setSelectedKey(resultKey(result));
113
+ onSelect(result);
114
+ }, text: _jsxs(_Fragment, { children: [_jsxs("span", { className: "ncua-postcode-search-modal__addr-line", children: [_jsx("span", { className: "ncua-postcode-search-modal__badge", children: ROAD_BADGE_LABEL }), _jsx("span", { className: "ncua-postcode-search-modal__item-road", children: result.roadAddress }), _jsx("span", { className: "ncua-postcode-search-modal__item-zip", children: result.zipCode })] }), _jsxs("span", { className: "ncua-postcode-search-modal__addr-line", children: [_jsx("span", { className: "ncua-postcode-search-modal__badge", children: JIBUN_BADGE_LABEL }), _jsx("span", { className: "ncua-postcode-search-modal__item-jibun", children: result.jibunAddress })] })] }) }) }, `${result.zipCode}-${index}`))) }), _jsx("div", { className: "ncua-postcode-search-modal__pagination", children: _jsx(Pagination, { totalCount: totalCount, itemCountPerPage: pageSize, pageCount: PAGER_WINDOW, currentPage: currentPage, breakPoint: isMobile ? 'mo' : 'pc', onPageChange: onPageChange }) })] })), showEmptyState && (_jsx("div", { className: "ncua-postcode-search-modal__empty", children: _jsx(EmptyState, { title: EMPTY_TITLE, description: EMPTY_DESCRIPTION }) }))] }) })] }));
115
+ };
116
+ PostcodeSearchModal.displayName = 'PostcodeSearchModal';
117
+ PostcodeSearchModal.Tip = Tip;
118
+ export { PostcodeSearchModal };
@@ -0,0 +1,456 @@
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 { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import { PostcodeSearchModal } from '../PostcodeSearchModal';
7
+ // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
8
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
9
+ const PAGE_SIZE = 15;
10
+ /** Tip 압축 임계값(30) 이하 결과 건수 — Tip 미노출 케이스 */
11
+ const SMALL_RESULT_COUNT = 5;
12
+ /** SMALL_RESULT_COUNT 기준 총 페이지 수 */
13
+ const SMALL_RESULT_TOTAL_PAGE = 1;
14
+ /** Tip 압축 임계값(30) 초과 결과 건수 — Tip 압축 + totalPage(3) <= 페이지 그룹 크기(10) */
15
+ const LARGE_RESULT_COUNT = 45;
16
+ /** LARGE_RESULT_COUNT 기준 총 페이지 수 */
17
+ const LARGE_RESULT_TOTAL_PAGE = 3;
18
+ /** 점프 버튼이 뜨는 결과 건수 — totalPage(14) > 페이지 그룹 크기(10) */
19
+ const HUGE_RESULT_COUNT = 200;
20
+ /** 클릭 대상 페이지 번호 */
21
+ const TARGET_PAGE = 3;
22
+ /** 결과 더미 생성 기준값 */
23
+ const ZIP_CODE_BASE = 13529;
24
+ const ROAD_NUMBER_BASE = 242;
25
+ const JIBUN_NUMBER_BASE = 620;
26
+ let root = null;
27
+ let container = null;
28
+ /**
29
+ * Modal 은 createPortal 로 document.body 에 붙으므로 조회 기준은 body 다.
30
+ */
31
+ function render(props) {
32
+ if (!container) {
33
+ container = document.createElement('div');
34
+ document.body.appendChild(container);
35
+ root = createRoot(container);
36
+ }
37
+ act(() => {
38
+ root?.render(createElement(PostcodeSearchModal, props));
39
+ });
40
+ return document.body;
41
+ }
42
+ /** matchMedia 를 vitest 환경에서 stub 한다 (jsdom 은 matches 를 항상 false 로 준다). */
43
+ function stubMatchMedia(matches) {
44
+ vi.stubGlobal('matchMedia', (query) => ({
45
+ matches,
46
+ media: query,
47
+ onchange: null,
48
+ addEventListener: vi.fn(),
49
+ removeEventListener: vi.fn(),
50
+ addListener: vi.fn(),
51
+ removeListener: vi.fn(),
52
+ dispatchEvent: vi.fn(() => false),
53
+ }));
54
+ }
55
+ /**
56
+ * controlled input 에 값을 입력한다.
57
+ * React 는 element 의 value 프로퍼티를 가로채 변경을 추적하므로, 프로토타입의 네이티브 setter 를
58
+ * 직접 호출해야 React 가 "값이 바뀌었다"고 판단하고 onChange 를 발화한다.
59
+ */
60
+ function setInputValue(input, value) {
61
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
62
+ if (!nativeSetter)
63
+ throw new Error('HTMLInputElement.value setter 를 찾을 수 없습니다');
64
+ act(() => {
65
+ nativeSetter.call(input, value);
66
+ input.dispatchEvent(new Event('input', { bubbles: true }));
67
+ });
68
+ }
69
+ function makeResults(count) {
70
+ return Array.from({ length: count }, (_, i) => ({
71
+ zipCode: String(ZIP_CODE_BASE + i),
72
+ roadAddress: `경기 성남시 분당구 판교로 ${ROAD_NUMBER_BASE + i}`,
73
+ jibunAddress: `경기 성남시 분당구 삼평동 ${JIBUN_NUMBER_BASE + i}`,
74
+ }));
75
+ }
76
+ function baseProps(overrides = {}) {
77
+ return {
78
+ open: true,
79
+ onClose: vi.fn(),
80
+ searchQuery: '',
81
+ onSearchQueryChange: vi.fn(),
82
+ onSearch: vi.fn(),
83
+ results: [],
84
+ totalCount: 0,
85
+ currentPage: 1,
86
+ onPageChange: vi.fn(),
87
+ onSelect: vi.fn(),
88
+ ...overrides,
89
+ };
90
+ }
91
+ const tipOf = (el) => el.querySelector('.ncua-postcode-search-modal__tip');
92
+ const isCompactTip = (el) => Boolean(el.querySelector('.ncua-postcode-search-modal__tip-compact-text'));
93
+ const countLabelOf = (el) => el.querySelector('.ncua-postcode-search-modal__count');
94
+ const itemsOf = (el) => el.querySelectorAll('.ncua-postcode-search-modal__item');
95
+ const inputRootOf = (el) => el.querySelector('.ncua-input');
96
+ const hintOf = (el) => el.querySelector('.ncua-input__hint-text');
97
+ const emptyStateOf = (el) => el.querySelector('.ncua-empty-state');
98
+ const paginationOf = (el) => el.querySelector('.ncua-pagination');
99
+ beforeEach(() => {
100
+ stubMatchMedia(false);
101
+ });
102
+ afterEach(() => {
103
+ if (root && container) {
104
+ act(() => root?.unmount());
105
+ container.remove();
106
+ }
107
+ root = null;
108
+ container = null;
109
+ vi.unstubAllGlobals();
110
+ });
111
+ describe('PostcodeSearchModal — Case 1: 검색 전 초기 상태', () => {
112
+ it('상세 Tip 만 노출되고 카운트·리스트·페이지네이션·EmptyState 는 렌더되지 않는다', () => {
113
+ // Given: 검색어·결과가 비어 있고 에러도 없는 상태에서
114
+ // When: 모달을 열면
115
+ const el = render(baseProps());
116
+ // Then: 상세 Tip 만 노출되고 결과 영역은 전부 미노출이다
117
+ expect(tipOf(el)).not.toBeNull();
118
+ expect(isCompactTip(el)).toBe(false);
119
+ expect(countLabelOf(el)).toBeNull();
120
+ expect(el.querySelector('.ncua-postcode-search-modal__list')).toBeNull();
121
+ expect(paginationOf(el)).toBeNull();
122
+ expect(emptyStateOf(el)).toBeNull();
123
+ });
124
+ it('검색 인풋이 비어 있고 destructive 상태가 아니다', () => {
125
+ // Given/When: 초기 상태로 렌더하면
126
+ const el = render(baseProps());
127
+ // Then: 입력값이 비어 있고 오류 스타일이 아니다
128
+ const input = el.querySelector('.ncua-input input');
129
+ expect(input?.value).toBe('');
130
+ expect(inputRootOf(el)?.classList.contains('destructive')).toBe(false);
131
+ expect(hintOf(el)).toBeNull();
132
+ });
133
+ it('open=false 면 아무것도 렌더되지 않는다', () => {
134
+ // Given/When: 닫힌 상태로 렌더하면
135
+ const el = render(baseProps({ open: false }));
136
+ // Then: 모달 자체가 없다
137
+ expect(el.querySelector('.ncua-modal')).toBeNull();
138
+ });
139
+ });
140
+ describe('PostcodeSearchModal — Case 2~4: 에러코드별 hint 매핑', () => {
141
+ it.each([
142
+ ['E0008', '서', '검색어를 두 글자 이상 입력해주세요.'],
143
+ ['E0006', '서울특별시', '시도명으로는 검색이 불가합니다.'],
144
+ ['E0011', '!!!', '검색어를 다시 입력해주세요.'],
145
+ ['E0009', '!!!', '검색어를 다시 입력해주세요.'],
146
+ ['E0010', '!!!', '검색어를 다시 입력해주세요.'],
147
+ ['E0012', '!!!', '검색어를 다시 입력해주세요.'],
148
+ ['E0013', '!!!', '검색어를 다시 입력해주세요.'],
149
+ ])('%s 이면 destructive 와 hint "%s" 가 노출된다', (errorCode, searchQuery, hint) => {
150
+ // Given/When: 에러코드를 전달해 렌더하면
151
+ const el = render(baseProps({ searchQuery, errorCode }));
152
+ // Then: Input 이 destructive 이고 매핑된 hint 문구가 나온다
153
+ expect(inputRootOf(el)?.classList.contains('destructive')).toBe(true);
154
+ expect(hintOf(el)?.textContent).toBe(hint);
155
+ });
156
+ it('에러 상태에서는 상세 Tip 이 노출되고 리스트·EmptyState 는 미노출이다', () => {
157
+ // Given/When: 에러코드를 전달해 렌더하면
158
+ const el = render(baseProps({ searchQuery: '서', errorCode: 'E0008' }));
159
+ // Then: 상세 Tip 만 남는다
160
+ expect(tipOf(el)).not.toBeNull();
161
+ expect(isCompactTip(el)).toBe(false);
162
+ expect(el.querySelector('.ncua-postcode-search-modal__list')).toBeNull();
163
+ expect(emptyStateOf(el)).toBeNull();
164
+ expect(paginationOf(el)).toBeNull();
165
+ });
166
+ });
167
+ describe('PostcodeSearchModal — Case 5: 검색 결과 없음', () => {
168
+ it('검색 실행 전 입력만 한 상태에서는 EmptyState 가 노출되지 않는다', () => {
169
+ // Given: 검색어가 빈 상태로 열려 있다가
170
+ render(baseProps({ searchQuery: '', results: [], totalCount: 0 }));
171
+ // When: 검색을 실행하지 않고 글자만 입력하면
172
+ const el = render(baseProps({ searchQuery: '존재하지않는주소', results: [], totalCount: 0 }));
173
+ // Then: "검색 결과가 없습니다." 는 뜨지 않고 상세 Tip 만 유지된다
174
+ expect(emptyStateOf(el)).toBeNull();
175
+ expect(tipOf(el)).not.toBeNull();
176
+ });
177
+ it('EmptyState 가 "검색 결과가 없습니다." 로 렌더되고 상세 Tip 이 유지된다', () => {
178
+ // Given: 검색어는 있으나 결과가 0건인 상태에서
179
+ const el = render(baseProps({ searchQuery: '존재하지않는주소', results: [], totalCount: 0 }));
180
+ // When: 검색 버튼을 눌러 실제로 검색을 실행하면
181
+ act(() => {
182
+ el.querySelector('.ncua-postcode-search-modal__search-button')?.click();
183
+ });
184
+ // Then: EmptyState 가 노출되고 오류 스타일은 아니며 페이지네이션은 없다
185
+ expect(emptyStateOf(el)?.textContent).toContain('검색 결과가 없습니다.');
186
+ expect(tipOf(el)).not.toBeNull();
187
+ expect(isCompactTip(el)).toBe(false);
188
+ expect(inputRootOf(el)?.classList.contains('destructive')).toBe(false);
189
+ expect(paginationOf(el)).toBeNull();
190
+ expect(countLabelOf(el)).toBeNull();
191
+ });
192
+ });
193
+ describe('PostcodeSearchModal — Case 6: 결과 30건 이하', () => {
194
+ it('카운트 "검색 5개" 와 5행 리스트가 렌더되고 Tip 은 미노출된다', () => {
195
+ // Given/When: 5건 결과를 전달하면
196
+ const results = makeResults(SMALL_RESULT_COUNT);
197
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
198
+ // Then: 카운트·리스트가 노출되고 Tip 은 사라진다
199
+ expect(countLabelOf(el)?.textContent).toBe(`검색 ${SMALL_RESULT_COUNT}개`);
200
+ expect(itemsOf(el)).toHaveLength(SMALL_RESULT_COUNT);
201
+ expect(tipOf(el)).toBeNull();
202
+ });
203
+ it('각 행에 라디오·도로명·우편번호·지번이 모두 렌더된다', () => {
204
+ // Given/When: 5건 결과를 전달하면
205
+ const results = makeResults(SMALL_RESULT_COUNT);
206
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
207
+ // Then: 첫 행의 구성요소가 설계대로 존재한다
208
+ const first = itemsOf(el)[0];
209
+ expect(first.querySelector('input[type="radio"]')).not.toBeNull();
210
+ expect(first.querySelector('.ncua-postcode-search-modal__item-road')?.textContent).toBe(results[0].roadAddress);
211
+ expect(first.querySelector('.ncua-postcode-search-modal__item-zip')?.textContent).toBe(results[0].zipCode);
212
+ expect(first.querySelector('.ncua-postcode-search-modal__item-jibun')?.textContent).toBe(results[0].jibunAddress);
213
+ // 도로명·지번 두 줄과 각 줄의 배지
214
+ expect(first.querySelectorAll('.ncua-postcode-search-modal__addr-line')).toHaveLength(2);
215
+ expect(first.querySelectorAll('.ncua-postcode-search-modal__badge')).toHaveLength(2);
216
+ });
217
+ it('totalPage=1 이면 점프 버튼 없이 페이지 번호만 노출된다', () => {
218
+ // Given/When: 5건(1페이지) 결과를 전달하면
219
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(SMALL_RESULT_COUNT), totalCount: SMALL_RESULT_COUNT }));
220
+ // Then: 점프 버튼이 없다
221
+ expect(paginationOf(el)).not.toBeNull();
222
+ expect(el.querySelector('.ncua-pagination__first')).toBeNull();
223
+ expect(el.querySelector('.ncua-pagination__last')).toBeNull();
224
+ expect(el.querySelectorAll('.ncua-pagination__page-num')).toHaveLength(SMALL_RESULT_TOTAL_PAGE);
225
+ });
226
+ });
227
+ describe('PostcodeSearchModal — Case 7: 결과 30건 초과', () => {
228
+ it('카운트 "검색 45개" 와 15행 리스트, 압축 Tip 이 렌더된다', () => {
229
+ // Given/When: 45건 중 첫 페이지 15건을 전달하면
230
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(PAGE_SIZE), totalCount: LARGE_RESULT_COUNT }));
231
+ // Then: 압축 Tip 이 노출된다
232
+ expect(countLabelOf(el)?.textContent).toBe(`검색 ${LARGE_RESULT_COUNT}개`);
233
+ expect(itemsOf(el)).toHaveLength(PAGE_SIZE);
234
+ expect(tipOf(el)).not.toBeNull();
235
+ expect(isCompactTip(el)).toBe(true);
236
+ });
237
+ it('totalPage(3) 가 PAGER_WINDOW(10) 이하이므로 점프 버튼은 노출되지 않는다', () => {
238
+ // Given/When: totalCount=45, PAGE_SIZE=15 → totalPage=3
239
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(PAGE_SIZE), totalCount: LARGE_RESULT_COUNT }));
240
+ // Then: 페이지 번호 3개만 노출된다
241
+ expect(el.querySelectorAll('.ncua-pagination__page-num')).toHaveLength(LARGE_RESULT_TOTAL_PAGE);
242
+ expect(el.querySelector('.ncua-pagination__first')).toBeNull();
243
+ });
244
+ });
245
+ describe('PostcodeSearchModal — Case 8: 결과 대량', () => {
246
+ it('totalCount=200 이면 첫/이전/다음/마지막 점프 버튼이 노출된다', () => {
247
+ // Given/When: totalCount=200 → totalPage=14 > PAGER_WINDOW(10)
248
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(PAGE_SIZE), totalCount: HUGE_RESULT_COUNT }));
249
+ // Then: 점프 버튼 4종이 모두 존재한다
250
+ expect(el.querySelector('.ncua-pagination__first')).not.toBeNull();
251
+ expect(el.querySelector('.ncua-pagination__before')).not.toBeNull();
252
+ expect(el.querySelector('.ncua-pagination__next')).not.toBeNull();
253
+ expect(el.querySelector('.ncua-pagination__last')).not.toBeNull();
254
+ expect(isCompactTip(el)).toBe(true);
255
+ });
256
+ it('3페이지 버튼을 클릭하면 onPageChange(3) 이 호출된다', () => {
257
+ // Given: 대량 결과가 렌더된 상태에서
258
+ const onPageChange = vi.fn();
259
+ const el = render(baseProps({
260
+ searchQuery: '판교로',
261
+ results: makeResults(PAGE_SIZE),
262
+ totalCount: HUGE_RESULT_COUNT,
263
+ onPageChange,
264
+ }));
265
+ // When: 3번 페이지 버튼을 클릭하면
266
+ const pageButtons = el.querySelectorAll('.ncua-pagination__page-num');
267
+ act(() => {
268
+ pageButtons[TARGET_PAGE - 1]?.click();
269
+ });
270
+ // Then: 3 이 전달된다
271
+ expect(onPageChange).toHaveBeenCalledWith(TARGET_PAGE);
272
+ });
273
+ });
274
+ describe('PostcodeSearchModal — 아이템 선택', () => {
275
+ it('라디오를 클릭하면 해당 결과로 onSelect 가 호출된다', () => {
276
+ // Given: 5건 결과가 렌더된 상태에서
277
+ const results = makeResults(SMALL_RESULT_COUNT);
278
+ const onSelect = vi.fn();
279
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT, onSelect }));
280
+ // When: 2번째 아이템의 라디오를 클릭하면
281
+ const radios = el.querySelectorAll('.ncua-postcode-search-modal__item input[type="radio"]');
282
+ act(() => {
283
+ radios[1]?.click();
284
+ });
285
+ // Then: 2번째 결과 객체가 전달된다
286
+ expect(onSelect).toHaveBeenCalledWith(results[1]);
287
+ });
288
+ it('loading 중에는 결과가 0건이어도 EmptyState 가 뜨지 않는다', () => {
289
+ // Given: 검색을 실행해 EmptyState 가 떠 있는 상태에서
290
+ render(baseProps({ searchQuery: '판교로', results: [], totalCount: 0 }));
291
+ act(() => {
292
+ document.body.querySelector('.ncua-postcode-search-modal__search-button')?.click();
293
+ });
294
+ // When: 사용처가 API 응답을 기다린다고 알리면
295
+ const el = render(baseProps({ searchQuery: '판교로', results: [], totalCount: 0, loading: true }));
296
+ // Then: "검색 결과가 없습니다." 는 노출되지 않는다
297
+ expect(emptyStateOf(el)).toBeNull();
298
+ });
299
+ it('모달을 다시 열면 이전 선택과 검색 상태가 초기화된다', () => {
300
+ // Given: 결과에서 한 행을 고른 뒤
301
+ const results = makeResults(SMALL_RESULT_COUNT);
302
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
303
+ const radios = el.querySelectorAll('.ncua-postcode-search-modal__item input[type="radio"]');
304
+ act(() => {
305
+ radios[1]?.click();
306
+ });
307
+ expect(radios[1].checked).toBe(true);
308
+ // When: 모달을 닫았다가 다시 열면
309
+ render(baseProps({ open: false, searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
310
+ const reopened = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
311
+ // Then: 선택 표시가 남아 있지 않다
312
+ const reopenedRadios = reopened.querySelectorAll('.ncua-postcode-search-modal__item input[type="radio"]');
313
+ expect(reopenedRadios[1].checked).toBe(false);
314
+ });
315
+ it('클릭한 행만 checked 로 표시된다 — 사용처가 값을 되돌려주지 않아도 된다', () => {
316
+ // Given: 결과 5건이 렌더된 상태에서
317
+ const results = makeResults(SMALL_RESULT_COUNT);
318
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: SMALL_RESULT_COUNT }));
319
+ const radios = el.querySelectorAll('.ncua-postcode-search-modal__item input[type="radio"]');
320
+ // When: 두 번째 행을 클릭하면
321
+ act(() => {
322
+ radios[1]?.click();
323
+ });
324
+ // Then: 그 행만 checked 다
325
+ expect(radios[0].checked).toBe(false);
326
+ expect(radios[1].checked).toBe(true);
327
+ expect(radios[2].checked).toBe(false);
328
+ });
329
+ it('우편번호가 같은 행이 있어도 클릭한 행만 checked 다', () => {
330
+ // Given: 같은 우편번호를 쓰는 두 행이 한 페이지에 있을 때
331
+ const sameZip = '13529';
332
+ const results = [
333
+ { zipCode: sameZip, roadAddress: '경기 성남시 분당구 판교로 242', jibunAddress: '경기 성남시 분당구 삼평동 620' },
334
+ { zipCode: sameZip, roadAddress: '경기 성남시 분당구 판교로 242', jibunAddress: '경기 성남시 분당구 삼평동 621' },
335
+ ];
336
+ const el = render(baseProps({ searchQuery: '판교로', results, totalCount: results.length }));
337
+ const radios = el.querySelectorAll('.ncua-postcode-search-modal__item input[type="radio"]');
338
+ // When: 두 번째 행을 클릭하면
339
+ act(() => {
340
+ radios[1]?.click();
341
+ });
342
+ // Then: 첫 행은 선택되지 않는다
343
+ expect(radios[0].checked).toBe(false);
344
+ expect(radios[1].checked).toBe(true);
345
+ });
346
+ });
347
+ describe('PostcodeSearchModal — 검색 인터랙션', () => {
348
+ it('검색 버튼을 누르면 onSearch 가 호출된다', () => {
349
+ // Given: 검색어가 입력된 상태에서
350
+ const onSearch = vi.fn();
351
+ const el = render(baseProps({ searchQuery: '판교로', onSearch }));
352
+ // When: 인풋 바깥 오른쪽의 검색 버튼을 클릭하면
353
+ const searchButton = el.querySelector('.ncua-postcode-search-modal__search-button');
354
+ expect(searchButton?.textContent).toBe('검색');
355
+ act(() => {
356
+ searchButton?.click();
357
+ });
358
+ // Then: onSearch 가 호출된다
359
+ expect(onSearch).toHaveBeenCalledTimes(1);
360
+ });
361
+ it('Enter 를 누르면 onSearch 가 호출된다', () => {
362
+ // Given: 검색어가 입력된 상태에서
363
+ const onSearch = vi.fn();
364
+ const el = render(baseProps({ searchQuery: '판교로', onSearch }));
365
+ const input = el.querySelector('.ncua-input input');
366
+ if (!input)
367
+ throw new Error('검색 인풋이 렌더되지 않았습니다');
368
+ // When: 인풋에서 Enter 를 누르면
369
+ act(() => {
370
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
371
+ });
372
+ // Then: 검색 버튼을 누른 것과 동일하게 onSearch 가 호출된다
373
+ expect(onSearch).toHaveBeenCalledTimes(1);
374
+ });
375
+ it('한글 조합 중 Enter 는 검색으로 보지 않는다', () => {
376
+ // Given: 검색어를 조합 중인 상태에서
377
+ const onSearch = vi.fn();
378
+ const el = render(baseProps({ searchQuery: '판교', onSearch }));
379
+ const input = el.querySelector('.ncua-input input');
380
+ if (!input)
381
+ throw new Error('검색 인풋이 렌더되지 않았습니다');
382
+ // When: 조합 확정용 Enter 가 들어오면
383
+ act(() => {
384
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', isComposing: true, bubbles: true }));
385
+ });
386
+ // Then: 검색은 실행되지 않는다
387
+ expect(onSearch).not.toHaveBeenCalled();
388
+ });
389
+ it('입력값이 바뀌면 onSearchQueryChange 에 새 값이 전달된다', () => {
390
+ // Given: controlled 인풋이 렌더된 상태에서
391
+ const onSearchQueryChange = vi.fn();
392
+ const el = render(baseProps({ onSearchQueryChange }));
393
+ // When: 값을 입력하면
394
+ const input = el.querySelector('.ncua-input input');
395
+ if (!input)
396
+ throw new Error('검색 인풋이 렌더되지 않았습니다');
397
+ // controlled input 은 React 의 value tracker 를 거치므로, 네이티브 setter 로 값을 넣어야
398
+ // React 가 변경을 감지해 onChange 를 발화한다.
399
+ setInputValue(input, '판교로');
400
+ // Then: 새 값이 전달된다
401
+ expect(onSearchQueryChange).toHaveBeenCalledWith('판교로');
402
+ });
403
+ });
404
+ describe('PostcodeSearchModal — 반응형 전환', () => {
405
+ it('데스크톱(768px 초과) 에서는 Pagination 이 pc 모드로 렌더된다', () => {
406
+ // Given/When: matchMedia 가 매치되지 않는 환경에서 렌더하면
407
+ stubMatchMedia(false);
408
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(SMALL_RESULT_COUNT), totalCount: SMALL_RESULT_COUNT }));
409
+ // Then: pc 모디파이어가 붙는다
410
+ expect(paginationOf(el)?.classList.contains('ncua-pagination--pc')).toBe(true);
411
+ });
412
+ it('모바일(768px 이하) 에서는 Pagination 이 mo 모드로 렌더된다', () => {
413
+ // Given/When: 640px 상당으로 matchMedia 가 매치되는 환경에서 렌더하면
414
+ stubMatchMedia(true);
415
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(SMALL_RESULT_COUNT), totalCount: SMALL_RESULT_COUNT }));
416
+ // Then: mo 모디파이어가 붙는다
417
+ expect(paginationOf(el)?.classList.contains('ncua-pagination--mo')).toBe(true);
418
+ });
419
+ });
420
+ describe('PostcodeSearchModal.Tip — 서브컴포넌트', () => {
421
+ it('상세 모드는 조합 3종과 예시 주소를 모두 보여준다', () => {
422
+ // Given/When: 상세 Tip 이 노출되는 초기 상태로 렌더하면
423
+ const el = render(baseProps());
424
+ // Then: 안내 문구와 3개 조합, 예시 주소가 모두 포함된다
425
+ const tipText = tipOf(el)?.textContent ?? '';
426
+ expect(tipText).toContain('아래 조합으로 검색하면 원하는 주소를 더 쉽게 찾을 수 있어요.');
427
+ expect(tipText).toContain('도로명 + 건물번호');
428
+ expect(tipText).toContain('예) 디지털로26길 43');
429
+ expect(tipText).toContain('지역명(동·리) + 번지');
430
+ expect(tipText).toContain('예) 구로동 235-3');
431
+ expect(tipText).toContain('지역명(동·리) + 건물명(아파트명)');
432
+ expect(tipText).toContain('예) 구로동 대륭포스트타워8차');
433
+ });
434
+ it('압축 모드는 조합 3종만 보여주고 예시는 생략한다', () => {
435
+ // Given/When: 30건 초과 결과로 압축 Tip 을 렌더하면
436
+ const el = render(baseProps({ searchQuery: '판교로', results: makeResults(PAGE_SIZE), totalCount: LARGE_RESULT_COUNT }));
437
+ // Then: 조합만 한 줄로 남고 예시 주소는 없다
438
+ const tipText = tipOf(el)?.textContent ?? '';
439
+ expect(tipText).toContain('아래 조합으로 검색하면 원하는 주소를 더 쉽게 찾을 수 있어요.');
440
+ expect(tipText).toContain("'도로명+건물번호', '지역명+지번', '지역명+건물명(아파트명)'");
441
+ expect(tipText).not.toContain('디지털로26길 43');
442
+ expect(tipText).not.toContain('구로동 235-3');
443
+ expect(tipText).not.toContain('구로동 대륭포스트타워8차');
444
+ });
445
+ it('Tip 아이콘은 하드코딩 SVG 가 아니라 아이콘 슬롯 클래스로 렌더된다', () => {
446
+ // Given/When: 상세 Tip 을 렌더하면
447
+ const el = render(baseProps());
448
+ // Then: 지정한 아이콘 클래스를 가진 svg 가 존재한다
449
+ expect(tipOf(el)?.querySelector('svg.ncua-postcode-search-modal__tip-icon')).not.toBeNull();
450
+ });
451
+ it('PostcodeSearchModal.Tip 이 compound 서브컴포넌트로 노출된다', () => {
452
+ // Given/When/Then: displayName 규약을 만족한다
453
+ expect(typeof PostcodeSearchModal.Tip).toBe('function');
454
+ expect(PostcodeSearchModal.Tip.displayName).toBe('PostcodeSearchModal.Tip');
455
+ });
456
+ });
@@ -0,0 +1 @@
1
+ export * from './PostcodeSearchModal';
@@ -0,0 +1 @@
1
+ export * from './PostcodeSearchModal';