@ncds/ui-admin 1.8.26-alpha.4 → 1.8.26-alpha.6

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 (95) hide show
  1. package/dist/cjs/assets/scripts/notification/FloatingNotification.js +23 -7
  2. package/dist/cjs/assets/scripts/notification/FullWidthNotification.js +14 -3
  3. package/dist/cjs/assets/scripts/notification/MessageNotification.js +9 -9
  4. package/dist/cjs/assets/scripts/notification/Notification.js +8 -2
  5. package/dist/cjs/assets/scripts/notification/const/icons.js +17 -8
  6. package/dist/cjs/assets/scripts/notification/const/index.js +6 -0
  7. package/dist/cjs/assets/scripts/notification/messageTemplate.js +21 -5
  8. package/dist/cjs/constant/notification.js +8 -3
  9. package/dist/cjs/src/components/overlays/notification/FloatingNotification.js +11 -29
  10. package/dist/cjs/src/components/overlays/notification/FullWidthNotification.js +9 -24
  11. package/dist/cjs/src/components/overlays/notification/MessageNotification.js +25 -9
  12. package/dist/cjs/src/components/overlays/notification/MessageNotificationParts.js +5 -2
  13. package/dist/cjs/src/components/overlays/notification/Notification.js +1 -0
  14. package/dist/cjs/src/components/overlays/notification/__tests__/CalloutNotification.test.js +8 -2
  15. package/dist/cjs/src/components/overlays/notification/__tests__/MessageNotification.test.js +55 -13
  16. package/dist/cjs/src/components/overlays/notification/__tests__/Notification.test.js +176 -0
  17. package/dist/cjs/src/components/overlays/notification/useAutoClose.js +39 -0
  18. package/dist/cjs/src/generated/scoped-css.js +1 -1
  19. package/dist/cjs/src/utils/notification/__tests__/resolveAutoClose.test.js +44 -0
  20. package/dist/cjs/src/utils/notification/index.js +12 -0
  21. package/dist/cjs/src/utils/notification/resolveAutoClose.js +22 -0
  22. package/dist/esm/assets/scripts/notification/FloatingNotification.js +23 -7
  23. package/dist/esm/assets/scripts/notification/FullWidthNotification.js +14 -3
  24. package/dist/esm/assets/scripts/notification/MessageNotification.js +10 -10
  25. package/dist/esm/assets/scripts/notification/Notification.js +8 -2
  26. package/dist/esm/assets/scripts/notification/const/icons.js +16 -7
  27. package/dist/esm/assets/scripts/notification/const/index.js +1 -1
  28. package/dist/esm/assets/scripts/notification/messageTemplate.js +21 -5
  29. package/dist/esm/constant/notification.js +7 -2
  30. package/dist/esm/src/components/overlays/notification/FloatingNotification.js +12 -30
  31. package/dist/esm/src/components/overlays/notification/FullWidthNotification.js +10 -25
  32. package/dist/esm/src/components/overlays/notification/MessageNotification.js +25 -9
  33. package/dist/esm/src/components/overlays/notification/MessageNotificationParts.js +5 -2
  34. package/dist/esm/src/components/overlays/notification/Notification.js +1 -0
  35. package/dist/esm/src/components/overlays/notification/__tests__/CalloutNotification.test.js +9 -3
  36. package/dist/esm/src/components/overlays/notification/__tests__/MessageNotification.test.js +55 -13
  37. package/dist/esm/src/components/overlays/notification/__tests__/Notification.test.js +177 -1
  38. package/dist/esm/src/components/overlays/notification/useAutoClose.js +32 -0
  39. package/dist/esm/src/generated/scoped-css.js +1 -1
  40. package/dist/esm/src/utils/notification/__tests__/resolveAutoClose.test.js +42 -0
  41. package/dist/esm/src/utils/notification/index.js +1 -0
  42. package/dist/esm/src/utils/notification/resolveAutoClose.js +15 -0
  43. package/dist/temp/assets/scripts/notification/FloatingNotification.js +10 -6
  44. package/dist/temp/assets/scripts/notification/FullWidthNotification.js +8 -5
  45. package/dist/temp/assets/scripts/notification/MessageNotification.d.ts +1 -1
  46. package/dist/temp/assets/scripts/notification/MessageNotification.js +10 -12
  47. package/dist/temp/assets/scripts/notification/Notification.js +7 -1
  48. package/dist/temp/assets/scripts/notification/const/icons.d.ts +6 -6
  49. package/dist/temp/assets/scripts/notification/const/icons.js +16 -7
  50. package/dist/temp/assets/scripts/notification/const/index.d.ts +1 -1
  51. package/dist/temp/assets/scripts/notification/const/index.js +1 -1
  52. package/dist/temp/assets/scripts/notification/const/types.d.ts +8 -1
  53. package/dist/temp/assets/scripts/notification/messageTemplate.d.ts +1 -0
  54. package/dist/temp/assets/scripts/notification/messageTemplate.js +19 -9
  55. package/dist/temp/constant/notification.d.ts +6 -1
  56. package/dist/temp/constant/notification.js +6 -1
  57. package/dist/temp/src/components/overlays/notification/FloatingNotification.d.ts +8 -0
  58. package/dist/temp/src/components/overlays/notification/FloatingNotification.js +7 -30
  59. package/dist/temp/src/components/overlays/notification/FullWidthNotification.d.ts +7 -0
  60. package/dist/temp/src/components/overlays/notification/FullWidthNotification.js +6 -25
  61. package/dist/temp/src/components/overlays/notification/MessageNotification.d.ts +13 -1
  62. package/dist/temp/src/components/overlays/notification/MessageNotification.js +16 -9
  63. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.d.ts +2 -1
  64. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.js +5 -3
  65. package/dist/temp/src/components/overlays/notification/Notification.d.ts +16 -3
  66. package/dist/temp/src/components/overlays/notification/Notification.js +1 -1
  67. package/dist/temp/src/components/overlays/notification/__tests__/CalloutNotification.test.js +8 -1
  68. package/dist/temp/src/components/overlays/notification/__tests__/MessageNotification.test.js +44 -9
  69. package/dist/temp/src/components/overlays/notification/__tests__/Notification.test.js +128 -1
  70. package/dist/temp/src/components/overlays/notification/useAutoClose.d.ts +15 -0
  71. package/dist/temp/src/components/overlays/notification/useAutoClose.js +25 -0
  72. package/dist/temp/src/generated/scoped-css.js +1 -1
  73. package/dist/temp/src/utils/notification/__tests__/resolveAutoClose.test.d.ts +1 -0
  74. package/dist/temp/src/utils/notification/__tests__/resolveAutoClose.test.js +22 -0
  75. package/dist/temp/src/utils/notification/index.d.ts +1 -0
  76. package/dist/temp/src/utils/notification/index.js +1 -0
  77. package/dist/temp/src/utils/notification/resolveAutoClose.d.ts +14 -0
  78. package/dist/temp/src/utils/notification/resolveAutoClose.js +12 -0
  79. package/dist/types/assets/scripts/notification/MessageNotification.d.ts +1 -1
  80. package/dist/types/assets/scripts/notification/const/icons.d.ts +6 -6
  81. package/dist/types/assets/scripts/notification/const/index.d.ts +1 -1
  82. package/dist/types/assets/scripts/notification/const/types.d.ts +8 -1
  83. package/dist/types/assets/scripts/notification/messageTemplate.d.ts +1 -0
  84. package/dist/types/constant/notification.d.ts +6 -1
  85. package/dist/types/src/components/overlays/notification/FloatingNotification.d.ts +8 -0
  86. package/dist/types/src/components/overlays/notification/FullWidthNotification.d.ts +7 -0
  87. package/dist/types/src/components/overlays/notification/MessageNotification.d.ts +13 -1
  88. package/dist/types/src/components/overlays/notification/MessageNotificationParts.d.ts +2 -1
  89. package/dist/types/src/components/overlays/notification/Notification.d.ts +16 -3
  90. package/dist/types/src/components/overlays/notification/useAutoClose.d.ts +15 -0
  91. package/dist/types/src/utils/notification/__tests__/resolveAutoClose.test.d.ts +1 -0
  92. package/dist/types/src/utils/notification/index.d.ts +1 -0
  93. package/dist/types/src/utils/notification/resolveAutoClose.d.ts +14 -0
  94. package/dist/ui-admin/assets/styles/style.css +17 -11
  95. package/package.json +1 -1
@@ -46,6 +46,7 @@ const renderNotification = function () {
46
46
  container?.remove();
47
47
  root = null;
48
48
  container = null;
49
+ _vitest.vi.restoreAllMocks();
49
50
  });
50
51
  (0, _vitest.describe)('CalloutNotification — width prop', () => {
51
52
  (0, _vitest.it)('width 미지정 시 너비 클래스를 붙이지 않는다 (부모 너비를 채우는 기본 스타일 유지)', () => {
@@ -94,6 +95,7 @@ const renderNotification = function () {
94
95
  });
95
96
  // Notification 의 callout 분기가 제외하는 prop 전체. 여기 누락된 prop 은 DOM 속성으로 출력된다.
96
97
  (0, _vitest.it)('callout 이 지원하지 않는 prop 은 DOM 속성으로 새지 않는다', () => {
98
+ const consoleError = _vitest.vi.spyOn(console, 'error').mockImplementation(() => undefined);
97
99
  const element = renderNotification({
98
100
  icon: () => null,
99
101
  supportingText: '보조 문구',
@@ -106,12 +108,16 @@ const renderNotification = function () {
106
108
  portal: true,
107
109
  onClose: () => undefined,
108
110
  onHidePermanently: () => undefined,
109
- hidePermanentlyLabel: '다시 보지 않기'
111
+ hidePermanentlyLabel: '다시 보지 않기',
112
+ hideCloseButton: true
110
113
  });
111
- for (const attr of ['icon', 'supportingtext', 'supporttextlink', 'actions', 'autoclose', 'portal', 'onclose', 'onhidepermanently', 'hidepermanentlylabel']) {
114
+ for (const attr of ['icon', 'supportingtext', 'supporttextlink', 'actions', 'autoclose', 'portal', 'onclose', 'onhidepermanently', 'hidepermanentlylabel', 'hideclosebutton']) {
112
115
  (0, _vitest.expect)(element.hasAttribute(attr), attr).toBe(false);
113
116
  }
114
117
  (0, _vitest.expect)(element.textContent).toBe('안내 문구');
118
+ // 불리언 true 는 React 가 미지 속성으로 출력하지 않아 hasAttribute 로는 누수를 못 잡는다 — 경고 로그로 검출한다.
119
+ const leaked = consoleError.mock.calls.some(call => call.some(arg => String(arg).includes('hideCloseButton')));
120
+ (0, _vitest.expect)(leaked).toBe(false);
115
121
  });
116
122
  (0, _vitest.it)('ref 를 callout 루트 엘리먼트로 전달한다', () => {
117
123
  let captured = null;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _uiAdminIcon = require("@ncds/ui-admin-icon");
3
4
  var _react = require("react");
4
5
  var _client = require("react-dom/client");
5
6
  var _testUtils = require("react-dom/test-utils");
@@ -21,16 +22,12 @@ const SELECTOR = {
21
22
  CLOSE_BUTTON: '.ncua-message-notification__close-button'
22
23
  };
23
24
  const mounted = [];
24
- function renderMessageNotification() {
25
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
+ function mount(element) {
26
26
  const container = document.createElement('div');
27
27
  document.body.appendChild(container);
28
28
  const root = (0, _client.createRoot)(container);
29
29
  (0, _testUtils.act)(() => {
30
- root.render(/*#__PURE__*/(0, _react.createElement)(_MessageNotification.MessageNotification, {
31
- title: '알림 제목',
32
- ...props
33
- }));
30
+ root.render(element);
34
31
  });
35
32
  mounted.push({
36
33
  root,
@@ -38,6 +35,20 @@ function renderMessageNotification() {
38
35
  });
39
36
  return container;
40
37
  }
38
+ function renderMessageNotification() {
39
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
40
+ return mount(/*#__PURE__*/(0, _react.createElement)(_MessageNotification.MessageNotification, {
41
+ title: '알림 제목',
42
+ ...props
43
+ }));
44
+ }
45
+ /** 아이콘 컴포넌트를 단독 렌더해 `path[d]` 를 얻는다. 아이콘 판정은 d 비교로 한다. */
46
+ function iconPathD(Icon) {
47
+ return mount(/*#__PURE__*/(0, _react.createElement)(Icon)).querySelector('path')?.getAttribute('d') ?? null;
48
+ }
49
+ function renderedIconPathD(container) {
50
+ return container.querySelector(`${SELECTOR.ICON} svg path`)?.getAttribute('d') ?? null;
51
+ }
41
52
  (0, _vitest.afterEach)(() => {
42
53
  for (const {
43
54
  root,
@@ -146,17 +157,48 @@ function renderMessageNotification() {
146
157
  (0, _vitest.expect)(hideLink?.className.split(' ').filter(Boolean).sort()).toEqual(['ncua-message-notification__hide-link', 'ncua-notification__action-button']);
147
158
  });
148
159
  });
149
- (0, _vitest.describe)('MessageNotification (React) — 공개 API 회귀 방지', () => {
150
- (0, _vitest.it)('지원하지 않는 color("info")는 neutral로 폴백한다', () => {
151
- // Given/When: message 타입이 지원하지 않는 info 색상을 넘기면
160
+ (0, _vitest.describe)('MessageNotification (React) — color="info" (#568)', () => {
161
+ (0, _vitest.it)('R-01: color="info" 는 neutral 로 폴백하지 않고 --info 수식자로 렌더한다', () => {
162
+ // Given/When: variant 미지정, info 색상으로 렌더하면
163
+ const root = renderMessageNotification({
164
+ color: 'info'
165
+ }).querySelector(SELECTOR.ROOT);
166
+ // Then: info 수식자가 있고 neutral 수식자는 없다
167
+ (0, _vitest.expect)(root?.classList.contains('ncua-message-notification--info')).toBe(true);
168
+ (0, _vitest.expect)(root?.classList.contains('ncua-message-notification--neutral')).toBe(false);
169
+ });
170
+ (0, _vitest.it)('R-02: 기본 info 아이콘은 neutral 과 같은 Pin02 다', () => {
171
+ // Given/When: variant 미지정, info 색상으로 렌더하면
152
172
  const container = renderMessageNotification({
153
173
  color: 'info'
154
174
  });
155
- // Then: neutral 수식자로 렌더되고 info 수식자는 없다
156
- const root = container.querySelector(SELECTOR.ROOT);
157
- (0, _vitest.expect)(root?.classList.contains('ncua-message-notification--neutral')).toBe(true);
158
- (0, _vitest.expect)(root?.classList.contains('ncua-message-notification--info')).toBe(false);
175
+ // Then: 아이콘 path 가 Pin02 와 같다
176
+ const expected = iconPathD(_uiAdminIcon.Pin02);
177
+ (0, _vitest.expect)(expected).not.toBeNull();
178
+ (0, _vitest.expect)(renderedIconPathD(container)).toBe(expected);
159
179
  });
180
+ (0, _vitest.it)('R-03: info 의 FeaturedIcon 은 neutral·md 로 렌더한다 (violet 톤은 SCSS 가 덮는다)', () => {
181
+ // Given/When: variant 미지정, info 색상으로 렌더하면
182
+ const icon = renderMessageNotification({
183
+ color: 'info'
184
+ }).querySelector(SELECTOR.ICON);
185
+ // Then: FeaturedIcon 에는 info 색이 없으므로 neutral 수식자와 md 사이즈가 유지된다
186
+ (0, _vitest.expect)(icon?.classList.contains('ncua-featured-icon--neutral')).toBe(true);
187
+ (0, _vitest.expect)(icon?.classList.contains('ncua-featured-icon--md')).toBe(true);
188
+ });
189
+ (0, _vitest.it)('R-04: block 의 info 아이콘은 InfoCircle 을 유지한다', () => {
190
+ // Given/When: block 변형에 info 색상으로 렌더하면
191
+ const container = renderMessageNotification({
192
+ variant: 'block',
193
+ color: 'info'
194
+ });
195
+ // Then: 아이콘 path 가 InfoCircle 과 같다 (#536 회귀)
196
+ const expected = iconPathD(_uiAdminIcon.InfoCircle);
197
+ (0, _vitest.expect)(expected).not.toBeNull();
198
+ (0, _vitest.expect)(renderedIconPathD(container)).toBe(expected);
199
+ });
200
+ });
201
+ (0, _vitest.describe)('MessageNotification (React) — 공개 API 회귀 방지', () => {
160
202
  (0, _vitest.it)('닫기/다시 보지 않기 클릭 시 핸들러가 호출되고 접근성 속성이 유지된다', () => {
161
203
  // Given: 핸들러를 지정해 렌더하고
162
204
  const onClose = _vitest.vi.fn();
@@ -4,6 +4,7 @@ var _react = require("react");
4
4
  var _client = require("react-dom/client");
5
5
  var _testUtils = require("react-dom/test-utils");
6
6
  var _vitest = require("vitest");
7
+ var _notification = require("../../../../../constant/notification");
7
8
  var _Notification = require("../Notification");
8
9
  // @vitest-environment jsdom
9
10
 
@@ -80,4 +81,179 @@ const render = props => {
80
81
  });
81
82
  (0, _vitest.expect)(element).toBeNull();
82
83
  });
84
+ });
85
+ const CLOSE_BUTTON = {
86
+ floating: '.ncua-floating-notification__close-button',
87
+ 'full-width': '.ncua-full-width-notification__close-button',
88
+ message: '.ncua-message-notification__close-button'
89
+ };
90
+ const MESSAGE_FOOTER = '.ncua-message-notification__footer-container';
91
+ const MESSAGE_HIDE_LINK = '.ncua-message-notification__hide-link';
92
+ /** DES-SPEC-027 §5.3 성공 토스트 자동 닫힘 시간. */
93
+ const AUTO_CLOSE_MS = 3000;
94
+ (0, _vitest.describe)('Notification — hideCloseButton', () => {
95
+ (0, _vitest.afterEach)(() => {
96
+ _vitest.vi.useRealTimers();
97
+ });
98
+ (0, _vitest.it)('R-01: floating — onClose 가 있어도 hideCloseButton 이면 닫기 버튼을 렌더하지 않는다', () => {
99
+ const element = render({
100
+ type: 'floating',
101
+ onClose: _vitest.vi.fn(),
102
+ hideCloseButton: true
103
+ });
104
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON.floating)).toBeNull();
105
+ });
106
+ (0, _vitest.it)('R-02: full-width — onClose 가 있어도 hideCloseButton 이면 닫기 버튼을 렌더하지 않는다', () => {
107
+ const element = render({
108
+ type: 'full-width',
109
+ onClose: _vitest.vi.fn(),
110
+ hideCloseButton: true
111
+ });
112
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON['full-width'])).toBeNull();
113
+ });
114
+ (0, _vitest.it)('R-03: message — hideCloseButton 이면 닫기 버튼과 빈 footer 컨테이너를 모두 렌더하지 않는다', () => {
115
+ const element = render({
116
+ type: 'message',
117
+ onClose: _vitest.vi.fn(),
118
+ hideCloseButton: true
119
+ });
120
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON.message)).toBeNull();
121
+ (0, _vitest.expect)(element?.querySelector(MESSAGE_FOOTER)).toBeNull();
122
+ });
123
+ _vitest.it.each(['floating', 'full-width', 'message'])('R-04: type=%s — hideCloseButton 미지정(기본 false)이면 onClose 만으로 닫기 버튼을 렌더한다', type => {
124
+ const element = render({
125
+ type,
126
+ onClose: _vitest.vi.fn()
127
+ });
128
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON[type])).not.toBeNull();
129
+ });
130
+ _vitest.it.each(['floating', 'full-width', 'message'])('R-05: type=%s — onClose 없이 hideCloseButton 만 주면 닫기 버튼 없이 오류 없이 렌더한다', type => {
131
+ const element = render({
132
+ type,
133
+ hideCloseButton: true
134
+ });
135
+ (0, _vitest.expect)(element).not.toBeNull();
136
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON[type])).toBeNull();
137
+ });
138
+ (0, _vitest.it)('R-06: floating — hideCloseButton 이어도 autoClose 만료 시 onClose 가 1회 호출되고 DOM 에서 제거된다', () => {
139
+ _vitest.vi.useFakeTimers();
140
+ const onClose = _vitest.vi.fn();
141
+ render({
142
+ type: 'floating',
143
+ autoClose: AUTO_CLOSE_MS,
144
+ hideCloseButton: true,
145
+ onClose
146
+ });
147
+ (0, _testUtils.act)(() => {
148
+ _vitest.vi.advanceTimersByTime(AUTO_CLOSE_MS);
149
+ });
150
+ (0, _vitest.expect)(onClose).toHaveBeenCalledTimes(1);
151
+ (0, _vitest.expect)(container?.querySelector('.ncua-floating-notification')).toBeNull();
152
+ });
153
+ (0, _vitest.it)('R-07: full-width — hideCloseButton 이어도 autoClose 만료 시 onClose 가 1회 호출되고 DOM 에서 제거된다', () => {
154
+ _vitest.vi.useFakeTimers();
155
+ const onClose = _vitest.vi.fn();
156
+ render({
157
+ type: 'full-width',
158
+ autoClose: AUTO_CLOSE_MS,
159
+ hideCloseButton: true,
160
+ onClose
161
+ });
162
+ (0, _testUtils.act)(() => {
163
+ _vitest.vi.advanceTimersByTime(AUTO_CLOSE_MS);
164
+ });
165
+ (0, _vitest.expect)(onClose).toHaveBeenCalledTimes(1);
166
+ (0, _vitest.expect)(container?.querySelector('.ncua-full-width-notification')).toBeNull();
167
+ });
168
+ (0, _vitest.it)('R-09: message — hideCloseButton + onHidePermanently 이면 footer 에 다시 보지 않기만 렌더한다', () => {
169
+ const element = render({
170
+ type: 'message',
171
+ onClose: _vitest.vi.fn(),
172
+ hideCloseButton: true,
173
+ onHidePermanently: _vitest.vi.fn()
174
+ });
175
+ (0, _vitest.expect)(element?.querySelector(MESSAGE_FOOTER)).not.toBeNull();
176
+ (0, _vitest.expect)(element?.querySelector(MESSAGE_HIDE_LINK)).not.toBeNull();
177
+ (0, _vitest.expect)(element?.querySelector(CLOSE_BUTTON.message)).toBeNull();
178
+ });
179
+ (0, _vitest.it)('R-10: message — hideCloseButton 이어도 autoClose 만료 시 onClose 가 1회 호출되고 DOM 에서 제거된다', () => {
180
+ _vitest.vi.useFakeTimers();
181
+ const onClose = _vitest.vi.fn();
182
+ render({
183
+ type: 'message',
184
+ autoClose: AUTO_CLOSE_MS,
185
+ hideCloseButton: true,
186
+ onClose
187
+ });
188
+ (0, _testUtils.act)(() => {
189
+ _vitest.vi.advanceTimersByTime(AUTO_CLOSE_MS);
190
+ });
191
+ (0, _vitest.expect)(onClose).toHaveBeenCalledTimes(1);
192
+ (0, _vitest.expect)(container?.querySelector('.ncua-message-notification')).toBeNull();
193
+ });
194
+ });
195
+ (0, _vitest.describe)('Notification — hideCloseButton 기본 autoClose', () => {
196
+ (0, _vitest.afterEach)(() => {
197
+ _vitest.vi.useRealTimers();
198
+ });
199
+ (0, _vitest.it)('R-11: floating — hideCloseButton 만 주고 autoClose 를 생략하면 3초 뒤 onClose 가 호출되고 제거된다', () => {
200
+ _vitest.vi.useFakeTimers();
201
+ const onClose = _vitest.vi.fn();
202
+ render({
203
+ type: 'floating',
204
+ hideCloseButton: true,
205
+ onClose
206
+ });
207
+ (0, _testUtils.act)(() => {
208
+ _vitest.vi.advanceTimersByTime(_notification.HIDE_CLOSE_BUTTON_AUTO_CLOSE_MS - 1);
209
+ });
210
+ (0, _vitest.expect)(onClose).not.toHaveBeenCalled();
211
+ (0, _testUtils.act)(() => {
212
+ _vitest.vi.advanceTimersByTime(1);
213
+ });
214
+ (0, _vitest.expect)(onClose).toHaveBeenCalledTimes(1);
215
+ (0, _vitest.expect)(container?.firstElementChild).toBeNull();
216
+ });
217
+ _vitest.it.each(['full-width', 'message'])('R-14: type=%s — hideCloseButton 만 주고 autoClose 를 생략해도 자동으로 닫히지 않는다 (부모 언마운트 용도)', type => {
218
+ _vitest.vi.useFakeTimers();
219
+ const onClose = _vitest.vi.fn();
220
+ render({
221
+ type,
222
+ hideCloseButton: true,
223
+ onClose
224
+ });
225
+ (0, _testUtils.act)(() => {
226
+ _vitest.vi.advanceTimersByTime(_notification.HIDE_CLOSE_BUTTON_AUTO_CLOSE_MS * 2);
227
+ });
228
+ (0, _vitest.expect)(onClose).not.toHaveBeenCalled();
229
+ (0, _vitest.expect)(container?.firstElementChild).not.toBeNull();
230
+ });
231
+ (0, _vitest.it)('R-12: floating — hideCloseButton + autoClose={0} 을 명시하면 자동으로 닫히지 않는다 (부모 언마운트 용도)', () => {
232
+ _vitest.vi.useFakeTimers();
233
+ const onClose = _vitest.vi.fn();
234
+ render({
235
+ type: 'floating',
236
+ hideCloseButton: true,
237
+ autoClose: 0,
238
+ onClose
239
+ });
240
+ (0, _testUtils.act)(() => {
241
+ _vitest.vi.advanceTimersByTime(_notification.HIDE_CLOSE_BUTTON_AUTO_CLOSE_MS * 2);
242
+ });
243
+ (0, _vitest.expect)(onClose).not.toHaveBeenCalled();
244
+ (0, _vitest.expect)(container?.querySelector('.ncua-floating-notification')).not.toBeNull();
245
+ });
246
+ (0, _vitest.it)('R-13: floating — hideCloseButton 이 아니면 autoClose 생략 시 기본 자동 닫힘이 없다 (회귀)', () => {
247
+ _vitest.vi.useFakeTimers();
248
+ const onClose = _vitest.vi.fn();
249
+ render({
250
+ type: 'floating',
251
+ onClose
252
+ });
253
+ (0, _testUtils.act)(() => {
254
+ _vitest.vi.advanceTimersByTime(_notification.HIDE_CLOSE_BUTTON_AUTO_CLOSE_MS * 2);
255
+ });
256
+ (0, _vitest.expect)(onClose).not.toHaveBeenCalled();
257
+ (0, _vitest.expect)(container?.querySelector('.ncua-floating-notification')).not.toBeNull();
258
+ });
83
259
  });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAutoClose = void 0;
7
+ var _react = require("react");
8
+ var _notification = require("../../../utils/notification");
9
+ /**
10
+ * autoClose 타이머. 만료 시 `onClose`를 호출하고 `true`(제거됨)를 반환한다.
11
+ * floating · full-width · message 가 공유한다.
12
+ *
13
+ * `onClose`는 매 렌더 새 함수일 수 있어 ref 로 latest 만 보관하고 deps 에서 뺀다 —
14
+ * 인라인 핸들러를 넘겨도 부모 리렌더마다 타이머가 리셋되지 않는다.
15
+ */
16
+ const useAutoClose = _ref => {
17
+ let {
18
+ autoClose,
19
+ hideCloseButton,
20
+ onClose
21
+ } = _ref;
22
+ const [shouldRemove, setShouldRemove] = (0, _react.useState)(false);
23
+ const onCloseRef = (0, _react.useRef)(onClose);
24
+ onCloseRef.current = onClose;
25
+ const autoCloseMs = (0, _notification.resolveAutoClose)({
26
+ autoClose,
27
+ hideCloseButton
28
+ });
29
+ (0, _react.useEffect)(() => {
30
+ if (autoCloseMs <= 0) return;
31
+ const timer = setTimeout(() => {
32
+ onCloseRef.current?.();
33
+ setShouldRemove(true);
34
+ }, autoCloseMs);
35
+ return () => clearTimeout(timer);
36
+ }, [autoCloseMs]);
37
+ return shouldRemove;
38
+ };
39
+ exports.useAutoClose = useAutoClose;