@pie-lib/config-ui 13.0.4-next.31 → 13.0.4-next.34
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.
- package/CHANGELOG.json +32 -0
- package/CHANGELOG.md +2419 -0
- package/LICENSE.md +5 -0
- package/lib/alert-dialog.js +68 -0
- package/lib/alert-dialog.js.map +1 -0
- package/lib/checkbox.js +84 -0
- package/lib/checkbox.js.map +1 -0
- package/lib/choice-configuration/feedback-menu.js +129 -0
- package/lib/choice-configuration/feedback-menu.js.map +1 -0
- package/lib/choice-configuration/index.js +381 -0
- package/lib/choice-configuration/index.js.map +1 -0
- package/lib/choice-utils.js +42 -0
- package/lib/choice-utils.js.map +1 -0
- package/lib/feedback-config/feedback-selector.js +155 -0
- package/lib/feedback-config/feedback-selector.js.map +1 -0
- package/lib/feedback-config/group.js +61 -0
- package/lib/feedback-config/group.js.map +1 -0
- package/lib/feedback-config/index.js +146 -0
- package/lib/feedback-config/index.js.map +1 -0
- package/lib/form-section.js +44 -0
- package/lib/form-section.js.map +1 -0
- package/lib/help.js +106 -0
- package/lib/help.js.map +1 -0
- package/lib/index.js +186 -0
- package/lib/index.js.map +1 -0
- package/lib/input.js +106 -0
- package/lib/input.js.map +1 -0
- package/lib/inputs.js +105 -0
- package/lib/inputs.js.map +1 -0
- package/lib/langs.js +136 -0
- package/lib/langs.js.map +1 -0
- package/lib/layout/config-layout.js +137 -0
- package/lib/layout/config-layout.js.map +1 -0
- package/lib/layout/index.js +21 -0
- package/lib/layout/index.js.map +1 -0
- package/lib/layout/layout-contents.js +160 -0
- package/lib/layout/layout-contents.js.map +1 -0
- package/lib/layout/settings-box.js +57 -0
- package/lib/layout/settings-box.js.map +1 -0
- package/lib/mui-box/index.js +63 -0
- package/lib/mui-box/index.js.map +1 -0
- package/lib/number-text-field-custom.js +376 -0
- package/lib/number-text-field-custom.js.map +1 -0
- package/lib/number-text-field.js +229 -0
- package/lib/number-text-field.js.map +1 -0
- package/lib/radio-with-label.js +48 -0
- package/lib/radio-with-label.js.map +1 -0
- package/lib/settings/display-size.js +61 -0
- package/lib/settings/display-size.js.map +1 -0
- package/lib/settings/index.js +110 -0
- package/lib/settings/index.js.map +1 -0
- package/lib/settings/panel.js +392 -0
- package/lib/settings/panel.js.map +1 -0
- package/lib/settings/settings-radio-label.js +51 -0
- package/lib/settings/settings-radio-label.js.map +1 -0
- package/lib/settings/toggle.js +63 -0
- package/lib/settings/toggle.js.map +1 -0
- package/lib/tabs/index.js +75 -0
- package/lib/tabs/index.js.map +1 -0
- package/lib/tags-input/index.js +149 -0
- package/lib/tags-input/index.js.map +1 -0
- package/lib/two-choice.js +136 -0
- package/lib/two-choice.js.map +1 -0
- package/lib/with-stateful-model.js +61 -0
- package/lib/with-stateful-model.js.map +1 -0
- package/package.json +19 -33
- package/src/__tests__/alert-dialog.test.jsx +183 -0
- package/src/__tests__/checkbox.test.jsx +152 -0
- package/src/__tests__/choice-utils.test.js +12 -0
- package/src/__tests__/form-section.test.jsx +328 -0
- package/src/__tests__/help.test.jsx +184 -0
- package/src/__tests__/input.test.jsx +156 -0
- package/src/__tests__/langs.test.jsx +376 -0
- package/src/__tests__/number-text-field-custom.test.jsx +255 -0
- package/src/__tests__/number-text-field.test.jsx +263 -0
- package/src/__tests__/radio-with-label.test.jsx +155 -0
- package/src/__tests__/settings-panel.test.js +187 -0
- package/src/__tests__/settings.test.jsx +452 -0
- package/src/__tests__/tabs.test.jsx +188 -0
- package/src/__tests__/two-choice.test.js +110 -0
- package/src/__tests__/with-stateful-model.test.jsx +139 -0
- package/src/alert-dialog.jsx +75 -0
- package/src/checkbox.jsx +61 -0
- package/src/choice-configuration/__tests__/feedback-menu.test.jsx +151 -0
- package/src/choice-configuration/__tests__/index.test.jsx +234 -0
- package/src/choice-configuration/feedback-menu.jsx +96 -0
- package/src/choice-configuration/index.jsx +357 -0
- package/src/choice-utils.js +30 -0
- package/src/feedback-config/__tests__/feedback-config.test.jsx +141 -0
- package/src/feedback-config/__tests__/feedback-selector.test.jsx +97 -0
- package/src/feedback-config/feedback-selector.jsx +112 -0
- package/src/feedback-config/group.jsx +51 -0
- package/src/feedback-config/index.jsx +111 -0
- package/src/form-section.jsx +31 -0
- package/src/help.jsx +79 -0
- package/src/index.js +55 -0
- package/src/input.jsx +72 -0
- package/src/inputs.jsx +69 -0
- package/src/langs.jsx +111 -0
- package/src/layout/__tests__/config.layout.test.jsx +59 -0
- package/src/layout/__tests__/layout-content.test.jsx +3 -0
- package/src/layout/config-layout.jsx +103 -0
- package/src/layout/index.js +4 -0
- package/src/layout/layout-contents.jsx +117 -0
- package/src/layout/settings-box.jsx +32 -0
- package/src/mui-box/index.jsx +56 -0
- package/src/number-text-field-custom.jsx +333 -0
- package/src/number-text-field.jsx +215 -0
- package/src/radio-with-label.jsx +30 -0
- package/src/settings/display-size.jsx +53 -0
- package/src/settings/index.js +83 -0
- package/src/settings/panel.jsx +333 -0
- package/src/settings/settings-radio-label.jsx +32 -0
- package/src/settings/toggle.jsx +46 -0
- package/src/tabs/index.jsx +47 -0
- package/src/tags-input/__tests__/index.test.jsx +113 -0
- package/src/tags-input/index.jsx +116 -0
- package/src/two-choice.jsx +90 -0
- package/src/with-stateful-model.jsx +36 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -11
- package/dist/alert-dialog.d.ts +0 -44
- package/dist/alert-dialog.js +0 -47
- package/dist/checkbox.d.ts +0 -34
- package/dist/checkbox.js +0 -57
- package/dist/choice-configuration/feedback-menu.d.ts +0 -32
- package/dist/choice-configuration/feedback-menu.js +0 -85
- package/dist/choice-configuration/index.d.ts +0 -62
- package/dist/choice-configuration/index.js +0 -240
- package/dist/choice-utils.d.ts +0 -21
- package/dist/choice-utils.js +0 -15
- package/dist/feedback-config/feedback-selector.d.ts +0 -33
- package/dist/feedback-config/feedback-selector.js +0 -92
- package/dist/feedback-config/group.d.ts +0 -21
- package/dist/feedback-config/group.js +0 -33
- package/dist/feedback-config/index.d.ts +0 -48
- package/dist/feedback-config/index.js +0 -96
- package/dist/form-section.d.ts +0 -25
- package/dist/form-section.js +0 -25
- package/dist/fraction-to-number.d.ts +0 -7
- package/dist/fraction-to-number.js +0 -9
- package/dist/help.d.ts +0 -41
- package/dist/help.js +0 -61
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -34
- package/dist/input.d.ts +0 -29
- package/dist/input.js +0 -65
- package/dist/inputs.d.ts +0 -63
- package/dist/inputs.js +0 -70
- package/dist/langs.d.ts +0 -41
- package/dist/langs.js +0 -76
- package/dist/layout/config-layout.d.ts +0 -10
- package/dist/layout/config-layout.js +0 -75
- package/dist/layout/index.d.ts +0 -11
- package/dist/layout/index.js +0 -10
- package/dist/layout/layout-contents.d.ts +0 -21
- package/dist/layout/layout-contents.js +0 -70
- package/dist/layout/settings-box.d.ts +0 -19
- package/dist/layout/settings-box.js +0 -31
- package/dist/mui-box/index.d.ts +0 -21
- package/dist/mui-box/index.js +0 -47
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/extends.js +0 -12
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +0 -7
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +0 -12
- package/dist/node_modules/.bun/@babel_runtime@7.28.6/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +0 -8
- package/dist/node_modules/.bun/react-measure@2.5.2_6dbf9a050bc9aadb/node_modules/react-measure/dist/index.esm.js +0 -122
- package/dist/node_modules/.bun/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -276
- package/dist/number-text-field-custom.d.ts +0 -51
- package/dist/number-text-field-custom.js +0 -192
- package/dist/number-text-field.d.ts +0 -47
- package/dist/number-text-field.js +0 -122
- package/dist/radio-with-label.d.ts +0 -25
- package/dist/radio-with-label.js +0 -27
- package/dist/settings/display-size.d.ts +0 -26
- package/dist/settings/display-size.js +0 -45
- package/dist/settings/index.d.ts +0 -45
- package/dist/settings/index.js +0 -63
- package/dist/settings/panel.d.ts +0 -27
- package/dist/settings/panel.js +0 -201
- package/dist/settings/settings-radio-label.d.ts +0 -25
- package/dist/settings/settings-radio-label.js +0 -29
- package/dist/settings/toggle.d.ts +0 -25
- package/dist/settings/toggle.js +0 -33
- package/dist/tabs/index.d.ts +0 -22
- package/dist/tabs/index.js +0 -39
- package/dist/tags-input/index.d.ts +0 -21
- package/dist/tags-input/index.js +0 -83
- package/dist/two-choice.d.ts +0 -43
- package/dist/two-choice.js +0 -79
- package/dist/with-stateful-model.d.ts +0 -42
- package/dist/with-stateful-model.js +0 -32
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
});
|