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

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 (53) hide show
  1. package/dist/cjs/assets/scripts/notification/MessageNotification.js +6 -46
  2. package/dist/cjs/assets/scripts/notification/const/classNames.js +3 -0
  3. package/dist/cjs/assets/scripts/notification/const/index.js +1 -1
  4. package/dist/cjs/assets/scripts/notification/const/sizes.js +4 -2
  5. package/dist/cjs/assets/scripts/notification/messageTemplate.js +77 -0
  6. package/dist/cjs/assets/scripts/notification/utils.js +40 -4
  7. package/dist/cjs/src/components/overlays/notification/MessageNotification.js +12 -54
  8. package/dist/cjs/src/components/overlays/notification/MessageNotificationParts.js +90 -0
  9. package/dist/cjs/src/components/overlays/notification/__tests__/MessageNotification.test.js +246 -0
  10. package/dist/cjs/src/generated/scoped-css.js +1 -1
  11. package/dist/esm/assets/scripts/notification/MessageNotification.js +8 -48
  12. package/dist/esm/assets/scripts/notification/const/classNames.js +3 -0
  13. package/dist/esm/assets/scripts/notification/const/index.js +3 -2
  14. package/dist/esm/assets/scripts/notification/const/sizes.js +4 -2
  15. package/dist/esm/assets/scripts/notification/messageTemplate.js +71 -0
  16. package/dist/esm/assets/scripts/notification/utils.js +39 -4
  17. package/dist/esm/src/components/overlays/notification/MessageNotification.js +13 -55
  18. package/dist/esm/src/components/overlays/notification/MessageNotificationParts.js +83 -0
  19. package/dist/esm/src/components/overlays/notification/__tests__/MessageNotification.test.js +243 -0
  20. package/dist/esm/src/generated/scoped-css.js +1 -1
  21. package/dist/temp/assets/scripts/notification/MessageNotification.d.ts +0 -3
  22. package/dist/temp/assets/scripts/notification/MessageNotification.js +7 -43
  23. package/dist/temp/assets/scripts/notification/const/classNames.d.ts +1 -0
  24. package/dist/temp/assets/scripts/notification/const/classNames.js +3 -0
  25. package/dist/temp/assets/scripts/notification/const/index.d.ts +3 -3
  26. package/dist/temp/assets/scripts/notification/const/index.js +3 -2
  27. package/dist/temp/assets/scripts/notification/const/sizes.d.ts +2 -2
  28. package/dist/temp/assets/scripts/notification/const/sizes.js +4 -2
  29. package/dist/temp/assets/scripts/notification/const/types.d.ts +20 -2
  30. package/dist/temp/assets/scripts/notification/messageTemplate.d.ts +14 -0
  31. package/dist/temp/assets/scripts/notification/messageTemplate.js +69 -0
  32. package/dist/temp/assets/scripts/notification/utils.d.ts +19 -2
  33. package/dist/temp/assets/scripts/notification/utils.js +39 -5
  34. package/dist/temp/src/components/overlays/notification/MessageNotification.js +3 -12
  35. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.d.ts +27 -0
  36. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.js +27 -0
  37. package/dist/temp/src/components/overlays/notification/Notification.d.ts +3 -2
  38. package/dist/temp/src/components/overlays/notification/__tests__/MessageNotification.test.d.ts +1 -0
  39. package/dist/temp/src/components/overlays/notification/__tests__/MessageNotification.test.js +190 -0
  40. package/dist/temp/src/generated/scoped-css.js +1 -1
  41. package/dist/types/assets/scripts/notification/MessageNotification.d.ts +0 -3
  42. package/dist/types/assets/scripts/notification/const/classNames.d.ts +1 -0
  43. package/dist/types/assets/scripts/notification/const/index.d.ts +3 -3
  44. package/dist/types/assets/scripts/notification/const/sizes.d.ts +2 -2
  45. package/dist/types/assets/scripts/notification/const/types.d.ts +20 -2
  46. package/dist/types/assets/scripts/notification/messageTemplate.d.ts +14 -0
  47. package/dist/types/assets/scripts/notification/utils.d.ts +19 -2
  48. package/dist/types/src/components/overlays/notification/MessageNotificationParts.d.ts +27 -0
  49. package/dist/types/src/components/overlays/notification/Notification.d.ts +3 -2
  50. package/dist/types/src/components/overlays/notification/__tests__/MessageNotification.test.d.ts +1 -0
  51. package/dist/ui-admin/assets/styles/style.css +20 -21
  52. package/dist/ui-admin/assets/styles/style.scoped.css +20 -21
  53. package/package.json +1 -1
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+
3
+ var _react = require("react");
4
+ var _client = require("react-dom/client");
5
+ var _testUtils = require("react-dom/test-utils");
6
+ var _vitest = require("vitest");
7
+ var _MessageNotification = require("../MessageNotification");
8
+ // @vitest-environment jsdom
9
+
10
+ // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
11
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
12
+ const SELECTOR = {
13
+ ROOT: '.ncua-message-notification',
14
+ CONTENT: '.ncua-message-notification__content',
15
+ CONTENT_WRAPPER: '.ncua-message-notification__content-wrapper',
16
+ ICON: '.ncua-message-notification__icon',
17
+ ACTIONS_CONTAINER: '.ncua-message-notification__actions-container',
18
+ ACTIONS: '.ncua-message-notification__actions',
19
+ FOOTER_CONTAINER: '.ncua-message-notification__footer-container',
20
+ HIDE_LINK: '.ncua-message-notification__hide-link',
21
+ CLOSE_BUTTON: '.ncua-message-notification__close-button'
22
+ };
23
+ const mounted = [];
24
+ function renderMessageNotification() {
25
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
+ const container = document.createElement('div');
27
+ document.body.appendChild(container);
28
+ const root = (0, _client.createRoot)(container);
29
+ (0, _testUtils.act)(() => {
30
+ root.render(/*#__PURE__*/(0, _react.createElement)(_MessageNotification.MessageNotification, {
31
+ title: '알림 제목',
32
+ ...props
33
+ }));
34
+ });
35
+ mounted.push({
36
+ root,
37
+ container
38
+ });
39
+ return container;
40
+ }
41
+ (0, _vitest.afterEach)(() => {
42
+ for (const {
43
+ root,
44
+ container
45
+ } of mounted.splice(0)) {
46
+ (0, _testUtils.act)(() => {
47
+ root.unmount();
48
+ });
49
+ container.remove();
50
+ }
51
+ });
52
+ (0, _vitest.describe)('MessageNotification (React) — DOM 구조 계약', () => {
53
+ (0, _vitest.it)('U-1: __footer-container가 __actions-container의 자식으로 렌더된다', () => {
54
+ // Given: 다시 보지 않기·닫기 핸들러가 주어지고
55
+ // When: MessageNotification을 렌더하면
56
+ const container = renderMessageNotification({
57
+ onHidePermanently: _vitest.vi.fn(),
58
+ onClose: _vitest.vi.fn()
59
+ });
60
+ // Then: footer-container는 actions-container의 직계 자식이다 (content의 직계 자식이 아니다)
61
+ const actionsContainer = container.querySelector(SELECTOR.ACTIONS_CONTAINER);
62
+ const footerContainer = container.querySelector(SELECTOR.FOOTER_CONTAINER);
63
+ (0, _vitest.expect)(actionsContainer).not.toBeNull();
64
+ (0, _vitest.expect)(footerContainer).not.toBeNull();
65
+ (0, _vitest.expect)(footerContainer?.parentElement).toBe(actionsContainer);
66
+ });
67
+ (0, _vitest.it)('U-2: actions 지정 시 __actions와 __footer-container가 __actions-container 안에 순서대로 공존한다', () => {
68
+ // Given: 액션 버튼 2개와 다시 보지 않기·닫기 핸들러가 주어지고
69
+ const actions = [{
70
+ label: '조회하기',
71
+ hierarchy: 'text',
72
+ onClick: _vitest.vi.fn()
73
+ }, {
74
+ label: '포인트 충전',
75
+ hierarchy: 'text-gray',
76
+ onClick: _vitest.vi.fn()
77
+ }];
78
+ // When: 렌더하면
79
+ const container = renderMessageNotification({
80
+ actions,
81
+ onHidePermanently: _vitest.vi.fn(),
82
+ onClose: _vitest.vi.fn()
83
+ });
84
+ // Then: actions-container의 자식은 [actions, footer-container] 순서다
85
+ const actionsContainer = container.querySelector(SELECTOR.ACTIONS_CONTAINER);
86
+ const actionsGroup = container.querySelector(SELECTOR.ACTIONS);
87
+ const footerContainer = container.querySelector(SELECTOR.FOOTER_CONTAINER);
88
+ (0, _vitest.expect)(actionsContainer).not.toBeNull();
89
+ (0, _vitest.expect)(Array.from(actionsContainer?.children ?? [])).toEqual([actionsGroup, footerContainer]);
90
+ });
91
+ (0, _vitest.it)('U-3: onHidePermanently·onClose·actions 미지정 시 빈 컨테이너가 남지 않는다', () => {
92
+ // Given/When: 우측 그룹에 표시할 요소가 하나도 없는 상태로 렌더하면
93
+ const container = renderMessageNotification();
94
+ // Then: actions-container도 footer-container도 렌더되지 않는다
95
+ (0, _vitest.expect)(container.querySelector(SELECTOR.ACTIONS_CONTAINER)).toBeNull();
96
+ (0, _vitest.expect)(container.querySelector(SELECTOR.FOOTER_CONTAINER)).toBeNull();
97
+ // 본문 영역은 그대로 유지된다
98
+ (0, _vitest.expect)(container.querySelector(SELECTOR.CONTENT_WRAPPER)).not.toBeNull();
99
+ });
100
+ (0, _vitest.it)('U-3-a: actions만 지정하면 actions-container만 남고 footer-container는 없다', () => {
101
+ // Given/When: 액션 버튼만 있고 닫기 그룹이 없으면
102
+ const container = renderMessageNotification({
103
+ actions: [{
104
+ label: '조회하기',
105
+ hierarchy: 'text',
106
+ onClick: _vitest.vi.fn()
107
+ }]
108
+ });
109
+ // Then: actions-container는 존재하고 그 자식은 actions 그룹 하나뿐이다
110
+ const actionsContainer = container.querySelector(SELECTOR.ACTIONS_CONTAINER);
111
+ const actionsGroup = container.querySelector(SELECTOR.ACTIONS);
112
+ (0, _vitest.expect)(actionsContainer).not.toBeNull();
113
+ (0, _vitest.expect)(container.querySelector(SELECTOR.FOOTER_CONTAINER)).toBeNull();
114
+ (0, _vitest.expect)(Array.from(actionsContainer?.children ?? [])).toEqual([actionsGroup]);
115
+ });
116
+ (0, _vitest.it)('U-3-b: onClose만 지정하면 footer-container에 닫기 버튼만 담긴다', () => {
117
+ // Given/When: 닫기 핸들러만 지정하면
118
+ const container = renderMessageNotification({
119
+ onClose: _vitest.vi.fn()
120
+ });
121
+ // Then: footer-container에는 닫기 버튼 1개만 존재하고 hide-link는 없다
122
+ const footerContainer = container.querySelector(SELECTOR.FOOTER_CONTAINER);
123
+ (0, _vitest.expect)(footerContainer?.children).toHaveLength(1);
124
+ (0, _vitest.expect)(footerContainer?.querySelector(SELECTOR.CLOSE_BUTTON)).not.toBeNull();
125
+ (0, _vitest.expect)(footerContainer?.querySelector(SELECTOR.HIDE_LINK)).toBeNull();
126
+ });
127
+ (0, _vitest.it)('U-4: FeaturedIcon이 md 사이즈(40px 원 / 20px 아이콘)로 렌더된다', () => {
128
+ // Given/When: error 색상으로 렌더하면
129
+ const container = renderMessageNotification({
130
+ color: 'error'
131
+ });
132
+ // Then: featured-icon은 --md 수식자를 가지며 내부 SVG는 20px다
133
+ const icon = container.querySelector(SELECTOR.ICON);
134
+ (0, _vitest.expect)(icon).not.toBeNull();
135
+ (0, _vitest.expect)(icon?.classList.contains('ncua-featured-icon--md')).toBe(true);
136
+ (0, _vitest.expect)(icon?.classList.contains('ncua-featured-icon--lg')).toBe(false);
137
+ (0, _vitest.expect)(icon?.querySelector('svg')?.getAttribute('width')).toBe('20');
138
+ });
139
+ (0, _vitest.it)('hide-link는 구현별 수식자(--link/--text) 없이 공통 클래스 2개만 갖는다', () => {
140
+ // Given/When: 다시 보지 않기 핸들러를 지정해 렌더하면
141
+ const container = renderMessageNotification({
142
+ onHidePermanently: _vitest.vi.fn()
143
+ });
144
+ // Then: SCSS 미정의 수식자 --link에 의존하지 않는다
145
+ const hideLink = container.querySelector(SELECTOR.HIDE_LINK);
146
+ (0, _vitest.expect)(hideLink?.className.split(' ').filter(Boolean).sort()).toEqual(['ncua-message-notification__hide-link', 'ncua-notification__action-button']);
147
+ });
148
+ });
149
+ (0, _vitest.describe)('MessageNotification (React) — 공개 API 회귀 방지', () => {
150
+ (0, _vitest.it)('지원하지 않는 color("info")는 neutral로 폴백한다', () => {
151
+ // Given/When: message 타입이 지원하지 않는 info 색상을 넘기면
152
+ const container = renderMessageNotification({
153
+ color: 'info'
154
+ });
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);
159
+ });
160
+ (0, _vitest.it)('닫기/다시 보지 않기 클릭 시 핸들러가 호출되고 접근성 속성이 유지된다', () => {
161
+ // Given: 핸들러를 지정해 렌더하고
162
+ const onClose = _vitest.vi.fn();
163
+ const onHidePermanently = _vitest.vi.fn();
164
+ const container = renderMessageNotification({
165
+ onClose,
166
+ onHidePermanently
167
+ });
168
+ // When: 각 버튼을 클릭하면
169
+ (0, _testUtils.act)(() => {
170
+ container.querySelector(SELECTOR.CLOSE_BUTTON)?.click();
171
+ container.querySelector(SELECTOR.HIDE_LINK)?.click();
172
+ });
173
+ // Then: 핸들러가 각각 1회 호출되고 role/aria-label이 유지된다
174
+ (0, _vitest.expect)(onClose).toHaveBeenCalledTimes(1);
175
+ (0, _vitest.expect)(onHidePermanently).toHaveBeenCalledTimes(1);
176
+ (0, _vitest.expect)(container.querySelector(SELECTOR.ROOT)?.getAttribute('role')).toBe('alert');
177
+ (0, _vitest.expect)(container.querySelector(SELECTOR.CLOSE_BUTTON)?.getAttribute('aria-label')).toBe('알림 닫기');
178
+ });
179
+ });
180
+ (0, _vitest.describe)('MessageNotification (React) — 액션 버튼 색상(hierarchy)', () => {
181
+ const SIZE_MODIFIER = /^ncua-btn--(xs|sm|md|lg|xl)$/;
182
+ /** 사이즈를 제외한 `ncua-btn--*` 수식자 = 색상(hierarchy) 수식자. */
183
+ function buttonHierarchyModifiers(root) {
184
+ return Array.from(root.querySelectorAll('.ncua-btn')).map(button => Array.from(button.classList).find(name => name.startsWith('ncua-btn--') && !SIZE_MODIFIER.test(name)) ?? '');
185
+ }
186
+ (0, _vitest.it)('Figma TO-BE 조합(secondary-gray / secondary)을 ncua-btn 수식자로 반영한다', () => {
187
+ // Given/When: 조회하기 secondary-gray, 포인트 충전 secondary로 렌더하면
188
+ const container = renderMessageNotification({
189
+ actions: [{
190
+ label: '조회하기',
191
+ hierarchy: 'secondary-gray',
192
+ onClick: _vitest.vi.fn()
193
+ }, {
194
+ label: '포인트 충전',
195
+ hierarchy: 'secondary',
196
+ onClick: _vitest.vi.fn()
197
+ }]
198
+ });
199
+ // Then: ButtonTheme와 동일한 수식자가 순서대로 붙는다
200
+ (0, _vitest.expect)(buttonHierarchyModifiers(container)).toEqual(['ncua-btn--secondary-gray', 'ncua-btn--secondary']);
201
+ });
202
+ (0, _vitest.it)('text / text-gray도 계속 지원한다', () => {
203
+ // Given/When: 기존 어휘로 렌더하면
204
+ const container = renderMessageNotification({
205
+ actions: [{
206
+ label: '조회하기',
207
+ hierarchy: 'text',
208
+ onClick: _vitest.vi.fn()
209
+ }, {
210
+ label: '포인트 충전',
211
+ hierarchy: 'text-gray',
212
+ onClick: _vitest.vi.fn()
213
+ }]
214
+ });
215
+ // Then: 기존 수식자가 그대로 유지된다 (회귀 방지)
216
+ (0, _vitest.expect)(buttonHierarchyModifiers(container)).toEqual(['ncua-btn--text', 'ncua-btn--text-gray']);
217
+ });
218
+ (0, _vitest.it)('hierarchy를 생략하면 기본값 text로 렌더한다', () => {
219
+ // Given/When: 색상을 지정하지 않은 액션을 렌더하면
220
+ const container = renderMessageNotification({
221
+ actions: [{
222
+ label: '확인',
223
+ onClick: _vitest.vi.fn()
224
+ }]
225
+ });
226
+ // Then: Button의 기본값(secondary-gray)이 아니라 알림의 기본값 text가 적용된다
227
+ (0, _vitest.expect)(buttonHierarchyModifiers(container)).toEqual(['ncua-btn--text']);
228
+ });
229
+ (0, _vitest.it)('액션 버튼 클릭 시 onClick이 호출된다', () => {
230
+ // Given: secondary 색상 액션을 렌더하고
231
+ const onClick = _vitest.vi.fn();
232
+ const container = renderMessageNotification({
233
+ actions: [{
234
+ label: '포인트 충전',
235
+ hierarchy: 'secondary',
236
+ onClick
237
+ }]
238
+ });
239
+ // When: 버튼을 클릭하면
240
+ (0, _testUtils.act)(() => {
241
+ container.querySelector('.ncua-btn')?.click();
242
+ });
243
+ // Then: 핸들러가 1회 호출된다
244
+ (0, _vitest.expect)(onClick).toHaveBeenCalledTimes(1);
245
+ });
246
+ });