@ncds/ui-admin 1.8.21-alpha.8 → 1.8.21

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 (56) 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/input-base/InputBase.js +13 -7
  3. package/dist/cjs/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +16 -11
  4. package/dist/cjs/src/components/navigation/pagination/Pagination.js +3 -1
  5. package/dist/cjs/src/components/navigation/pagination/__tests__/Pagination.test.js +74 -0
  6. package/dist/cjs/src/components/overlays/notification/CalloutNotification.js +6 -1
  7. package/dist/cjs/src/components/overlays/notification/Notification.js +22 -2
  8. package/dist/cjs/src/components/overlays/notification/__tests__/CalloutNotification.test.js +128 -0
  9. package/dist/cjs/src/components/overlays/notification/__tests__/Notification.test.js +83 -0
  10. package/dist/cjs/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +72 -90
  11. package/dist/cjs/src/components/overlays/postcode-search-modal/PostcodeSearchModalTip.js +70 -0
  12. package/dist/cjs/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +96 -39
  13. package/dist/cjs/src/generated/scoped-css.js +1 -1
  14. package/dist/esm/src/components/feedback-and-status/badge/Badge.js +1 -1
  15. package/dist/esm/src/components/forms-and-input/input-base/InputBase.js +13 -7
  16. package/dist/esm/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +16 -11
  17. package/dist/esm/src/components/navigation/pagination/Pagination.js +3 -1
  18. package/dist/esm/src/components/navigation/pagination/__tests__/Pagination.test.js +74 -0
  19. package/dist/esm/src/components/overlays/notification/CalloutNotification.js +6 -1
  20. package/dist/esm/src/components/overlays/notification/Notification.js +22 -2
  21. package/dist/esm/src/components/overlays/notification/__tests__/CalloutNotification.test.js +125 -0
  22. package/dist/esm/src/components/overlays/notification/__tests__/Notification.test.js +80 -0
  23. package/dist/esm/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +72 -90
  24. package/dist/esm/src/components/overlays/postcode-search-modal/PostcodeSearchModalTip.js +63 -0
  25. package/dist/esm/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +96 -39
  26. package/dist/esm/src/generated/scoped-css.js +1 -1
  27. package/dist/temp/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  28. package/dist/temp/src/components/feedback-and-status/badge/Badge.js +1 -1
  29. package/dist/temp/src/components/forms-and-input/input-base/InputBase.js +10 -4
  30. package/dist/temp/src/components/forms-and-input/input-base/__tests__/InputBase.test.js +14 -12
  31. package/dist/temp/src/components/navigation/pagination/Pagination.js +3 -1
  32. package/dist/temp/src/components/navigation/pagination/__tests__/Pagination.test.js +74 -0
  33. package/dist/temp/src/components/overlays/notification/CalloutNotification.d.ts +3 -1
  34. package/dist/temp/src/components/overlays/notification/CalloutNotification.js +5 -1
  35. package/dist/temp/src/components/overlays/notification/Notification.d.ts +12 -2
  36. package/dist/temp/src/components/overlays/notification/Notification.js +9 -4
  37. package/dist/temp/src/components/overlays/notification/__tests__/CalloutNotification.test.d.ts +1 -0
  38. package/dist/temp/src/components/overlays/notification/__tests__/CalloutNotification.test.js +108 -0
  39. package/dist/temp/src/components/overlays/notification/__tests__/Notification.test.d.ts +1 -0
  40. package/dist/temp/src/components/overlays/notification/__tests__/Notification.test.js +71 -0
  41. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModal.d.ts +2 -6
  42. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModal.js +38 -27
  43. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModalTip.d.ts +16 -0
  44. package/dist/temp/src/components/overlays/postcode-search-modal/PostcodeSearchModalTip.js +24 -0
  45. package/dist/temp/src/components/overlays/postcode-search-modal/__tests__/PostcodeSearchModal.test.js +82 -35
  46. package/dist/temp/src/generated/scoped-css.js +1 -1
  47. package/dist/types/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  48. package/dist/types/src/components/overlays/notification/CalloutNotification.d.ts +3 -1
  49. package/dist/types/src/components/overlays/notification/Notification.d.ts +12 -2
  50. package/dist/types/src/components/overlays/notification/__tests__/CalloutNotification.test.d.ts +1 -0
  51. package/dist/types/src/components/overlays/notification/__tests__/Notification.test.d.ts +1 -0
  52. package/dist/types/src/components/overlays/postcode-search-modal/PostcodeSearchModal.d.ts +2 -6
  53. package/dist/types/src/components/overlays/postcode-search-modal/PostcodeSearchModalTip.d.ts +16 -0
  54. package/dist/ui-admin/assets/styles/style.css +91 -33
  55. package/package.json +1 -1
  56. package/dist/ui-admin/assets/styles/style.scoped.css +0 -8557
@@ -9,7 +9,7 @@ const BADGE_ICON_SIZE = 12;
9
9
  /** new-badge 박스 안에 들어가는 'N' 아이콘 크기. 박스는 sm 16px / md 20px 이며 아이콘은 그보다 작다(패딩 포함). */
10
10
  const NEW_BADGE_ICON_SIZE = {
11
11
  sm: 12,
12
- md: 14
12
+ md: 16
13
13
  };
14
14
  const Badge = _ref => {
15
15
  let {
@@ -5,12 +5,18 @@ import { forwardRef, useEffect, useRef, useState } from 'react';
5
5
  import { COLOR } from '../../../../constant/color';
6
6
  import { HintText } from '../../shared/hintText/HintText';
7
7
  import { Label } from '../../shared/label/Label';
8
- // 슬롯 아이콘(leadingElement/trailingElement) 상태 아이콘(clear·validation·destructive)은 같은 크기를 쓴다.
8
+ // 슬롯 아이콘(leadingElement/trailingElement) 인풋 크기에 맞춰 커진다.
9
9
  // slot.size 를 명시하면 그 값이 우선한다.
10
10
  const iconSvgSize = {
11
11
  xs: 14,
12
12
  sm: 20
13
13
  };
14
+ // 상태 아이콘(clear·validation·destructive)은 인풋 크기와 무관하게 16px 로 고정한다.
15
+ // 슬롯 아이콘은 sm 에서 20px 로 커지므로 두 상수를 하나로 합치지 않는다.
16
+ const statusIconSvgSize = {
17
+ xs: 14,
18
+ sm: 16
19
+ };
14
20
  const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
15
21
  let {
16
22
  size = 'xs',
@@ -118,8 +124,8 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
118
124
  onClick: onClearText,
119
125
  children: _jsx(X, {
120
126
  className: "ncua-input__clear-icon",
121
- width: iconSvgSize[size],
122
- height: iconSvgSize[size]
127
+ width: statusIconSvgSize[size],
128
+ height: statusIconSvgSize[size]
123
129
  })
124
130
  });
125
131
  };
@@ -129,8 +135,8 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
129
135
  className: "ncua-input__icon-wrap ncua-input__right-icon",
130
136
  children: _jsx(InfoCircle, {
131
137
  className: "ncua-input__destructive-icon",
132
- width: iconSvgSize[size],
133
- height: iconSvgSize[size]
138
+ width: statusIconSvgSize[size],
139
+ height: statusIconSvgSize[size]
134
140
  })
135
141
  });
136
142
  }
@@ -139,8 +145,8 @@ const InputBase = /*#__PURE__*/forwardRef((_ref, ref) => {
139
145
  className: "ncua-input__icon-wrap ncua-input__right-icon",
140
146
  children: _jsx(CheckCircle, {
141
147
  className: "ncua-input__validation-icon",
142
- width: iconSvgSize[size],
143
- height: iconSvgSize[size]
148
+ width: statusIconSvgSize[size],
149
+ height: statusIconSvgSize[size]
144
150
  })
145
151
  });
146
152
  }
@@ -77,8 +77,9 @@ describe('InputBase — 아이콘 사이즈', () => {
77
77
  height: svg?.getAttribute('height')
78
78
  };
79
79
  };
80
- // 슬롯 아이콘과 상태 아이콘은 같은 크기를 쓴다 과거 상태 아이콘만 sm=16으로 어긋나 있었다
81
- it.each([['xs', '14'], ['sm', '20']])('size=%s 때 슬롯 아이콘과 상태 아이콘이 모두 %spx렌더된다', (size, expected) => {
80
+ // 슬롯 아이콘은 인풋 크기에 연동돼 sm 에서 20px 커지지만,
81
+ // 상태 아이콘(clear·validation·destructive) 16px고정한다.
82
+ it.each([['xs', '14', '14'], ['sm', '20', '16']])('size=%s 일 때 슬롯 아이콘은 %spx, 상태 아이콘은 %spx로 렌더된다', (size, slotExpected, statusExpected) => {
82
83
  // Given/When: 슬롯 아이콘과 clear 버튼, destructive 상태를 함께 렌더하면
83
84
  const view = mountInputBase({
84
85
  size,
@@ -90,23 +91,27 @@ describe('InputBase — 아이콘 사이즈', () => {
90
91
  icon: SearchLg
91
92
  }
92
93
  });
93
- // Then: 슬롯·clear·destructive 아이콘의 크기가 서로 어긋나지 않는다
94
- const expectedSize = {
95
- width: expected,
96
- height: expected
94
+ // Then: 슬롯 아이콘만 인풋 크기를 따라가고, 상태 아이콘은 16px 을 넘지 않는다
95
+ const slotSize = {
96
+ width: slotExpected,
97
+ height: slotExpected
98
+ };
99
+ const statusSize = {
100
+ width: statusExpected,
101
+ height: statusExpected
97
102
  };
98
- expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual(expectedSize);
99
- expect(iconSizeOf(view.container, '.ncua-input__clear-icon')).toEqual(expectedSize);
100
- expect(iconSizeOf(view.container, '.ncua-input__destructive-icon')).toEqual(expectedSize);
103
+ expect(iconSizeOf(view.container, '.ncua-input__left-icon')).toEqual(slotSize);
104
+ expect(iconSizeOf(view.container, '.ncua-input__clear-icon')).toEqual(statusSize);
105
+ expect(iconSizeOf(view.container, '.ncua-input__destructive-icon')).toEqual(statusSize);
101
106
  view.unmount();
102
107
  });
103
- it.each([['xs', '14'], ['sm', '20']])('size=%s 일 때 validation 아이콘도 %spx로 렌더된다', (size, expected) => {
108
+ it.each([['xs', '14'], ['sm', '16']])('size=%s 일 때 validation 아이콘은 %spx로 렌더된다', (size, expected) => {
104
109
  // Given/When: validation 상태로 렌더하면
105
110
  const view = mountInputBase({
106
111
  size,
107
112
  validation: true
108
113
  });
109
- // Then: 다른 아이콘과 같은 크기다
114
+ // Then: 다른 상태 아이콘과 같은 크기다
110
115
  expect(iconSizeOf(view.container, '.ncua-input__validation-icon')).toEqual({
111
116
  width: expected,
112
117
  height: expected
@@ -19,7 +19,9 @@ export const Pagination = _ref => {
19
19
  const [start, setStart] = useState(1);
20
20
  const noPrev = breakPoint === 'mo' ? currentPage === 1 : start === 1;
21
21
  const noNext = breakPoint === 'mo' ? currentPage >= totalPage : start + pageCount - 1 >= totalPage;
22
- const showJumpPageButton = totalPage > pageCount;
22
+ // mo CSS 페이지 번호 목록과 first/last 를 숨겨 prev/next 만 남는다.
23
+ // pc 기준(totalPage > pageCount)을 그대로 쓰면 페이지가 적을 때 이동 수단이 하나도 없다.
24
+ const showJumpPageButton = breakPoint === 'mo' ? totalPage > 1 : totalPage > pageCount;
23
25
  const handleClickButton = pageNum => {
24
26
  if (isFunction(onPageChange)) {
25
27
  onPageChange(pageNum);
@@ -12,6 +12,12 @@ const CURRENT_PAGE = 91; // 100페이지 기준 마지막 그룹(91~100)을 보
12
12
  const GROUP_START_100_PAGES = 91; // currentPage=91 일 때의 그룹 시작
13
13
  const GROUP_START_50_PAGES = 41; // totalPage=50 으로 줄었을 때의 마지막 그룹 시작
14
14
  const LAST_PAGE_50 = 50;
15
+ /** 페이지 그룹 크기(10) 이하로 나뉘는 건수 — 3페이지 */
16
+ const TOTAL_COUNT_3_PAGES = 30;
17
+ /** TOTAL_COUNT_3_PAGES 기준 총 페이지 수 = 마지막 페이지 번호 */
18
+ const LAST_PAGE_3 = 3;
19
+ /** 페이지가 하나뿐인 건수 */
20
+ const TOTAL_COUNT_1_PAGE = 8;
15
21
  let root = null;
16
22
  let container = null;
17
23
  function render(props) {
@@ -34,6 +40,8 @@ afterEach(() => {
34
40
  container = null;
35
41
  });
36
42
  const pageNums = el => Array.from(el.querySelectorAll('.ncua-pagination__page-num')).map(b => Number(b.textContent));
43
+ const prevOf = el => el.querySelector('.ncua-pagination__before');
44
+ const nextOf = el => el.querySelector('.ncua-pagination__next');
37
45
  describe('#332 Pagination — totalPage 축소 시 start 보정', () => {
38
46
  it('totalPage 가 줄면 start 를 마지막 그룹으로 보정하고 범위 밖 페이지 버튼을 표시하지 않는다', () => {
39
47
  // 1) 100 페이지에서 91 페이지 보는 중 → 91~100 그룹 표시
@@ -56,4 +64,70 @@ describe('#332 Pagination — totalPage 축소 시 start 보정', () => {
56
64
  expect(nums[0]).toBe(GROUP_START_50_PAGES);
57
65
  expect(Math.max(...nums)).toBeLessThanOrEqual(LAST_PAGE_50);
58
66
  });
67
+ });
68
+ describe('Pagination — mo 모드 이전/다음 버튼 노출', () => {
69
+ it('페이지가 그룹 크기 이하여도 mo 에서는 이전·다음 버튼이 노출된다', () => {
70
+ // Given/When: 3페이지(그룹 크기 10 이하) 분량을 mo 로 렌더하면
71
+ const el = render({
72
+ totalCount: TOTAL_COUNT_3_PAGES,
73
+ itemCountPerPage: ITEM_COUNT_PER_PAGE,
74
+ pageCount: PAGE_GROUP_SIZE,
75
+ currentPage: 1,
76
+ breakPoint: 'mo'
77
+ });
78
+ // Then: mo 는 페이지 번호 목록이 CSS 로 숨겨지므로 이전·다음 버튼이 있어야 이동할 수 있다
79
+ expect(prevOf(el)).not.toBeNull();
80
+ expect(nextOf(el)).not.toBeNull();
81
+ });
82
+ it('첫 페이지에서는 이전 버튼이, 마지막 페이지에서는 다음 버튼이 비활성이다', () => {
83
+ // Given/When: 3페이지 중 첫 페이지를 mo 로 렌더하면
84
+ const first = render({
85
+ totalCount: TOTAL_COUNT_3_PAGES,
86
+ itemCountPerPage: ITEM_COUNT_PER_PAGE,
87
+ pageCount: PAGE_GROUP_SIZE,
88
+ currentPage: 1,
89
+ breakPoint: 'mo'
90
+ });
91
+ // Then: 이전만 막히고 다음은 누를 수 있다
92
+ expect(prevOf(first)?.disabled).toBe(true);
93
+ expect(nextOf(first)?.disabled).toBe(false);
94
+ // When: 마지막 페이지로 이동하면
95
+ const last = render({
96
+ totalCount: TOTAL_COUNT_3_PAGES,
97
+ itemCountPerPage: ITEM_COUNT_PER_PAGE,
98
+ pageCount: PAGE_GROUP_SIZE,
99
+ currentPage: LAST_PAGE_3,
100
+ breakPoint: 'mo'
101
+ });
102
+ // Then: 반대로 다음이 막힌다
103
+ expect(prevOf(last)?.disabled).toBe(false);
104
+ expect(nextOf(last)?.disabled).toBe(true);
105
+ });
106
+ it('페이지가 하나뿐이면 mo 에서도 이전·다음 버튼을 내보내지 않는다', () => {
107
+ // Given/When: 1페이지 분량을 mo 로 렌더하면
108
+ const el = render({
109
+ totalCount: TOTAL_COUNT_1_PAGE,
110
+ itemCountPerPage: ITEM_COUNT_PER_PAGE,
111
+ pageCount: PAGE_GROUP_SIZE,
112
+ currentPage: 1,
113
+ breakPoint: 'mo'
114
+ });
115
+ // Then: 이동할 곳이 없으므로 버튼도 없다
116
+ expect(prevOf(el)).toBeNull();
117
+ expect(nextOf(el)).toBeNull();
118
+ });
119
+ it('pc 는 기존대로 페이지 그룹을 넘길 때만 점프 버튼을 노출한다', () => {
120
+ // Given/When: 3페이지 분량을 pc 로 렌더하면
121
+ const el = render({
122
+ totalCount: TOTAL_COUNT_3_PAGES,
123
+ itemCountPerPage: ITEM_COUNT_PER_PAGE,
124
+ pageCount: PAGE_GROUP_SIZE,
125
+ currentPage: 1,
126
+ breakPoint: 'pc'
127
+ });
128
+ // Then: 페이지 번호로 직접 이동하므로 점프 버튼은 나오지 않는다
129
+ expect(prevOf(el)).toBeNull();
130
+ expect(nextOf(el)).toBeNull();
131
+ expect(pageNums(el)).toHaveLength(LAST_PAGE_3);
132
+ });
59
133
  });
@@ -1,16 +1,21 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import classNames from 'classnames';
3
3
  import { forwardRef } from 'react';
4
+ const WIDTH_CLASS = {
5
+ full: 'ncua-callout-notification--full',
6
+ fit: 'ncua-callout-notification--fit'
7
+ };
4
8
  const CalloutNotification = /*#__PURE__*/forwardRef((_ref, ref) => {
5
9
  let {
6
10
  color = 'neutral',
7
11
  className,
8
12
  title,
13
+ width,
9
14
  ...rest
10
15
  } = _ref;
11
16
  return _jsx("div", {
12
17
  ref: ref,
13
- className: classNames('ncua-callout-notification', `ncua-callout-notification--${color}`, className),
18
+ className: classNames('ncua-callout-notification', `ncua-callout-notification--${color}`, width && WIDTH_CLASS[width], className),
14
19
  ...rest,
15
20
  children: title
16
21
  });
@@ -4,10 +4,15 @@ import { CalloutNotification } from './CalloutNotification';
4
4
  import { FloatingNotification } from './FloatingNotification';
5
5
  import { FullWidthNotification } from './FullWidthNotification';
6
6
  import { MessageNotification } from './MessageNotification';
7
- const Notification = /*#__PURE__*/forwardRef((_ref, ref) => {
7
+ const Notification = /*#__PURE__*/forwardRef(
8
+ // 단일 type 에만 유효한 prop 은 rest 에서 분리해 해당 분기로만 명시 전달한다.
9
+ // rest 에 남기면 다른 type 의 하위 컴포넌트가 div 로 스프레드해 DOM 속성으로 출력된다.
10
+ (_ref, ref) => {
8
11
  let {
9
12
  type = 'floating',
10
13
  color = 'neutral',
14
+ width,
15
+ supportTextLink,
11
16
  ...rest
12
17
  } = _ref;
13
18
  if (type === 'floating') {
@@ -20,6 +25,7 @@ const Notification = /*#__PURE__*/forwardRef((_ref, ref) => {
20
25
  if (type === 'full-width') {
21
26
  return _jsx(FullWidthNotification, {
22
27
  color: color,
28
+ supportTextLink: supportTextLink,
23
29
  ...rest,
24
30
  ref: ref
25
31
  });
@@ -32,9 +38,23 @@ const Notification = /*#__PURE__*/forwardRef((_ref, ref) => {
32
38
  });
33
39
  }
34
40
  if (type === 'callout') {
41
+ // 나머지 3개 type 이 공유하는 prop 은 callout 이 지원하지 않으므로 여기서 제외한다.
42
+ const {
43
+ icon: _icon,
44
+ supportingText: _supportingText,
45
+ actions: _actions,
46
+ autoClose: _autoClose,
47
+ onClose: _onClose,
48
+ onHidePermanently: _onHidePermanently,
49
+ hidePermanentlyLabel: _hidePermanentlyLabel,
50
+ portal: _portal,
51
+ ...calloutProps
52
+ } = rest;
35
53
  return _jsx(CalloutNotification, {
36
54
  color: color,
37
- ...rest
55
+ width: width,
56
+ ...calloutProps,
57
+ ref: ref
38
58
  });
39
59
  }
40
60
  return null;
@@ -0,0 +1,125 @@
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, describe, expect, it } from 'vitest';
6
+ import { CalloutNotification } from '../CalloutNotification';
7
+ import { Notification } from '../Notification';
8
+ // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
9
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
10
+ const BASE = 'ncua-callout-notification';
11
+ let root = null;
12
+ let container = null;
13
+ const mount = element => {
14
+ container = document.createElement('div');
15
+ document.body.appendChild(container);
16
+ root = createRoot(container);
17
+ act(() => {
18
+ root?.render(element);
19
+ });
20
+ const rendered = container.firstElementChild;
21
+ if (!(rendered instanceof HTMLElement)) throw new Error('callout 이 렌더되지 않았다');
22
+ return rendered;
23
+ };
24
+ const renderCallout = function () {
25
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
+ return mount(/*#__PURE__*/createElement(CalloutNotification, {
27
+ title: '안내 문구',
28
+ ...props
29
+ }));
30
+ };
31
+ const renderNotification = function () {
32
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
33
+ return mount(/*#__PURE__*/createElement(Notification, {
34
+ type: 'callout',
35
+ title: '안내 문구',
36
+ ...props
37
+ }));
38
+ };
39
+ afterEach(() => {
40
+ act(() => {
41
+ root?.unmount();
42
+ });
43
+ container?.remove();
44
+ root = null;
45
+ container = null;
46
+ });
47
+ describe('CalloutNotification — width prop', () => {
48
+ it('width 미지정 시 너비 클래스를 붙이지 않는다 (부모 너비를 채우는 기본 스타일 유지)', () => {
49
+ const element = renderCallout();
50
+ expect(element.classList.contains('ncua-callout-notification--full')).toBe(false);
51
+ expect(element.classList.contains('ncua-callout-notification--fit')).toBe(false);
52
+ });
53
+ it("width='full' 은 --full modifier 를 붙인다", () => {
54
+ const element = renderCallout({
55
+ width: 'full'
56
+ });
57
+ expect(element.classList.contains('ncua-callout-notification--full')).toBe(true);
58
+ expect(element.classList.contains('ncua-callout-notification--fit')).toBe(false);
59
+ });
60
+ it("width='fit' 은 --fit modifier 를 붙인다", () => {
61
+ const element = renderCallout({
62
+ width: 'fit'
63
+ });
64
+ expect(element.classList.contains('ncua-callout-notification--fit')).toBe(true);
65
+ expect(element.classList.contains('ncua-callout-notification--full')).toBe(false);
66
+ });
67
+ it('width 는 DOM 속성으로 새지 않는다', () => {
68
+ const element = renderCallout({
69
+ width: 'fit'
70
+ });
71
+ expect(element.hasAttribute('width')).toBe(false);
72
+ });
73
+ it('width 는 베이스/컬러 클래스와 외부 className 을 유지한 채 추가된다', () => {
74
+ const element = renderCallout({
75
+ width: 'fit',
76
+ color: 'info',
77
+ className: 'custom'
78
+ });
79
+ expect(element.classList.contains(BASE)).toBe(true);
80
+ expect(element.classList.contains(`${BASE}--info`)).toBe(true);
81
+ expect(element.classList.contains('custom')).toBe(true);
82
+ });
83
+ });
84
+ describe('Notification type="callout" — 위임 계약', () => {
85
+ it('width 를 CalloutNotification 으로 전달한다', () => {
86
+ const element = renderNotification({
87
+ width: 'fit'
88
+ });
89
+ expect(element.classList.contains(BASE)).toBe(true);
90
+ expect(element.classList.contains('ncua-callout-notification--fit')).toBe(true);
91
+ });
92
+ // Notification 의 callout 분기가 제외하는 prop 전체. 여기 누락된 prop 은 DOM 속성으로 출력된다.
93
+ it('callout 이 지원하지 않는 prop 은 DOM 속성으로 새지 않는다', () => {
94
+ const element = renderNotification({
95
+ icon: () => null,
96
+ supportingText: '보조 문구',
97
+ supportTextLink: 'https://example.com',
98
+ actions: [{
99
+ label: '확인',
100
+ onClick: () => undefined
101
+ }],
102
+ autoClose: 3000,
103
+ portal: true,
104
+ onClose: () => undefined,
105
+ onHidePermanently: () => undefined,
106
+ hidePermanentlyLabel: '다시 보지 않기'
107
+ });
108
+ for (const attr of ['icon', 'supportingtext', 'supporttextlink', 'actions', 'autoclose', 'portal', 'onclose', 'onhidepermanently', 'hidepermanentlylabel']) {
109
+ expect(element.hasAttribute(attr), attr).toBe(false);
110
+ }
111
+ expect(element.textContent).toBe('안내 문구');
112
+ });
113
+ it('ref 를 callout 루트 엘리먼트로 전달한다', () => {
114
+ let captured = null;
115
+ mount(/*#__PURE__*/createElement(Notification, {
116
+ type: 'callout',
117
+ title: '안내 문구',
118
+ ref: node => {
119
+ captured = node;
120
+ }
121
+ }));
122
+ expect(captured).not.toBeNull();
123
+ expect(captured.classList.contains(BASE)).toBe(true);
124
+ });
125
+ });
@@ -0,0 +1,80 @@
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, beforeAll, describe, expect, it } from 'vitest';
6
+ import { Notification } from '../Notification';
7
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
8
+ let root = null;
9
+ let container = null;
10
+ beforeAll(() => {
11
+ // jsdom 미구현 API 보정 — FloatingNotification 의 모바일 리스너가 window.matchMedia 를 호출한다.
12
+ if (typeof window.matchMedia !== 'function') {
13
+ const stub = query => ({
14
+ matches: false,
15
+ media: query,
16
+ onchange: null,
17
+ addEventListener: () => undefined,
18
+ removeEventListener: () => undefined,
19
+ addListener: () => undefined,
20
+ removeListener: () => undefined,
21
+ dispatchEvent: () => false
22
+ });
23
+ window.matchMedia = stub;
24
+ }
25
+ });
26
+ // 정의되지 않은 type 의 런타임 동작까지 고정하므로 props 를 넓게 받는다.
27
+ const render = props => {
28
+ container = document.createElement('div');
29
+ document.body.appendChild(container);
30
+ root = createRoot(container);
31
+ act(() => {
32
+ root?.render(/*#__PURE__*/createElement(Notification, {
33
+ title: '안내 문구',
34
+ ...props
35
+ }));
36
+ });
37
+ const rendered = container.firstElementChild;
38
+ return rendered instanceof HTMLElement ? rendered : null;
39
+ };
40
+ afterEach(() => {
41
+ act(() => {
42
+ root?.unmount();
43
+ });
44
+ container?.remove();
45
+ root = null;
46
+ container = null;
47
+ });
48
+ describe('Notification — type 별 위임', () => {
49
+ it.each([['floating', 'ncua-floating-notification'], ['full-width', 'ncua-full-width-notification'], ['message', 'ncua-message-notification'], ['callout', 'ncua-callout-notification']])('type=%s 는 %s 를 렌더한다', (type, baseClass) => {
50
+ const element = render({
51
+ type
52
+ });
53
+ expect(element?.classList.contains(baseClass)).toBe(true);
54
+ });
55
+ it('type 미지정은 floating 으로 렌더한다', () => {
56
+ const element = render({});
57
+ expect(element?.classList.contains('ncua-floating-notification')).toBe(true);
58
+ });
59
+ it.each(['floating', 'full-width', 'message'])('type=%s 에 callout 전용 width 를 주어도 DOM 속성으로 새지 않는다', type => {
60
+ const element = render({
61
+ type,
62
+ width: 'fit'
63
+ });
64
+ expect(element?.hasAttribute('width')).toBe(false);
65
+ });
66
+ it.each(['floating', 'message'])('type=%s 에 full-width 전용 supportTextLink 를 주어도 DOM 속성으로 새지 않는다', type => {
67
+ const element = render({
68
+ type,
69
+ supportingText: '보조',
70
+ supportTextLink: 'https://example.com'
71
+ });
72
+ expect(element?.hasAttribute('supporttextlink')).toBe(false);
73
+ });
74
+ it('정의되지 않은 type 은 아무것도 렌더하지 않는다', () => {
75
+ const element = render({
76
+ type: 'banner'
77
+ });
78
+ expect(element).toBeNull();
79
+ });
80
+ });