@pie-lib/config-ui 13.0.3-next.3 → 13.0.4-next.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 (188) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/alert-dialog.d.ts +44 -0
  3. package/dist/alert-dialog.js +47 -0
  4. package/dist/checkbox.d.ts +34 -0
  5. package/dist/checkbox.js +57 -0
  6. package/dist/choice-configuration/feedback-menu.d.ts +32 -0
  7. package/dist/choice-configuration/feedback-menu.js +85 -0
  8. package/dist/choice-configuration/index.d.ts +62 -0
  9. package/dist/choice-configuration/index.js +240 -0
  10. package/dist/choice-utils.d.ts +21 -0
  11. package/dist/choice-utils.js +15 -0
  12. package/dist/feedback-config/feedback-selector.d.ts +33 -0
  13. package/dist/feedback-config/feedback-selector.js +92 -0
  14. package/dist/feedback-config/group.d.ts +21 -0
  15. package/dist/feedback-config/group.js +33 -0
  16. package/dist/feedback-config/index.d.ts +48 -0
  17. package/dist/feedback-config/index.js +96 -0
  18. package/dist/form-section.d.ts +25 -0
  19. package/dist/form-section.js +25 -0
  20. package/dist/help.d.ts +41 -0
  21. package/dist/help.js +61 -0
  22. package/dist/index.d.ts +31 -0
  23. package/dist/index.js +34 -0
  24. package/dist/input.d.ts +29 -0
  25. package/dist/input.js +65 -0
  26. package/dist/inputs.d.ts +63 -0
  27. package/dist/inputs.js +70 -0
  28. package/dist/langs.d.ts +41 -0
  29. package/dist/langs.js +76 -0
  30. package/dist/layout/config-layout.d.ts +10 -0
  31. package/dist/layout/config-layout.js +75 -0
  32. package/dist/layout/index.d.ts +11 -0
  33. package/dist/layout/index.js +10 -0
  34. package/dist/layout/layout-contents.d.ts +21 -0
  35. package/dist/layout/layout-contents.js +70 -0
  36. package/dist/layout/settings-box.d.ts +19 -0
  37. package/dist/layout/settings-box.js +31 -0
  38. package/dist/mui-box/index.d.ts +21 -0
  39. package/dist/mui-box/index.js +47 -0
  40. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
  41. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
  42. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
  43. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
  44. package/dist/node_modules/.bun/react-measure@2.5.2_6dbf9a050bc9aadb/node_modules/react-measure/dist/index.esm.js +122 -0
  45. package/dist/node_modules/.bun/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +276 -0
  46. package/dist/number-text-field-custom.d.ts +51 -0
  47. package/dist/number-text-field-custom.js +192 -0
  48. package/dist/number-text-field.d.ts +47 -0
  49. package/dist/number-text-field.js +122 -0
  50. package/dist/radio-with-label.d.ts +25 -0
  51. package/dist/radio-with-label.js +27 -0
  52. package/dist/settings/display-size.d.ts +26 -0
  53. package/dist/settings/display-size.js +45 -0
  54. package/dist/settings/index.d.ts +45 -0
  55. package/dist/settings/index.js +63 -0
  56. package/dist/settings/panel.d.ts +27 -0
  57. package/dist/settings/panel.js +201 -0
  58. package/dist/settings/settings-radio-label.d.ts +25 -0
  59. package/dist/settings/settings-radio-label.js +29 -0
  60. package/dist/settings/toggle.d.ts +25 -0
  61. package/dist/settings/toggle.js +33 -0
  62. package/dist/tabs/index.d.ts +22 -0
  63. package/dist/tabs/index.js +39 -0
  64. package/dist/tags-input/index.d.ts +21 -0
  65. package/dist/tags-input/index.js +83 -0
  66. package/dist/two-choice.d.ts +43 -0
  67. package/dist/two-choice.js +79 -0
  68. package/dist/with-stateful-model.d.ts +42 -0
  69. package/dist/with-stateful-model.js +32 -0
  70. package/package.json +30 -18
  71. package/CHANGELOG.json +0 -32
  72. package/CHANGELOG.md +0 -2415
  73. package/LICENSE.md +0 -5
  74. package/lib/alert-dialog.js +0 -68
  75. package/lib/alert-dialog.js.map +0 -1
  76. package/lib/checkbox.js +0 -84
  77. package/lib/checkbox.js.map +0 -1
  78. package/lib/choice-configuration/feedback-menu.js +0 -129
  79. package/lib/choice-configuration/feedback-menu.js.map +0 -1
  80. package/lib/choice-configuration/index.js +0 -381
  81. package/lib/choice-configuration/index.js.map +0 -1
  82. package/lib/choice-utils.js +0 -42
  83. package/lib/choice-utils.js.map +0 -1
  84. package/lib/feedback-config/feedback-selector.js +0 -155
  85. package/lib/feedback-config/feedback-selector.js.map +0 -1
  86. package/lib/feedback-config/group.js +0 -61
  87. package/lib/feedback-config/group.js.map +0 -1
  88. package/lib/feedback-config/index.js +0 -146
  89. package/lib/feedback-config/index.js.map +0 -1
  90. package/lib/form-section.js +0 -44
  91. package/lib/form-section.js.map +0 -1
  92. package/lib/help.js +0 -106
  93. package/lib/help.js.map +0 -1
  94. package/lib/index.js +0 -186
  95. package/lib/index.js.map +0 -1
  96. package/lib/input.js +0 -106
  97. package/lib/input.js.map +0 -1
  98. package/lib/inputs.js +0 -105
  99. package/lib/inputs.js.map +0 -1
  100. package/lib/langs.js +0 -136
  101. package/lib/langs.js.map +0 -1
  102. package/lib/layout/config-layout.js +0 -137
  103. package/lib/layout/config-layout.js.map +0 -1
  104. package/lib/layout/index.js +0 -21
  105. package/lib/layout/index.js.map +0 -1
  106. package/lib/layout/layout-contents.js +0 -160
  107. package/lib/layout/layout-contents.js.map +0 -1
  108. package/lib/layout/settings-box.js +0 -57
  109. package/lib/layout/settings-box.js.map +0 -1
  110. package/lib/mui-box/index.js +0 -63
  111. package/lib/mui-box/index.js.map +0 -1
  112. package/lib/number-text-field-custom.js +0 -376
  113. package/lib/number-text-field-custom.js.map +0 -1
  114. package/lib/number-text-field.js +0 -229
  115. package/lib/number-text-field.js.map +0 -1
  116. package/lib/radio-with-label.js +0 -48
  117. package/lib/radio-with-label.js.map +0 -1
  118. package/lib/settings/display-size.js +0 -61
  119. package/lib/settings/display-size.js.map +0 -1
  120. package/lib/settings/index.js +0 -110
  121. package/lib/settings/index.js.map +0 -1
  122. package/lib/settings/panel.js +0 -392
  123. package/lib/settings/panel.js.map +0 -1
  124. package/lib/settings/settings-radio-label.js +0 -51
  125. package/lib/settings/settings-radio-label.js.map +0 -1
  126. package/lib/settings/toggle.js +0 -63
  127. package/lib/settings/toggle.js.map +0 -1
  128. package/lib/tabs/index.js +0 -75
  129. package/lib/tabs/index.js.map +0 -1
  130. package/lib/tags-input/index.js +0 -149
  131. package/lib/tags-input/index.js.map +0 -1
  132. package/lib/two-choice.js +0 -136
  133. package/lib/two-choice.js.map +0 -1
  134. package/lib/with-stateful-model.js +0 -61
  135. package/lib/with-stateful-model.js.map +0 -1
  136. package/src/__tests__/alert-dialog.test.jsx +0 -183
  137. package/src/__tests__/checkbox.test.jsx +0 -152
  138. package/src/__tests__/choice-utils.test.js +0 -12
  139. package/src/__tests__/form-section.test.jsx +0 -328
  140. package/src/__tests__/help.test.jsx +0 -184
  141. package/src/__tests__/input.test.jsx +0 -156
  142. package/src/__tests__/langs.test.jsx +0 -376
  143. package/src/__tests__/number-text-field-custom.test.jsx +0 -255
  144. package/src/__tests__/number-text-field.test.jsx +0 -263
  145. package/src/__tests__/radio-with-label.test.jsx +0 -155
  146. package/src/__tests__/settings-panel.test.js +0 -187
  147. package/src/__tests__/settings.test.jsx +0 -452
  148. package/src/__tests__/tabs.test.jsx +0 -188
  149. package/src/__tests__/two-choice.test.js +0 -110
  150. package/src/__tests__/with-stateful-model.test.jsx +0 -139
  151. package/src/alert-dialog.jsx +0 -75
  152. package/src/checkbox.jsx +0 -61
  153. package/src/choice-configuration/__tests__/feedback-menu.test.jsx +0 -151
  154. package/src/choice-configuration/__tests__/index.test.jsx +0 -234
  155. package/src/choice-configuration/feedback-menu.jsx +0 -96
  156. package/src/choice-configuration/index.jsx +0 -357
  157. package/src/choice-utils.js +0 -30
  158. package/src/feedback-config/__tests__/feedback-config.test.jsx +0 -141
  159. package/src/feedback-config/__tests__/feedback-selector.test.jsx +0 -97
  160. package/src/feedback-config/feedback-selector.jsx +0 -112
  161. package/src/feedback-config/group.jsx +0 -51
  162. package/src/feedback-config/index.jsx +0 -111
  163. package/src/form-section.jsx +0 -31
  164. package/src/help.jsx +0 -79
  165. package/src/index.js +0 -55
  166. package/src/input.jsx +0 -72
  167. package/src/inputs.jsx +0 -69
  168. package/src/langs.jsx +0 -111
  169. package/src/layout/__tests__/config.layout.test.jsx +0 -59
  170. package/src/layout/__tests__/layout-content.test.jsx +0 -3
  171. package/src/layout/config-layout.jsx +0 -103
  172. package/src/layout/index.js +0 -4
  173. package/src/layout/layout-contents.jsx +0 -117
  174. package/src/layout/settings-box.jsx +0 -32
  175. package/src/mui-box/index.jsx +0 -56
  176. package/src/number-text-field-custom.jsx +0 -333
  177. package/src/number-text-field.jsx +0 -215
  178. package/src/radio-with-label.jsx +0 -30
  179. package/src/settings/display-size.jsx +0 -53
  180. package/src/settings/index.js +0 -83
  181. package/src/settings/panel.jsx +0 -333
  182. package/src/settings/settings-radio-label.jsx +0 -32
  183. package/src/settings/toggle.jsx +0 -46
  184. package/src/tabs/index.jsx +0 -47
  185. package/src/tags-input/__tests__/index.test.jsx +0 -113
  186. package/src/tags-input/index.jsx +0 -116
  187. package/src/two-choice.jsx +0 -90
  188. package/src/with-stateful-model.jsx +0 -36
@@ -1,263 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { NumberTextField } from '../number-text-field';
5
-
6
- describe('NumberTextField', () => {
7
- const defaultProps = {
8
- value: 1,
9
- min: 1,
10
- max: 10,
11
- classes: {},
12
- onChange: jest.fn(),
13
- };
14
-
15
- beforeEach(() => {
16
- jest.clearAllMocks();
17
- });
18
-
19
- describe('rendering', () => {
20
- it('renders TextField with correct value', () => {
21
- render(<NumberTextField {...defaultProps} />);
22
- const input = screen.getByRole('spinbutton');
23
- expect(input).toHaveValue(1);
24
- });
25
-
26
- it('renders with custom label', () => {
27
- render(<NumberTextField {...defaultProps} label="Custom Label" />);
28
- expect(screen.getByLabelText('Custom Label')).toBeInTheDocument();
29
- });
30
-
31
- it('renders with suffix', () => {
32
- const { container } = render(<NumberTextField {...defaultProps} suffix="px" />);
33
- expect(screen.getByText('px')).toBeInTheDocument();
34
- });
35
-
36
- it('renders without suffix when not provided', () => {
37
- const { container } = render(<NumberTextField {...defaultProps} />);
38
- const input = screen.getByRole('spinbutton');
39
- expect(input).toBeInTheDocument();
40
- });
41
-
42
- it('renders as disabled when disabled prop is true', () => {
43
- render(<NumberTextField {...defaultProps} disabled={true} />);
44
- const input = screen.getByRole('spinbutton');
45
- expect(input).toBeDisabled();
46
- });
47
-
48
- it('renders as enabled when disabled prop is false', () => {
49
- render(<NumberTextField {...defaultProps} disabled={false} />);
50
- const input = screen.getByRole('spinbutton');
51
- expect(input).not.toBeDisabled();
52
- });
53
-
54
- it('renders with custom variant', () => {
55
- const { container } = render(<NumberTextField {...defaultProps} variant="outlined" />);
56
- expect(container.querySelector('input')).toBeInTheDocument();
57
- });
58
-
59
- it('renders with disableUnderline variant', () => {
60
- const { container } = render(<NumberTextField {...defaultProps} disableUnderline={true} />);
61
- expect(container.querySelector('input')).toBeInTheDocument();
62
- });
63
-
64
- it('renders with custom className', () => {
65
- const { container } = render(<NumberTextField {...defaultProps} className="custom-class" />);
66
- expect(container.querySelector('.custom-class')).toBeInTheDocument();
67
- });
68
-
69
- it('renders with custom inputClassName', () => {
70
- const { container } = render(<NumberTextField {...defaultProps} inputClassName="input-class" />);
71
- expect(container.querySelector('.input-class')).toBeInTheDocument();
72
- });
73
-
74
- it('renders with ShrinkLabel InputLabelProps', () => {
75
- render(<NumberTextField {...defaultProps} label="Shrink Label" />);
76
- expect(screen.getByLabelText('Shrink Label')).toBeInTheDocument();
77
- });
78
-
79
- it('renders with margin normal', () => {
80
- const { container } = render(<NumberTextField {...defaultProps} />);
81
- expect(container.querySelector('input')).toBeInTheDocument();
82
- });
83
- });
84
-
85
- describe('onChange callback', () => {
86
- it('calls onChange with clamped value on blur', async () => {
87
- const user = userEvent.setup();
88
- const onChange = jest.fn();
89
- render(<NumberTextField {...defaultProps} onChange={onChange} />);
90
-
91
- const input = screen.getByRole('spinbutton');
92
- await user.clear(input);
93
- await user.type(input, '15');
94
- fireEvent.blur(input);
95
-
96
- await waitFor(() => {
97
- expect(onChange).toHaveBeenCalledWith(expect.anything(), 10);
98
- });
99
- });
100
-
101
- it('calls onChange on Enter key press', async () => {
102
- const user = userEvent.setup();
103
- const onChange = jest.fn();
104
- render(<NumberTextField {...defaultProps} onChange={onChange} />);
105
-
106
- const input = screen.getByRole('spinbutton');
107
- await user.clear(input);
108
- await user.type(input, '5');
109
- await user.keyboard('{Enter}');
110
-
111
- expect(input).toHaveValue(5);
112
- });
113
-
114
- it('calls onChange during typing (unvalidated)', async () => {
115
- const user = userEvent.setup();
116
- const onChange = jest.fn();
117
- render(<NumberTextField {...defaultProps} onChange={onChange} />);
118
-
119
- const input = screen.getByRole('spinbutton');
120
- await user.clear(input);
121
- await user.type(input, '7');
122
-
123
- // onChange should be called at least once during typing
124
- expect(input).toHaveValue(7);
125
- });
126
-
127
- it('does not call onChange when value does not change on blur', async () => {
128
- const user = userEvent.setup();
129
- const onChange = jest.fn();
130
- render(<NumberTextField {...defaultProps} value={5} onChange={onChange} />);
131
-
132
- const input = screen.getByRole('spinbutton');
133
- fireEvent.blur(input);
134
-
135
- expect(onChange).not.toHaveBeenCalled();
136
- });
137
- });
138
-
139
- describe('range constraints', () => {
140
- it('handles only min constraint', async () => {
141
- const user = userEvent.setup();
142
- const { container } = render(<NumberTextField value={5} min={3} onChange={jest.fn()} />);
143
-
144
- const input = screen.getByRole('spinbutton');
145
- expect(input).toHaveValue(5);
146
- });
147
-
148
- it('handles only max constraint', async () => {
149
- const user = userEvent.setup();
150
- const { container } = render(<NumberTextField value={5} max={10} onChange={jest.fn()} />);
151
-
152
- const input = screen.getByRole('spinbutton');
153
- expect(input).toHaveValue(5);
154
- });
155
-
156
- it('handles no constraints', () => {
157
- const { container } = render(<NumberTextField value={100} onChange={jest.fn()} />);
158
-
159
- const input = screen.getByRole('spinbutton');
160
- expect(input).toHaveValue(100);
161
- });
162
- });
163
-
164
- describe('keyboard interactions', () => {
165
- it('handles Enter key to blur', async () => {
166
- const user = userEvent.setup();
167
- const onChange = jest.fn();
168
- render(<NumberTextField {...defaultProps} onChange={onChange} />);
169
-
170
- const input = screen.getByRole('spinbutton');
171
- input.focus();
172
- await user.type(input, '{Enter}');
173
-
174
- expect(input).not.toHaveFocus();
175
- });
176
-
177
- it('allows typing numbers', async () => {
178
- const user = userEvent.setup();
179
- render(<NumberTextField {...defaultProps} />);
180
-
181
- const input = screen.getByRole('spinbutton');
182
- await user.clear(input);
183
- await user.type(input, '42');
184
-
185
- expect(input).toHaveValue(42);
186
- });
187
-
188
- it('allows negative sign', async () => {
189
- const user = userEvent.setup();
190
- render(<NumberTextField {...defaultProps} min={-100} value={0} />);
191
-
192
- const input = screen.getByRole('spinbutton');
193
- await user.clear(input);
194
- await user.type(input, '-5');
195
-
196
- expect(input).toHaveValue(-5);
197
- });
198
- });
199
-
200
- describe('props updates', () => {
201
- it('updates value when prop changes', () => {
202
- const { rerender } = render(<NumberTextField {...defaultProps} value={5} />);
203
-
204
- let input = screen.getByRole('spinbutton');
205
- expect(input).toHaveValue(5);
206
-
207
- rerender(<NumberTextField {...defaultProps} value={8} />);
208
-
209
- input = screen.getByRole('spinbutton');
210
- expect(input).toHaveValue(8);
211
- });
212
-
213
- it('updates constraints when min/max props change', async () => {
214
- const user = userEvent.setup();
215
- const onChange = jest.fn();
216
- const { rerender } = render(<NumberTextField value={5} min={1} max={10} onChange={onChange} />);
217
-
218
- rerender(<NumberTextField value={5} min={1} max={8} onChange={onChange} />);
219
-
220
- const input = screen.getByRole('spinbutton');
221
- await user.clear(input);
222
- await user.type(input, '15');
223
- fireEvent.blur(input);
224
-
225
- await waitFor(() => {
226
- expect(input).toHaveValue(8); // Clamped to new max
227
- });
228
- });
229
-
230
- it('re-clamps value when constraints become more restrictive', () => {
231
- const onChange = jest.fn();
232
- const { rerender } = render(<NumberTextField value={8} min={1} max={10} onChange={onChange} />);
233
-
234
- rerender(<NumberTextField value={8} min={1} max={5} onChange={onChange} />);
235
-
236
- // Component should re-clamp the value
237
- expect(screen.getByRole('spinbutton')).toBeInTheDocument();
238
- });
239
- });
240
-
241
- describe('fallback number logic', () => {
242
- it('defaults to 0 when no min or max is provided', () => {
243
- render(<NumberTextField value={undefined} onChange={jest.fn()} />);
244
-
245
- const input = screen.getByRole('spinbutton');
246
- expect(input).toHaveValue(0);
247
- });
248
-
249
- it('defaults to max when only max is provided', () => {
250
- render(<NumberTextField value={undefined} max={15} onChange={jest.fn()} />);
251
-
252
- const input = screen.getByRole('spinbutton');
253
- expect(input).toHaveValue(15);
254
- });
255
-
256
- it('defaults to min when only min is provided', () => {
257
- render(<NumberTextField value={undefined} min={5} onChange={jest.fn()} />);
258
-
259
- const input = screen.getByRole('spinbutton');
260
- expect(input).toHaveValue(5);
261
- });
262
- });
263
- });
@@ -1,155 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import RadioWithLabel from '../radio-with-label';
5
-
6
- describe('RadioWithLabel Component', () => {
7
- const onChange = jest.fn();
8
-
9
- beforeEach(() => {
10
- onChange.mockClear();
11
- });
12
-
13
- describe('Rendering', () => {
14
- it('should render radio button with label', () => {
15
- render(<RadioWithLabel label="Option 1" value="option1" checked={false} onChange={onChange} />);
16
-
17
- expect(screen.getByText('Option 1')).toBeInTheDocument();
18
- expect(screen.getByRole('radio')).toBeInTheDocument();
19
- });
20
-
21
- it('should render checked radio button', () => {
22
- render(<RadioWithLabel label="Selected" value="selected" checked={true} onChange={onChange} />);
23
-
24
- expect(screen.getByRole('radio')).toBeChecked();
25
- });
26
-
27
- it('should render unchecked radio button', () => {
28
- render(<RadioWithLabel label="Unselected" value="unselected" checked={false} onChange={onChange} />);
29
-
30
- expect(screen.getByRole('radio')).not.toBeChecked();
31
- });
32
- });
33
-
34
- describe('User interaction', () => {
35
- it('should call onChange when radio button is clicked', async () => {
36
- const user = userEvent.setup();
37
- render(<RadioWithLabel label="Option" value="option" checked={false} onChange={onChange} />);
38
-
39
- const radio = screen.getByRole('radio');
40
- await user.click(radio);
41
-
42
- expect(onChange).toHaveBeenCalled();
43
- });
44
-
45
- it('should call onChange when label is clicked', async () => {
46
- const user = userEvent.setup();
47
- render(<RadioWithLabel label="Click me" value="test" checked={false} onChange={onChange} />);
48
-
49
- const label = screen.getByText('Click me');
50
- await user.click(label);
51
-
52
- expect(onChange).toHaveBeenCalled();
53
- });
54
- });
55
-
56
- describe('Props', () => {
57
- it('should accept different value types', () => {
58
- const { container: stringContainer } = render(
59
- <RadioWithLabel label="String value" value="string" checked={false} onChange={onChange} />,
60
- );
61
-
62
- const { container: numberContainer } = render(
63
- <RadioWithLabel label="Number value" value={123} checked={false} onChange={onChange} />,
64
- );
65
-
66
- expect(stringContainer.querySelector('input[type="radio"]')).toBeInTheDocument();
67
- expect(numberContainer.querySelector('input[type="radio"]')).toBeInTheDocument();
68
- });
69
-
70
- it('should display different labels', () => {
71
- render(
72
- <>
73
- <RadioWithLabel label="Label A" value="a" checked={false} onChange={onChange} />
74
- <RadioWithLabel label="Label B" value="b" checked={false} onChange={onChange} />
75
- </>,
76
- );
77
-
78
- expect(screen.getByText('Label A')).toBeInTheDocument();
79
- expect(screen.getByText('Label B')).toBeInTheDocument();
80
- });
81
- });
82
-
83
- describe('Radio button group behavior', () => {
84
- it('should allow multiple radio buttons to be rendered', () => {
85
- render(
86
- <>
87
- <RadioWithLabel label="Option 1" value="opt1" checked={true} onChange={onChange} />
88
- <RadioWithLabel label="Option 2" value="opt2" checked={false} onChange={onChange} />
89
- <RadioWithLabel label="Option 3" value="opt3" checked={false} onChange={onChange} />
90
- </>,
91
- );
92
-
93
- const radios = screen.getAllByRole('radio');
94
- expect(radios).toHaveLength(3);
95
- expect(radios[0]).toBeChecked();
96
- expect(radios[1]).not.toBeChecked();
97
- expect(radios[2]).not.toBeChecked();
98
- });
99
-
100
- it('should handle independent onChange callbacks for multiple radios', async () => {
101
- const user = userEvent.setup();
102
- const onChange1 = jest.fn();
103
- const onChange2 = jest.fn();
104
- const onChange3 = jest.fn();
105
-
106
- render(
107
- <>
108
- <RadioWithLabel label="Option 1" value="opt1" checked={true} onChange={onChange1} />
109
- <RadioWithLabel label="Option 2" value="opt2" checked={false} onChange={onChange2} />
110
- <RadioWithLabel label="Option 3" value="opt3" checked={false} onChange={onChange3} />
111
- </>,
112
- );
113
-
114
- const radios = screen.getAllByRole('radio');
115
-
116
- await user.click(radios[1]);
117
- expect(onChange2).toHaveBeenCalled();
118
- expect(onChange1).not.toHaveBeenCalled();
119
- expect(onChange3).not.toHaveBeenCalled();
120
-
121
- onChange2.mockClear();
122
-
123
- await user.click(radios[2]);
124
- expect(onChange3).toHaveBeenCalled();
125
- expect(onChange1).not.toHaveBeenCalled();
126
- expect(onChange2).not.toHaveBeenCalled();
127
- });
128
- });
129
-
130
- describe('Styling', () => {
131
- it('should render with correct styling classes', () => {
132
- const { container } = render(
133
- <RadioWithLabel label="Styled" value="styled" checked={false} onChange={onChange} />,
134
- );
135
-
136
- expect(container.querySelector('[class*="MuiFormControlLabel"]')).toBeInTheDocument();
137
- expect(container.querySelector('[class*="MuiRadio"]')).toBeInTheDocument();
138
- });
139
- });
140
-
141
- describe('Edge cases', () => {
142
- it('should handle empty string label', () => {
143
- render(<RadioWithLabel label="" value="empty" checked={false} onChange={onChange} />);
144
-
145
- expect(screen.getByRole('radio')).toBeInTheDocument();
146
- });
147
-
148
- it('should handle long labels', () => {
149
- const longLabel = 'This is a very long label that should wrap properly and not break the layout';
150
- render(<RadioWithLabel label={longLabel} value="long" checked={false} onChange={onChange} />);
151
-
152
- expect(screen.getByText(longLabel)).toBeInTheDocument();
153
- });
154
- });
155
- });
@@ -1,187 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Panel } from '../settings/panel';
4
- import { dropdown, numberField, numberFields, radio, toggle } from '../settings';
5
-
6
- describe('Settings Panel', () => {
7
- let onChange;
8
- let configure;
9
- let model;
10
- let groups;
11
-
12
- beforeEach(() => {
13
- onChange = jest.fn();
14
- configure = {
15
- orientationLabel: 'Orientation',
16
- settingsOrientation: true,
17
- editChoiceLabel: false,
18
- };
19
- model = {
20
- choiceAreaLayout: 'vertical',
21
- };
22
-
23
- groups = ({ configure }) => ({
24
- 'Group 1': {
25
- choiceAreaLayout: configure.settingsOrientation && {
26
- type: 'radio',
27
- label: configure.orientationLabel,
28
- choices: [
29
- { label: 'opt1', value: 'opt1' },
30
- { label: 'opt2', value: 'opt2' },
31
- ],
32
- },
33
- editChoiceLabel: { type: 'toggle', label: 'Edit choice label', isConfigProperty: true },
34
- },
35
- });
36
- });
37
-
38
- const renderComponent = (extras = {}) => {
39
- return render(
40
- <Panel
41
- model={model}
42
- configuration={configure}
43
- onChangeModel={onChange}
44
- onChangeConfiguration={onChange}
45
- groups={groups({ configure })}
46
- {...extras}
47
- />,
48
- );
49
- };
50
-
51
- describe('rendering', () => {
52
- it('renders settings panel', () => {
53
- renderComponent();
54
-
55
- expect(screen.getByText('Group 1')).toBeInTheDocument();
56
- });
57
-
58
- it('renders toggle settings', () => {
59
- renderComponent();
60
-
61
- // Toggle components render with Switch role in MUI v5
62
- const toggles = screen.getAllByRole('switch');
63
- expect(toggles.length).toBeGreaterThan(0);
64
- });
65
-
66
- it('conditionally renders radio buttons based on configuration', () => {
67
- renderComponent();
68
-
69
- // Should render radio when settingsOrientation is true
70
- expect(screen.getByText('Orientation')).toBeInTheDocument();
71
- });
72
-
73
- it('does not render radio buttons when disabled in configuration', () => {
74
- const disabledGroups = groups({
75
- configure: {
76
- ...configure,
77
- settingsOrientation: false,
78
- },
79
- });
80
-
81
- render(
82
- <Panel
83
- model={model}
84
- configuration={{ ...configure, settingsOrientation: false }}
85
- onChangeModel={onChange}
86
- onChangeConfiguration={onChange}
87
- groups={disabledGroups}
88
- />,
89
- );
90
-
91
- // Should not render radio when settingsOrientation is false
92
- expect(screen.queryByText('Orientation')).not.toBeInTheDocument();
93
- });
94
- });
95
- });
96
-
97
- // Utility function tests - these are simple unit tests that don't need RTL
98
- describe('toggle', () => {
99
- it('returns a toggle type object', () => {
100
- const setting = toggle('Label');
101
-
102
- expect(setting).toEqual({
103
- label: 'Label',
104
- type: 'toggle',
105
- isConfigProperty: false,
106
- disabled: false,
107
- });
108
- });
109
- });
110
-
111
- describe('radio', () => {
112
- it('returns a radio type object', () => {
113
- const setting = radio('Radio', ['one', 'two']);
114
-
115
- expect(setting).toEqual({
116
- label: 'Radio',
117
- type: 'radio',
118
- isConfigProperty: false,
119
- choices: [
120
- {
121
- label: 'one',
122
- value: 'one',
123
- },
124
- {
125
- label: 'two',
126
- value: 'two',
127
- },
128
- ],
129
- });
130
- });
131
- });
132
-
133
- describe('dropdown', () => {
134
- it('returns a dropdown type object', () => {
135
- const setting = dropdown('Dropdown', ['one', 'two']);
136
-
137
- expect(setting).toEqual({
138
- label: 'Dropdown',
139
- type: 'dropdown',
140
- isConfigProperty: false,
141
- choices: ['one', 'two'],
142
- });
143
- });
144
- });
145
-
146
- describe('numberField', () => {
147
- it('returns a numberField type object', () => {
148
- const setting = numberField('Number Field', { max: 12 }, true);
149
-
150
- expect(setting).toEqual({
151
- label: 'Number Field',
152
- type: 'numberField',
153
- isConfigProperty: true,
154
- max: 12,
155
- });
156
- });
157
- });
158
-
159
- describe('numberFields', () => {
160
- it('returns a numberFields type object', () => {
161
- const setting = numberFields('Number Fields', {
162
- one: {
163
- label: 'One',
164
- },
165
- two: {
166
- label: 'Two',
167
- },
168
- });
169
-
170
- expect(setting).toEqual({
171
- label: 'Number Fields',
172
- type: 'numberFields',
173
- fields: {
174
- one: {
175
- type: 'numberField',
176
- label: 'One',
177
- isConfigProperty: false,
178
- },
179
- two: {
180
- type: 'numberField',
181
- label: 'Two',
182
- isConfigProperty: false,
183
- },
184
- },
185
- });
186
- });
187
- });