@ncds/ui-admin 1.8.25 → 1.8.26-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/cjs/assets/scripts/notification/FullWidthNotification.js +2 -0
  2. package/dist/cjs/assets/scripts/notification/MessageNotification.js +30 -23
  3. package/dist/cjs/assets/scripts/notification/const/classNames.js +3 -0
  4. package/dist/cjs/assets/scripts/notification/const/icons.js +11 -2
  5. package/dist/cjs/assets/scripts/notification/const/index.js +9 -4
  6. package/dist/cjs/assets/scripts/notification/const/sizes.js +6 -1
  7. package/dist/cjs/assets/scripts/notification/const/types.js +1 -10
  8. package/dist/cjs/assets/scripts/notification/messageTemplate.js +20 -8
  9. package/dist/cjs/assets/scripts/notification/utils.js +21 -17
  10. package/dist/cjs/constant/notification.js +15 -1
  11. package/dist/cjs/src/components/feedback-and-status/badge/Badge.js +1 -1
  12. package/dist/cjs/src/components/forms-and-input/combo-box/ComboBox.js +16 -126
  13. package/dist/cjs/src/components/forms-and-input/combo-box/__tests__/ComboBox.portal.test.js +3 -3
  14. package/dist/cjs/src/components/overlays/notification/FloatingNotification.js +4 -7
  15. package/dist/cjs/src/components/overlays/notification/FullWidthNotification.js +13 -8
  16. package/dist/cjs/src/components/overlays/notification/MessageNotification.js +20 -14
  17. package/dist/cjs/src/components/overlays/notification/MessageNotificationParts.js +22 -15
  18. package/dist/cjs/src/components/overlays/notification/Notification.js +6 -0
  19. package/dist/cjs/src/components/overlays/notification/NotificationActionButtons.js +27 -0
  20. package/dist/cjs/src/components/overlays/notification/__tests__/supportTextLink.test.js +58 -0
  21. package/dist/cjs/src/components/overlays/notification/linkTarget.js +18 -0
  22. package/dist/cjs/src/generated/scoped-css.js +1 -1
  23. package/dist/cjs/src/utils/index.js +11 -0
  24. package/dist/cjs/src/utils/url/__tests__/isSafeUrl.test.js +49 -0
  25. package/dist/cjs/src/utils/url/index.js +16 -0
  26. package/dist/cjs/src/utils/url/isSafeUrl.js +32 -0
  27. package/dist/esm/assets/scripts/notification/FullWidthNotification.js +3 -1
  28. package/dist/esm/assets/scripts/notification/MessageNotification.js +32 -25
  29. package/dist/esm/assets/scripts/notification/const/classNames.js +3 -0
  30. package/dist/esm/assets/scripts/notification/const/icons.js +10 -1
  31. package/dist/esm/assets/scripts/notification/const/index.js +2 -3
  32. package/dist/esm/assets/scripts/notification/const/sizes.js +5 -0
  33. package/dist/esm/assets/scripts/notification/const/types.js +1 -8
  34. package/dist/esm/assets/scripts/notification/messageTemplate.js +21 -9
  35. package/dist/esm/assets/scripts/notification/utils.js +19 -16
  36. package/dist/esm/constant/notification.js +14 -0
  37. package/dist/esm/src/components/feedback-and-status/badge/Badge.js +1 -1
  38. package/dist/esm/src/components/forms-and-input/combo-box/ComboBox.js +17 -127
  39. package/dist/esm/src/components/forms-and-input/combo-box/__tests__/ComboBox.portal.test.js +3 -3
  40. package/dist/esm/src/components/overlays/notification/FloatingNotification.js +4 -7
  41. package/dist/esm/src/components/overlays/notification/FullWidthNotification.js +13 -8
  42. package/dist/esm/src/components/overlays/notification/MessageNotification.js +21 -15
  43. package/dist/esm/src/components/overlays/notification/MessageNotificationParts.js +22 -15
  44. package/dist/esm/src/components/overlays/notification/Notification.js +6 -0
  45. package/dist/esm/src/components/overlays/notification/NotificationActionButtons.js +21 -0
  46. package/dist/esm/src/components/overlays/notification/__tests__/supportTextLink.test.js +55 -0
  47. package/dist/esm/src/components/overlays/notification/linkTarget.js +12 -0
  48. package/dist/esm/src/generated/scoped-css.js +1 -1
  49. package/dist/esm/src/utils/index.js +3 -1
  50. package/dist/esm/src/utils/url/__tests__/isSafeUrl.test.js +47 -0
  51. package/dist/esm/src/utils/url/index.js +1 -0
  52. package/dist/esm/src/utils/url/isSafeUrl.js +26 -0
  53. package/dist/temp/assets/scripts/notification/FullWidthNotification.js +3 -2
  54. package/dist/temp/assets/scripts/notification/MessageNotification.d.ts +2 -0
  55. package/dist/temp/assets/scripts/notification/MessageNotification.js +30 -25
  56. package/dist/temp/assets/scripts/notification/const/classNames.d.ts +3 -0
  57. package/dist/temp/assets/scripts/notification/const/classNames.js +3 -0
  58. package/dist/temp/assets/scripts/notification/const/icons.d.ts +6 -0
  59. package/dist/temp/assets/scripts/notification/const/icons.js +9 -0
  60. package/dist/temp/assets/scripts/notification/const/index.d.ts +3 -4
  61. package/dist/temp/assets/scripts/notification/const/index.js +2 -3
  62. package/dist/temp/assets/scripts/notification/const/sizes.d.ts +4 -0
  63. package/dist/temp/assets/scripts/notification/const/sizes.js +5 -0
  64. package/dist/temp/assets/scripts/notification/const/types.d.ts +28 -1
  65. package/dist/temp/assets/scripts/notification/const/types.js +1 -8
  66. package/dist/temp/assets/scripts/notification/messageTemplate.d.ts +5 -1
  67. package/dist/temp/assets/scripts/notification/messageTemplate.js +16 -11
  68. package/dist/temp/assets/scripts/notification/utils.d.ts +10 -3
  69. package/dist/temp/assets/scripts/notification/utils.js +21 -18
  70. package/dist/temp/constant/notification.d.ts +13 -0
  71. package/dist/temp/constant/notification.js +14 -0
  72. package/dist/temp/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  73. package/dist/temp/src/components/feedback-and-status/badge/Badge.js +1 -1
  74. package/dist/temp/src/components/forms-and-input/combo-box/ComboBox.d.ts +1 -1
  75. package/dist/temp/src/components/forms-and-input/combo-box/ComboBox.js +13 -119
  76. package/dist/temp/src/components/forms-and-input/combo-box/__tests__/ComboBox.portal.test.js +3 -3
  77. package/dist/temp/src/components/overlays/notification/FloatingNotification.js +2 -2
  78. package/dist/temp/src/components/overlays/notification/FullWidthNotification.d.ts +6 -1
  79. package/dist/temp/src/components/overlays/notification/FullWidthNotification.js +7 -2
  80. package/dist/temp/src/components/overlays/notification/MessageNotification.d.ts +15 -1
  81. package/dist/temp/src/components/overlays/notification/MessageNotification.js +11 -12
  82. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.d.ts +10 -5
  83. package/dist/temp/src/components/overlays/notification/MessageNotificationParts.js +9 -6
  84. package/dist/temp/src/components/overlays/notification/Notification.d.ts +23 -2
  85. package/dist/temp/src/components/overlays/notification/Notification.js +3 -3
  86. package/dist/temp/src/components/overlays/notification/NotificationActionButtons.d.ts +12 -0
  87. package/dist/temp/src/components/overlays/notification/NotificationActionButtons.js +9 -0
  88. package/dist/temp/src/components/overlays/notification/__tests__/supportTextLink.test.js +73 -0
  89. package/dist/temp/src/components/overlays/notification/linkTarget.d.ts +11 -0
  90. package/dist/temp/src/components/overlays/notification/linkTarget.js +9 -0
  91. package/dist/temp/src/generated/scoped-css.js +1 -1
  92. package/dist/temp/src/utils/index.d.ts +1 -0
  93. package/dist/temp/src/utils/index.js +2 -0
  94. package/dist/temp/src/utils/url/__tests__/isSafeUrl.test.js +61 -0
  95. package/dist/temp/src/utils/url/index.d.ts +1 -0
  96. package/dist/temp/src/utils/url/index.js +1 -0
  97. package/dist/temp/src/utils/url/isSafeUrl.d.ts +8 -0
  98. package/dist/temp/src/utils/url/isSafeUrl.js +29 -0
  99. package/dist/types/assets/scripts/notification/MessageNotification.d.ts +2 -0
  100. package/dist/types/assets/scripts/notification/const/classNames.d.ts +3 -0
  101. package/dist/types/assets/scripts/notification/const/icons.d.ts +6 -0
  102. package/dist/types/assets/scripts/notification/const/index.d.ts +3 -4
  103. package/dist/types/assets/scripts/notification/const/sizes.d.ts +4 -0
  104. package/dist/types/assets/scripts/notification/const/types.d.ts +28 -1
  105. package/dist/types/assets/scripts/notification/messageTemplate.d.ts +5 -1
  106. package/dist/types/assets/scripts/notification/utils.d.ts +10 -3
  107. package/dist/types/constant/notification.d.ts +13 -0
  108. package/dist/types/src/components/feedback-and-status/badge/Badge.d.ts +1 -1
  109. package/dist/types/src/components/forms-and-input/combo-box/ComboBox.d.ts +1 -1
  110. package/dist/types/src/components/overlays/notification/FullWidthNotification.d.ts +6 -1
  111. package/dist/types/src/components/overlays/notification/MessageNotification.d.ts +15 -1
  112. package/dist/types/src/components/overlays/notification/MessageNotificationParts.d.ts +10 -5
  113. package/dist/types/src/components/overlays/notification/Notification.d.ts +23 -2
  114. package/dist/types/src/components/overlays/notification/NotificationActionButtons.d.ts +12 -0
  115. package/dist/types/src/components/overlays/notification/__tests__/supportTextLink.test.d.ts +1 -0
  116. package/dist/types/src/components/overlays/notification/linkTarget.d.ts +11 -0
  117. package/dist/types/src/utils/index.d.ts +1 -0
  118. package/dist/types/src/utils/url/__tests__/isSafeUrl.test.d.ts +1 -0
  119. package/dist/types/src/utils/url/index.d.ts +1 -0
  120. package/dist/types/src/utils/url/isSafeUrl.d.ts +8 -0
  121. package/dist/ui-admin/assets/styles/style.css +54 -34
  122. package/package.json +1 -1
  123. package/dist/cjs/src/components/forms-and-input/combo-box/__tests__/ComboBox.test.js +0 -455
  124. package/dist/esm/src/components/forms-and-input/combo-box/__tests__/ComboBox.test.js +0 -452
  125. package/dist/temp/src/components/forms-and-input/combo-box/__tests__/ComboBox.test.js +0 -293
  126. /package/dist/temp/src/components/{forms-and-input/combo-box/__tests__/ComboBox.test.d.ts → overlays/notification/__tests__/supportTextLink.test.d.ts} +0 -0
  127. /package/dist/{types/src/components/forms-and-input/combo-box/__tests__/ComboBox.test.d.ts → temp/src/utils/url/__tests__/isSafeUrl.test.d.ts} +0 -0
@@ -1,293 +0,0 @@
1
- // @vitest-environment jsdom
2
- import { createElement, useState } from 'react';
3
- import { createRoot } from 'react-dom/client';
4
- import { act } from 'react-dom/test-utils';
5
- import { afterEach, describe, expect, it, vi } from 'vitest';
6
- import { ComboBox } from '../ComboBox';
7
- // React 18에서 act() 사용 시 필요한 플래그 (미설정 시 console.error 경고 발생)
8
- globalThis.IS_REACT_ACT_ENVIRONMENT = true;
9
- const OPTIONS = [
10
- { id: 1, label: '사과' },
11
- { id: 2, label: '바나나' },
12
- { id: 3, label: '체리' },
13
- ];
14
- /** id 1·2가 빠진 목록 — 검색 필터로 optionItems가 줄어든 상황 */
15
- const FILTERED_OPTIONS = [{ id: 3, label: '체리' }];
16
- /** optionItems에 없는 id */
17
- const MISSING_ID = 99;
18
- /** 바깥에서 reset 으로 넣는 값 — 기존 선택(1·2)과 겹치지 않는 id */
19
- const RESET_ID = 3;
20
- /** 「전체 선택」 결과 — OPTIONS 의 모든 id */
21
- const ALL_IDS = OPTIONS.map((option) => option.id);
22
- let root = null;
23
- let container = null;
24
- /** 같은 root에 다시 render하면 props 변경(rerender)이 된다. */
25
- function render(props) {
26
- if (!container) {
27
- container = document.createElement('div');
28
- document.body.appendChild(container);
29
- root = createRoot(container);
30
- }
31
- act(() => {
32
- root?.render(createElement(ComboBox, props));
33
- });
34
- return container;
35
- }
36
- /** onChange로 받은 값을 value로 되돌려주는 사용처 흉내 (controlled) */
37
- function Harness({ initialValue, onChangeSpy, transform, ...rest }) {
38
- const [value, setValue] = useState(initialValue);
39
- return createElement(ComboBox, {
40
- ...rest,
41
- value,
42
- onChange: (next) => {
43
- onChangeSpy(next);
44
- setValue(transform ? transform(next) : next);
45
- },
46
- });
47
- }
48
- function renderHarness(props) {
49
- if (!container) {
50
- container = document.createElement('div');
51
- document.body.appendChild(container);
52
- root = createRoot(container);
53
- }
54
- act(() => {
55
- root?.render(createElement(Harness, props));
56
- });
57
- return container;
58
- }
59
- function getTagTexts(el) {
60
- return Array.from(el.querySelectorAll('.ncua-combobox__tags .ncua-tag .ncua-tag__text')).map((node) => node.textContent ?? '');
61
- }
62
- function getCloseButtons(el) {
63
- return Array.from(el.querySelectorAll('.ncua-combobox__tags .ncua-tag__close'));
64
- }
65
- function click(target) {
66
- if (!target)
67
- throw new Error('클릭 대상을 찾을 수 없습니다');
68
- act(() => {
69
- target.click();
70
- });
71
- }
72
- /** 「전체」 버튼으로 드롭다운을 연다 (입력값이 없어도 전체 목록 표시). */
73
- function openDropdown(el) {
74
- click(el.querySelector('.ncua-input__right-icon'));
75
- }
76
- function clickOption(el, label) {
77
- const option = Array.from(el.querySelectorAll('.ncua-select-dropdown__option')).find((node) => node.textContent === label);
78
- click(option);
79
- }
80
- function clickButton(el, label) {
81
- const button = Array.from(el.querySelectorAll('button')).find((node) => node.textContent?.includes(label));
82
- click(button);
83
- }
84
- afterEach(() => {
85
- act(() => {
86
- root?.unmount();
87
- });
88
- container?.remove();
89
- root = null;
90
- container = null;
91
- });
92
- describe('ComboBox — 단일 모드 외부 value Tag', () => {
93
- it('S-01: value에 해당하는 옵션이 있으면 Tag 1개를 라벨로 표시한다', () => {
94
- const el = render({ value: 1, optionItems: OPTIONS });
95
- expect(getTagTexts(el)).toEqual(['사과']);
96
- });
97
- it('S-02: optionItems가 늦게 도착하면 도착 시 Tag를 표시한다', () => {
98
- const el = render({ value: 1, optionItems: [] });
99
- expect(getTagTexts(el)).toEqual([]);
100
- render({ value: 1, optionItems: OPTIONS });
101
- expect(getTagTexts(el)).toEqual(['사과']);
102
- });
103
- it.each([
104
- ['빈 문자열', ''],
105
- ['undefined', undefined],
106
- ['null', null],
107
- ])('S-03: value가 %s이면 Tag를 표시하지 않는다', (_, value) => {
108
- const el = render({ value: value, optionItems: OPTIONS });
109
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
110
- });
111
- it.each([
112
- ['빈 문자열', ''],
113
- ['undefined', undefined],
114
- ])('S-04: Tag 표시 중 value가 %s로 바뀌면 Tag가 사라진다', (_, value) => {
115
- const el = render({ value: 1, optionItems: OPTIONS });
116
- expect(getTagTexts(el)).toEqual(['사과']);
117
- render({ value, optionItems: OPTIONS });
118
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
119
- });
120
- it('S-05: 검색 필터로 optionItems에서 선택 항목이 빠져도 같은 라벨로 Tag를 유지한다', () => {
121
- const el = render({ value: 1, optionItems: OPTIONS });
122
- expect(getTagTexts(el)).toEqual(['사과']);
123
- render({ value: 1, optionItems: FILTERED_OPTIONS });
124
- expect(getTagTexts(el)).toEqual(['사과']);
125
- });
126
- it('S-06: 목록에 없는 다른 id로 바뀌면 이전 라벨을 쓰지 않고 Tag를 표시하지 않는다', () => {
127
- const el = render({ value: 1, optionItems: OPTIONS });
128
- expect(getTagTexts(el)).toEqual(['사과']);
129
- render({ value: MISSING_ID, optionItems: OPTIONS });
130
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
131
- });
132
- it('S-07: value가 다른 id로 바뀌면 그 id의 라벨로 Tag를 바꾼다', () => {
133
- const el = render({ value: 1, optionItems: OPTIONS });
134
- render({ value: 2, optionItems: OPTIONS });
135
- expect(getTagTexts(el)).toEqual(['바나나']);
136
- });
137
- it('S-08: disabled면 Tag는 표시하고 X 버튼은 표시하지 않는다', () => {
138
- const el = render({ value: 1, optionItems: OPTIONS, disabled: true });
139
- expect(getTagTexts(el)).toEqual(['사과']);
140
- expect(getCloseButtons(el)).toHaveLength(0);
141
- });
142
- it('S-09: value가 0이어도 빈 값으로 보지 않고 Tag를 표시한다', () => {
143
- const el = render({ value: 0, optionItems: [{ id: 0, label: '없음' }, ...OPTIONS] });
144
- expect(getTagTexts(el)).toEqual(['없음']);
145
- });
146
- it.each([
147
- [0, '0'],
148
- [null, ''],
149
- ])('S-12: register 사용 시 value가 %s이면 hidden input 값은 %j이다 (Tag 표시 규칙과 같게 0은 값으로 본다)', (value, expected) => {
150
- const register = { name: 'item', onChange: vi.fn(), onBlur: vi.fn(), ref: vi.fn() };
151
- const el = render({ value, register, optionItems: [{ id: 0, label: '없음' }, ...OPTIONS] });
152
- expect(el.querySelector('input[type="hidden"]')?.value).toBe(expected);
153
- });
154
- it('S-10 (회귀): 옵션을 클릭하면 onChange(id)를 호출하고 Tag를 표시한다', () => {
155
- const onChangeSpy = vi.fn();
156
- const el = renderHarness({ initialValue: '', onChangeSpy, optionItems: OPTIONS });
157
- openDropdown(el);
158
- clickOption(el, '바나나');
159
- expect(onChangeSpy).toHaveBeenCalledWith(2);
160
- expect(getTagTexts(el)).toEqual(['바나나']);
161
- });
162
- it('S-11 (회귀): X를 클릭하면 onChange("")를 호출하고 Tag가 사라진다', () => {
163
- const onChangeSpy = vi.fn();
164
- const el = renderHarness({ initialValue: 1, onChangeSpy, optionItems: OPTIONS });
165
- click(getCloseButtons(el)[0]);
166
- expect(onChangeSpy).toHaveBeenCalledWith('');
167
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
168
- });
169
- });
170
- describe('ComboBox — multiple 모드 외부 value Tag', () => {
171
- it('M-01: value 배열에 해당하는 Tag를 모두 표시한다', () => {
172
- const el = render({ multiple: true, value: [1, 2], optionItems: OPTIONS });
173
- expect(getTagTexts(el)).toEqual(['사과', '바나나']);
174
- });
175
- it('M-02: optionItems가 늦게 도착하면 도착 시 Tag를 표시한다', () => {
176
- const el = render({ multiple: true, value: [1, 2], optionItems: [] });
177
- expect(getTagTexts(el)).toEqual([]);
178
- render({ multiple: true, value: [1, 2], optionItems: OPTIONS });
179
- expect(getTagTexts(el)).toEqual(['사과', '바나나']);
180
- });
181
- it.each([
182
- ['빈 배열', []],
183
- ['undefined', undefined],
184
- ['null', null],
185
- ])('M-03: value가 %s이면 Tag를 표시하지 않는다', (_, value) => {
186
- const el = render({ multiple: true, value: value, optionItems: OPTIONS });
187
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
188
- });
189
- it.each([
190
- ['빈 배열', []],
191
- ['undefined', undefined],
192
- ])('M-04: Tag 표시 중 value가 %s로 바뀌면 Tag가 사라진다', (_, value) => {
193
- const el = render({ multiple: true, value: [1, 2], optionItems: OPTIONS });
194
- expect(getTagTexts(el)).toEqual(['사과', '바나나']);
195
- render({ multiple: true, value, optionItems: OPTIONS });
196
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
197
- });
198
- it('M-05: 바깥에서 value를 바꾸면(reset) 새 value로 Tag를 다시 그린다', () => {
199
- const el = render({ multiple: true, value: [1, 2], optionItems: OPTIONS });
200
- render({ multiple: true, value: [RESET_ID], optionItems: OPTIONS });
201
- expect(getTagTexts(el)).toEqual(['체리']);
202
- });
203
- it('M-06: 검색 필터로 optionItems에서 선택 항목이 빠져도 Tag를 유지한다', () => {
204
- const el = render({ multiple: true, value: [1, 2], optionItems: OPTIONS });
205
- render({ multiple: true, value: [1, 2], optionItems: FILTERED_OPTIONS });
206
- expect(getTagTexts(el)).toEqual(['사과', '바나나']);
207
- });
208
- it('M-07: disabled면 Tag는 표시하고 X 버튼은 표시하지 않는다', () => {
209
- const el = render({ multiple: true, value: [1], optionItems: OPTIONS, disabled: true });
210
- expect(getTagTexts(el)).toEqual(['사과']);
211
- expect(getCloseButtons(el)).toHaveLength(0);
212
- });
213
- it('M-08 (회귀): 옵션을 클릭하면 onChange만 호출하고 Tag는 「선택 완료」 전까지 그대로다', () => {
214
- const onChangeSpy = vi.fn();
215
- const el = renderHarness({ multiple: true, initialValue: [1], onChangeSpy, optionItems: OPTIONS });
216
- expect(getTagTexts(el)).toEqual(['사과']);
217
- openDropdown(el);
218
- clickOption(el, '바나나');
219
- expect(onChangeSpy).toHaveBeenCalledWith([1, 2]);
220
- expect(getTagTexts(el)).toEqual(['사과']);
221
- });
222
- it('M-09 (회귀): 옵션 클릭 후 「선택 완료」를 누르면 Tag를 반영하고 onComplete를 호출한다', () => {
223
- const onChangeSpy = vi.fn();
224
- const onComplete = vi.fn();
225
- const el = renderHarness({ multiple: true, initialValue: [1], onChangeSpy, onComplete, optionItems: OPTIONS });
226
- openDropdown(el);
227
- clickOption(el, '바나나');
228
- clickButton(el, '선택 완료');
229
- expect(getTagTexts(el)).toEqual(['사과', '바나나']);
230
- expect(onComplete).toHaveBeenCalledWith([1, 2]);
231
- });
232
- it('M-10 (회귀): X를 클릭하면 onChange(남은 배열)를 호출하고 해당 Tag만 제거한다', () => {
233
- const onChangeSpy = vi.fn();
234
- const el = renderHarness({ multiple: true, initialValue: [1, 2], onChangeSpy, optionItems: OPTIONS });
235
- click(getCloseButtons(el)[0]);
236
- expect(onChangeSpy).toHaveBeenCalledWith([2]);
237
- expect(getTagTexts(el)).toEqual(['바나나']);
238
- });
239
- it('M-11 (회귀): 「전체 선택」을 누르면 onChange(전체 id)만 호출하고 Tag는 그대로다', () => {
240
- const onChangeSpy = vi.fn();
241
- const el = renderHarness({ multiple: true, initialValue: [], onChangeSpy, optionItems: OPTIONS });
242
- openDropdown(el);
243
- clickButton(el, '전체 선택');
244
- expect(onChangeSpy).toHaveBeenCalledWith(ALL_IDS);
245
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
246
- });
247
- it('M-12: 클릭으로 고른 값과 같은 값을 바깥에서 비웠다가 다시 넣어도 Tag를 표시한다', () => {
248
- const props = { multiple: true, optionItems: OPTIONS, onChange: vi.fn() };
249
- const el = render({ ...props, value: [] });
250
- openDropdown(el);
251
- clickOption(el, '사과');
252
- render({ ...props, value: [1] });
253
- clickButton(el, '선택 완료');
254
- expect(getTagTexts(el)).toEqual(['사과']);
255
- render({ ...props, value: [] });
256
- expect(getTagTexts(el)).toEqual([]);
257
- render({ ...props, value: [1] });
258
- expect(getTagTexts(el)).toEqual(['사과']);
259
- });
260
- it('M-13 (회귀): 클릭 후 「선택 완료」 전에 optionItems가 바뀌어도(검색) Tag는 그대로다', () => {
261
- const onChangeSpy = vi.fn();
262
- const el = renderHarness({ multiple: true, initialValue: [1], onChangeSpy, optionItems: OPTIONS });
263
- openDropdown(el);
264
- clickOption(el, '바나나');
265
- renderHarness({ multiple: true, initialValue: [1], onChangeSpy, optionItems: FILTERED_OPTIONS });
266
- expect(onChangeSpy).toHaveBeenCalledWith([1, 2]);
267
- expect(getTagTexts(el)).toEqual(['사과']);
268
- });
269
- it('M-14 (회귀): 「선택 완료」 전에 클릭한 항목이 있을 때 X를 누르면 그 Tag만 빠지고 클릭한 항목은 확정되지 않는다', () => {
270
- const onChangeSpy = vi.fn();
271
- const el = renderHarness({ multiple: true, initialValue: [1], onChangeSpy, optionItems: OPTIONS });
272
- openDropdown(el);
273
- clickOption(el, '바나나');
274
- click(getCloseButtons(el)[0]);
275
- expect(onChangeSpy).toHaveBeenLastCalledWith([2]);
276
- expect(el.querySelector('.ncua-combobox__tags')).toBeNull();
277
- });
278
- it('M-15 (회귀): 사용처가 onChange 값의 순서를 바꿔 돌려줘도 「선택 완료」 전에는 Tag가 그대로다', () => {
279
- const onChangeSpy = vi.fn();
280
- const sortIds = (value) => (Array.isArray(value) ? [...value].sort() : value);
281
- const el = renderHarness({
282
- multiple: true,
283
- initialValue: [RESET_ID],
284
- onChangeSpy,
285
- transform: sortIds,
286
- optionItems: OPTIONS,
287
- });
288
- openDropdown(el);
289
- clickOption(el, '사과');
290
- expect(onChangeSpy).toHaveBeenCalledWith([RESET_ID, 1]);
291
- expect(getTagTexts(el)).toEqual(['체리']);
292
- });
293
- });