@pie-lib/config-ui 11.30.3-next.2 → 11.30.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.
- package/CHANGELOG.md +7 -78
- package/lib/__tests__/alert-dialog.test.js +262 -0
- package/lib/__tests__/checkbox.test.js +227 -0
- package/lib/__tests__/choice-utils.test.js +14 -0
- package/lib/__tests__/form-section.test.js +252 -0
- package/lib/__tests__/help.test.js +270 -0
- package/lib/__tests__/input.test.js +268 -0
- package/lib/__tests__/langs.test.js +541 -0
- package/lib/__tests__/number-text-field-custom.test.js +362 -0
- package/lib/__tests__/number-text-field.test.js +421 -0
- package/lib/__tests__/radio-with-label.test.js +233 -0
- package/lib/__tests__/settings-panel.test.js +184 -0
- package/lib/__tests__/settings.test.js +653 -0
- package/lib/__tests__/tabs.test.js +211 -0
- package/lib/__tests__/two-choice.test.js +124 -0
- package/lib/__tests__/with-stateful-model.test.js +221 -0
- package/lib/alert-dialog.js +36 -43
- package/lib/alert-dialog.js.map +1 -1
- package/lib/checkbox.js +57 -72
- package/lib/checkbox.js.map +1 -1
- package/lib/choice-configuration/__tests__/feedback-menu.test.js +287 -0
- package/lib/choice-configuration/__tests__/index.test.js +253 -0
- package/lib/choice-configuration/feedback-menu.js +30 -65
- package/lib/choice-configuration/feedback-menu.js.map +1 -1
- package/lib/choice-configuration/index.js +203 -263
- package/lib/choice-configuration/index.js.map +1 -1
- package/lib/choice-utils.js +7 -19
- package/lib/choice-utils.js.map +1 -1
- package/lib/feedback-config/__tests__/feedback-config.test.js +201 -0
- package/lib/feedback-config/__tests__/feedback-selector.test.js +177 -0
- package/lib/feedback-config/feedback-selector.js +80 -116
- package/lib/feedback-config/feedback-selector.js.map +1 -1
- package/lib/feedback-config/group.js +27 -41
- package/lib/feedback-config/group.js.map +1 -1
- package/lib/feedback-config/index.js +48 -91
- package/lib/feedback-config/index.js.map +1 -1
- package/lib/form-section.js +32 -34
- package/lib/form-section.js.map +1 -1
- package/lib/help.js +40 -81
- package/lib/help.js.map +1 -1
- package/lib/index.js +2 -32
- package/lib/index.js.map +1 -1
- package/lib/input.js +22 -55
- package/lib/input.js.map +1 -1
- package/lib/inputs.js +62 -96
- package/lib/inputs.js.map +1 -1
- package/lib/langs.js +59 -102
- package/lib/langs.js.map +1 -1
- package/lib/layout/__tests__/config.layout.test.js +70 -0
- package/lib/layout/__tests__/layout-content.test.js +6 -0
- package/lib/layout/config-layout.js +41 -71
- package/lib/layout/config-layout.js.map +1 -1
- package/lib/layout/index.js +1 -4
- package/lib/layout/index.js.map +1 -1
- package/lib/layout/layout-contents.js +73 -104
- package/lib/layout/layout-contents.js.map +1 -1
- package/lib/layout/settings-box.js +28 -57
- package/lib/layout/settings-box.js.map +1 -1
- package/lib/mui-box/index.js +42 -58
- package/lib/mui-box/index.js.map +1 -1
- package/lib/number-text-field-custom.js +80 -162
- package/lib/number-text-field-custom.js.map +1 -1
- package/lib/number-text-field.js +81 -115
- package/lib/number-text-field.js.map +1 -1
- package/lib/radio-with-label.js +31 -32
- package/lib/radio-with-label.js.map +1 -1
- package/lib/settings/display-size.js +17 -33
- package/lib/settings/display-size.js.map +1 -1
- package/lib/settings/index.js +15 -48
- package/lib/settings/index.js.map +1 -1
- package/lib/settings/panel.js +160 -230
- package/lib/settings/panel.js.map +1 -1
- package/lib/settings/settings-radio-label.js +29 -31
- package/lib/settings/settings-radio-label.js.map +1 -1
- package/lib/settings/toggle.js +36 -47
- package/lib/settings/toggle.js.map +1 -1
- package/lib/tabs/index.js +23 -58
- package/lib/tabs/index.js.map +1 -1
- package/lib/tags-input/__tests__/index.test.js +183 -0
- package/lib/tags-input/index.js +51 -100
- package/lib/tags-input/index.js.map +1 -1
- package/lib/two-choice.js +47 -91
- package/lib/two-choice.js.map +1 -1
- package/lib/with-stateful-model.js +9 -32
- package/lib/with-stateful-model.js.map +1 -1
- package/package.json +12 -20
- package/src/__tests__/alert-dialog.test.jsx +283 -0
- package/src/__tests__/checkbox.test.jsx +249 -0
- package/src/__tests__/form-section.test.jsx +334 -0
- package/src/__tests__/help.test.jsx +184 -0
- package/src/__tests__/input.test.jsx +192 -0
- package/src/__tests__/langs.test.jsx +435 -15
- package/src/__tests__/number-text-field-custom.test.jsx +438 -0
- package/src/__tests__/number-text-field.test.jsx +295 -102
- package/src/__tests__/radio-with-label.test.jsx +259 -0
- package/src/__tests__/settings-panel.test.js +66 -83
- package/src/__tests__/settings.test.jsx +515 -0
- package/src/__tests__/tabs.test.jsx +193 -0
- package/src/__tests__/two-choice.test.js +104 -18
- package/src/__tests__/with-stateful-model.test.jsx +145 -0
- package/src/alert-dialog.jsx +21 -19
- package/src/checkbox.jsx +42 -46
- package/src/choice-configuration/__tests__/feedback-menu.test.jsx +157 -4
- package/src/choice-configuration/__tests__/index.test.jsx +198 -56
- package/src/choice-configuration/feedback-menu.jsx +6 -6
- package/src/choice-configuration/index.jsx +201 -196
- package/src/feedback-config/__tests__/feedback-config.test.jsx +130 -60
- package/src/feedback-config/__tests__/feedback-selector.test.jsx +87 -40
- package/src/feedback-config/feedback-selector.jsx +52 -53
- package/src/feedback-config/group.jsx +21 -22
- package/src/feedback-config/index.jsx +27 -29
- package/src/form-section.jsx +26 -18
- package/src/help.jsx +20 -28
- package/src/input.jsx +1 -1
- package/src/inputs.jsx +34 -50
- package/src/langs.jsx +41 -46
- package/src/layout/__tests__/config.layout.test.jsx +55 -38
- package/src/layout/config-layout.jsx +38 -32
- package/src/layout/layout-contents.jsx +38 -39
- package/src/layout/settings-box.jsx +16 -19
- package/src/mui-box/index.jsx +35 -43
- package/src/number-text-field-custom.jsx +30 -36
- package/src/number-text-field.jsx +45 -29
- package/src/radio-with-label.jsx +25 -13
- package/src/settings/display-size.jsx +12 -11
- package/src/settings/panel.jsx +97 -91
- package/src/settings/settings-radio-label.jsx +25 -13
- package/src/settings/toggle.jsx +30 -29
- package/src/tabs/index.jsx +8 -8
- package/src/tags-input/__tests__/index.test.jsx +88 -37
- package/src/tags-input/index.jsx +35 -38
- package/src/two-choice.jsx +15 -19
- package/esm/index.css +0 -847
- package/esm/index.js +0 -213950
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/langs.test.jsx.snap +0 -32
- package/src/__tests__/__snapshots__/settings-panel.test.js.snap +0 -115
- package/src/__tests__/__snapshots__/two-choice.test.js.snap +0 -171
- package/src/choice-configuration/__tests__/__snapshots__/feedback-menu.test.jsx.snap +0 -51
- package/src/choice-configuration/__tests__/__snapshots__/index.test.jsx.snap +0 -519
- package/src/feedback-config/__tests__/__snapshots__/feedback-config.test.jsx.snap +0 -27
- package/src/feedback-config/__tests__/__snapshots__/feedback-selector.test.jsx.snap +0 -38
- package/src/layout/__tests__/__snapshots__/config.layout.test.jsx.snap +0 -59
- package/src/tags-input/__tests__/__snapshots__/index.test.jsx.snap +0 -170
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import Toggle from '../settings/toggle';
|
|
5
|
+
import DisplaySize from '../settings/display-size';
|
|
6
|
+
import SettingsRadioLabel from '../settings/settings-radio-label';
|
|
7
|
+
import { Panel } from '../settings/panel';
|
|
8
|
+
|
|
9
|
+
describe('Settings Components', () => {
|
|
10
|
+
describe('Toggle', () => {
|
|
11
|
+
it('renders toggle with label', () => {
|
|
12
|
+
const toggle = jest.fn();
|
|
13
|
+
render(<Toggle label="Enable Feature" checked={false} toggle={toggle} />);
|
|
14
|
+
|
|
15
|
+
expect(screen.getByText('Enable Feature')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('DisplaySize', () => {
|
|
20
|
+
const defaultProps = {
|
|
21
|
+
size: { width: 500, height: 400 },
|
|
22
|
+
label: 'Display Size',
|
|
23
|
+
onChange: jest.fn(),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('renders label and input fields', () => {
|
|
31
|
+
render(<DisplaySize {...defaultProps} />);
|
|
32
|
+
|
|
33
|
+
expect(screen.getByText('Display Size')).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByLabelText('Width')).toBeInTheDocument();
|
|
35
|
+
expect(screen.getByLabelText('Height')).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('displays width and height values', () => {
|
|
39
|
+
render(<DisplaySize {...defaultProps} />);
|
|
40
|
+
|
|
41
|
+
const widthInput = screen.getByLabelText('Width');
|
|
42
|
+
const heightInput = screen.getByLabelText('Height');
|
|
43
|
+
|
|
44
|
+
expect(widthInput).toHaveValue(500);
|
|
45
|
+
expect(heightInput).toHaveValue(400);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('calls onChange when width changes', async () => {
|
|
49
|
+
const user = userEvent.setup();
|
|
50
|
+
const onChange = jest.fn();
|
|
51
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
52
|
+
|
|
53
|
+
const widthInput = screen.getByLabelText('Width');
|
|
54
|
+
await user.clear(widthInput);
|
|
55
|
+
await user.type(widthInput, '600');
|
|
56
|
+
fireEvent.blur(widthInput);
|
|
57
|
+
|
|
58
|
+
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ width: 600 }));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('calls onChange when height changes', async () => {
|
|
62
|
+
const user = userEvent.setup();
|
|
63
|
+
const onChange = jest.fn();
|
|
64
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
65
|
+
|
|
66
|
+
const heightInput = screen.getByLabelText('Height');
|
|
67
|
+
await user.clear(heightInput);
|
|
68
|
+
await user.type(heightInput, '500');
|
|
69
|
+
fireEvent.blur(heightInput);
|
|
70
|
+
|
|
71
|
+
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ height: 500 }));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('maintains other dimension when one changes', async () => {
|
|
75
|
+
const user = userEvent.setup();
|
|
76
|
+
const onChange = jest.fn();
|
|
77
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
78
|
+
|
|
79
|
+
const widthInput = screen.getByLabelText('Width');
|
|
80
|
+
await user.clear(widthInput);
|
|
81
|
+
await user.type(widthInput, '700');
|
|
82
|
+
fireEvent.blur(widthInput);
|
|
83
|
+
|
|
84
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
85
|
+
width: 700,
|
|
86
|
+
height: 400,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('enforces min value constraint', async () => {
|
|
91
|
+
const user = userEvent.setup();
|
|
92
|
+
const onChange = jest.fn();
|
|
93
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
94
|
+
|
|
95
|
+
const widthInput = screen.getByLabelText('Width');
|
|
96
|
+
await user.clear(widthInput);
|
|
97
|
+
await user.type(widthInput, '100');
|
|
98
|
+
fireEvent.blur(widthInput);
|
|
99
|
+
|
|
100
|
+
// Should clamp to minimum 150
|
|
101
|
+
expect(widthInput).toHaveValue(150);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('enforces max value constraint', async () => {
|
|
105
|
+
const user = userEvent.setup();
|
|
106
|
+
const onChange = jest.fn();
|
|
107
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
108
|
+
|
|
109
|
+
const widthInput = screen.getByLabelText('Width');
|
|
110
|
+
await user.clear(widthInput);
|
|
111
|
+
await user.type(widthInput, '2000');
|
|
112
|
+
fireEvent.blur(widthInput);
|
|
113
|
+
|
|
114
|
+
// Should clamp to maximum 1000
|
|
115
|
+
expect(widthInput).toHaveValue(1000);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('updates when size prop changes', () => {
|
|
119
|
+
const { rerender } = render(<DisplaySize {...defaultProps} />);
|
|
120
|
+
|
|
121
|
+
let widthInput = screen.getByLabelText('Width');
|
|
122
|
+
expect(widthInput).toHaveValue(500);
|
|
123
|
+
|
|
124
|
+
rerender(
|
|
125
|
+
<DisplaySize {...defaultProps} size={{ width: 800, height: 600 }} />
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
widthInput = screen.getByLabelText('Width');
|
|
129
|
+
expect(widthInput).toHaveValue(800);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('handles boundary values at minimum', async () => {
|
|
133
|
+
const user = userEvent.setup();
|
|
134
|
+
const onChange = jest.fn();
|
|
135
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
136
|
+
|
|
137
|
+
const widthInput = screen.getByLabelText('Width');
|
|
138
|
+
const heightInput = screen.getByLabelText('Height');
|
|
139
|
+
|
|
140
|
+
await user.clear(widthInput);
|
|
141
|
+
await user.type(widthInput, '150');
|
|
142
|
+
fireEvent.blur(widthInput);
|
|
143
|
+
|
|
144
|
+
await user.clear(heightInput);
|
|
145
|
+
await user.type(heightInput, '150');
|
|
146
|
+
fireEvent.blur(heightInput);
|
|
147
|
+
|
|
148
|
+
expect(widthInput).toHaveValue(150);
|
|
149
|
+
expect(heightInput).toHaveValue(150);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('handles boundary values at maximum', async () => {
|
|
153
|
+
const user = userEvent.setup();
|
|
154
|
+
const onChange = jest.fn();
|
|
155
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
156
|
+
|
|
157
|
+
const widthInput = screen.getByLabelText('Width');
|
|
158
|
+
const heightInput = screen.getByLabelText('Height');
|
|
159
|
+
|
|
160
|
+
await user.clear(widthInput);
|
|
161
|
+
await user.type(widthInput, '1000');
|
|
162
|
+
fireEvent.blur(widthInput);
|
|
163
|
+
|
|
164
|
+
await user.clear(heightInput);
|
|
165
|
+
await user.type(heightInput, '1000');
|
|
166
|
+
fireEvent.blur(heightInput);
|
|
167
|
+
|
|
168
|
+
expect(widthInput).toHaveValue(1000);
|
|
169
|
+
expect(heightInput).toHaveValue(1000);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('handles decimal input values', async () => {
|
|
173
|
+
const user = userEvent.setup();
|
|
174
|
+
const onChange = jest.fn();
|
|
175
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
176
|
+
|
|
177
|
+
const widthInput = screen.getByLabelText('Width');
|
|
178
|
+
await user.clear(widthInput);
|
|
179
|
+
await user.type(widthInput, '500.5');
|
|
180
|
+
fireEvent.blur(widthInput);
|
|
181
|
+
|
|
182
|
+
expect(widthInput).toBeInTheDocument();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('handles empty input and resets to min', async () => {
|
|
186
|
+
const user = userEvent.setup();
|
|
187
|
+
const onChange = jest.fn();
|
|
188
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
189
|
+
|
|
190
|
+
const widthInput = screen.getByLabelText('Width');
|
|
191
|
+
await user.clear(widthInput);
|
|
192
|
+
fireEvent.blur(widthInput);
|
|
193
|
+
|
|
194
|
+
// Should reset to minimum value
|
|
195
|
+
expect(widthInput).toHaveValue(150);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('handles rapid width and height changes', async () => {
|
|
199
|
+
const user = userEvent.setup();
|
|
200
|
+
const onChange = jest.fn();
|
|
201
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
202
|
+
|
|
203
|
+
const widthInput = screen.getByLabelText('Width');
|
|
204
|
+
|
|
205
|
+
await user.clear(widthInput);
|
|
206
|
+
await user.type(widthInput, '6');
|
|
207
|
+
await user.type(widthInput, '0');
|
|
208
|
+
await user.type(widthInput, '0');
|
|
209
|
+
fireEvent.blur(widthInput);
|
|
210
|
+
|
|
211
|
+
expect(onChange).toHaveBeenCalled();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('clamps height at both boundaries', async () => {
|
|
215
|
+
const user = userEvent.setup();
|
|
216
|
+
const onChange = jest.fn();
|
|
217
|
+
render(<DisplaySize {...defaultProps} onChange={onChange} />);
|
|
218
|
+
|
|
219
|
+
const heightInput = screen.getByLabelText('Height');
|
|
220
|
+
|
|
221
|
+
// Test below min
|
|
222
|
+
await user.clear(heightInput);
|
|
223
|
+
await user.type(heightInput, '50');
|
|
224
|
+
fireEvent.blur(heightInput);
|
|
225
|
+
expect(heightInput).toHaveValue(150);
|
|
226
|
+
|
|
227
|
+
// Test above max
|
|
228
|
+
await user.clear(heightInput);
|
|
229
|
+
await user.type(heightInput, '2500');
|
|
230
|
+
fireEvent.blur(heightInput);
|
|
231
|
+
expect(heightInput).toHaveValue(1000);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('displays custom label text', () => {
|
|
235
|
+
render(
|
|
236
|
+
<DisplaySize
|
|
237
|
+
size={{ width: 500, height: 400 }}
|
|
238
|
+
label="Custom Size Settings"
|
|
239
|
+
onChange={jest.fn()}
|
|
240
|
+
/>
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
expect(screen.getByText('Custom Size Settings')).toBeInTheDocument();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('renders with variant outlined', () => {
|
|
247
|
+
const { container } = render(<DisplaySize {...defaultProps} />);
|
|
248
|
+
|
|
249
|
+
const inputs = container.querySelectorAll('input');
|
|
250
|
+
expect(inputs.length).toBe(2);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe('SettingsRadioLabel', () => {
|
|
255
|
+
it('renders radio label', () => {
|
|
256
|
+
const onChange = jest.fn();
|
|
257
|
+
render(
|
|
258
|
+
<SettingsRadioLabel
|
|
259
|
+
label="Option 1"
|
|
260
|
+
value="option1"
|
|
261
|
+
checked={false}
|
|
262
|
+
onChange={onChange}
|
|
263
|
+
/>
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
expect(screen.getByText('Option 1')).toBeInTheDocument();
|
|
267
|
+
expect(screen.getByRole('radio')).toBeInTheDocument();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('renders checked state', () => {
|
|
271
|
+
const onChange = jest.fn();
|
|
272
|
+
render(
|
|
273
|
+
<SettingsRadioLabel
|
|
274
|
+
label="Option 1"
|
|
275
|
+
value="option1"
|
|
276
|
+
checked={true}
|
|
277
|
+
onChange={onChange}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
const radio = screen.getByRole('radio');
|
|
282
|
+
expect(radio).toBeChecked();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('renders unchecked state', () => {
|
|
286
|
+
const onChange = jest.fn();
|
|
287
|
+
render(
|
|
288
|
+
<SettingsRadioLabel
|
|
289
|
+
label="Option 1"
|
|
290
|
+
value="option1"
|
|
291
|
+
checked={false}
|
|
292
|
+
onChange={onChange}
|
|
293
|
+
/>
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const radio = screen.getByRole('radio');
|
|
297
|
+
expect(radio).not.toBeChecked();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('calls onChange when radio is clicked', async () => {
|
|
301
|
+
const user = userEvent.setup();
|
|
302
|
+
const onChange = jest.fn();
|
|
303
|
+
render(
|
|
304
|
+
<SettingsRadioLabel
|
|
305
|
+
label="Option 1"
|
|
306
|
+
value="option1"
|
|
307
|
+
checked={false}
|
|
308
|
+
onChange={onChange}
|
|
309
|
+
/>
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
const radio = screen.getByRole('radio');
|
|
313
|
+
await user.click(radio);
|
|
314
|
+
|
|
315
|
+
expect(onChange).toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('displays label text correctly', () => {
|
|
319
|
+
const onChange = jest.fn();
|
|
320
|
+
const labelText = 'Custom Option Label';
|
|
321
|
+
render(
|
|
322
|
+
<SettingsRadioLabel
|
|
323
|
+
label={labelText}
|
|
324
|
+
value="custom"
|
|
325
|
+
checked={false}
|
|
326
|
+
onChange={onChange}
|
|
327
|
+
/>
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
expect(screen.getByText(labelText)).toBeInTheDocument();
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('Panel', () => {
|
|
335
|
+
const defaultProps = {
|
|
336
|
+
model: { toggleSetting: true, numberValue: 5 },
|
|
337
|
+
configuration: { configValue: 'test' },
|
|
338
|
+
groups: {
|
|
339
|
+
'General Settings': {
|
|
340
|
+
toggleSetting: {
|
|
341
|
+
type: 'toggle',
|
|
342
|
+
label: 'Enable Feature',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
onChangeModel: jest.fn(),
|
|
347
|
+
onChangeConfiguration: jest.fn(),
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
beforeEach(() => {
|
|
351
|
+
jest.clearAllMocks();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('renders panel with group label', () => {
|
|
355
|
+
render(<Panel {...defaultProps} />);
|
|
356
|
+
expect(screen.getByText('General Settings')).toBeInTheDocument();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('renders empty when groups is undefined', () => {
|
|
360
|
+
const { container } = render(
|
|
361
|
+
<Panel
|
|
362
|
+
{...defaultProps}
|
|
363
|
+
groups={undefined}
|
|
364
|
+
/>
|
|
365
|
+
);
|
|
366
|
+
expect(container.firstChild.children.length).toBe(0);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('renders empty when groups is empty', () => {
|
|
370
|
+
const { container } = render(
|
|
371
|
+
<Panel
|
|
372
|
+
{...defaultProps}
|
|
373
|
+
groups={{}}
|
|
374
|
+
/>
|
|
375
|
+
);
|
|
376
|
+
expect(container.firstChild.children.length).toBe(0);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('calls onChangeModel when model changes', async () => {
|
|
380
|
+
const user = userEvent.setup();
|
|
381
|
+
const onChangeModel = jest.fn();
|
|
382
|
+
const { container } = render(
|
|
383
|
+
<Panel
|
|
384
|
+
{...defaultProps}
|
|
385
|
+
onChangeModel={onChangeModel}
|
|
386
|
+
/>
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
const switchElement = container.querySelector('input[type="checkbox"]');
|
|
390
|
+
await user.click(switchElement);
|
|
391
|
+
|
|
392
|
+
expect(onChangeModel).toHaveBeenCalled();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('calls onChangeConfiguration when configuration changes', async () => {
|
|
396
|
+
const user = userEvent.setup();
|
|
397
|
+
const onChangeConfiguration = jest.fn();
|
|
398
|
+
const { container } = render(
|
|
399
|
+
<Panel
|
|
400
|
+
{...defaultProps}
|
|
401
|
+
groups={{
|
|
402
|
+
'Config Group': {
|
|
403
|
+
configValue: {
|
|
404
|
+
type: 'toggle',
|
|
405
|
+
label: 'Config Toggle',
|
|
406
|
+
isConfigProperty: true,
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
}}
|
|
410
|
+
onChangeConfiguration={onChangeConfiguration}
|
|
411
|
+
/>
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
const switchElement = container.querySelector('input[type="checkbox"]');
|
|
415
|
+
await user.click(switchElement);
|
|
416
|
+
|
|
417
|
+
expect(onChangeConfiguration).toHaveBeenCalled();
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('renders with modal when provided', () => {
|
|
421
|
+
const modal = <div data-testid="test-modal">Modal Content</div>;
|
|
422
|
+
render(
|
|
423
|
+
<Panel
|
|
424
|
+
{...defaultProps}
|
|
425
|
+
modal={modal}
|
|
426
|
+
/>
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
expect(screen.getByTestId('test-modal')).toBeInTheDocument();
|
|
430
|
+
expect(screen.getByText('Modal Content')).toBeInTheDocument();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('renders multiple groups', () => {
|
|
434
|
+
render(
|
|
435
|
+
<Panel
|
|
436
|
+
{...defaultProps}
|
|
437
|
+
groups={{
|
|
438
|
+
'Group One': {
|
|
439
|
+
setting1: {
|
|
440
|
+
type: 'toggle',
|
|
441
|
+
label: 'Setting One',
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
'Group Two': {
|
|
445
|
+
setting2: {
|
|
446
|
+
type: 'toggle',
|
|
447
|
+
label: 'Setting Two',
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
}}
|
|
451
|
+
model={{ setting1: true, setting2: false }}
|
|
452
|
+
/>
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
expect(screen.getByText('Group One')).toBeInTheDocument();
|
|
456
|
+
expect(screen.getByText('Group Two')).toBeInTheDocument();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('uses default callbacks when not provided', () => {
|
|
460
|
+
const { container } = render(
|
|
461
|
+
<Panel
|
|
462
|
+
model={{ test: true }}
|
|
463
|
+
groups={{
|
|
464
|
+
'Test Group': {
|
|
465
|
+
test: { type: 'toggle', label: 'Test' },
|
|
466
|
+
},
|
|
467
|
+
}}
|
|
468
|
+
/>
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('filters out empty groups', () => {
|
|
475
|
+
const { container } = render(
|
|
476
|
+
<Panel
|
|
477
|
+
{...defaultProps}
|
|
478
|
+
groups={{
|
|
479
|
+
'Empty Group': {},
|
|
480
|
+
'General Settings': {
|
|
481
|
+
toggleSetting: {
|
|
482
|
+
type: 'toggle',
|
|
483
|
+
label: 'Enable Feature',
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
}}
|
|
487
|
+
model={{ toggleSetting: true }}
|
|
488
|
+
/>
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
expect(screen.getByText('General Settings')).toBeInTheDocument();
|
|
492
|
+
expect(screen.queryByText('Empty Group')).not.toBeInTheDocument();
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('renders with null model', () => {
|
|
496
|
+
const { container } = render(
|
|
497
|
+
<Panel
|
|
498
|
+
model={null}
|
|
499
|
+
configuration={{}}
|
|
500
|
+
groups={{
|
|
501
|
+
'General Settings': {
|
|
502
|
+
toggleSetting: {
|
|
503
|
+
type: 'toggle',
|
|
504
|
+
label: 'Enable Feature',
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
}}
|
|
508
|
+
onChangeModel={jest.fn()}
|
|
509
|
+
/>
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
expect(screen.getByText('General Settings')).toBeInTheDocument();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { Tabs } from '../tabs';
|
|
5
|
+
|
|
6
|
+
describe('Tabs Component', () => {
|
|
7
|
+
it('renders tabs with correct titles', () => {
|
|
8
|
+
render(
|
|
9
|
+
<Tabs>
|
|
10
|
+
<div title="Tab 1">Content 1</div>
|
|
11
|
+
<div title="Tab 2">Content 2</div>
|
|
12
|
+
<div title="Tab 3">Content 3</div>
|
|
13
|
+
</Tabs>,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(screen.getByText('Tab 1')).toBeInTheDocument();
|
|
17
|
+
expect(screen.getByText('Tab 2')).toBeInTheDocument();
|
|
18
|
+
expect(screen.getByText('Tab 3')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('renders first tab content by default', () => {
|
|
22
|
+
render(
|
|
23
|
+
<Tabs>
|
|
24
|
+
<div title="Tab 1">Content 1</div>
|
|
25
|
+
<div title="Tab 2">Content 2</div>
|
|
26
|
+
<div title="Tab 3">Content 3</div>
|
|
27
|
+
</Tabs>,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
expect(screen.getByText('Content 1')).toBeInTheDocument();
|
|
31
|
+
expect(screen.queryByText('Content 2')).not.toBeInTheDocument();
|
|
32
|
+
expect(screen.queryByText('Content 3')).not.toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('switches to selected tab when clicked', async () => {
|
|
36
|
+
const user = userEvent.setup();
|
|
37
|
+
render(
|
|
38
|
+
<Tabs>
|
|
39
|
+
<div title="Tab 1">Content 1</div>
|
|
40
|
+
<div title="Tab 2">Content 2</div>
|
|
41
|
+
<div title="Tab 3">Content 3</div>
|
|
42
|
+
</Tabs>,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const tab2 = screen.getByRole('tab', { name: 'Tab 2' });
|
|
46
|
+
await user.click(tab2);
|
|
47
|
+
|
|
48
|
+
expect(screen.queryByText('Content 1')).not.toBeInTheDocument();
|
|
49
|
+
expect(screen.getByText('Content 2')).toBeInTheDocument();
|
|
50
|
+
expect(screen.queryByText('Content 3')).not.toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('displays correct content when multiple tabs are clicked', async () => {
|
|
54
|
+
const user = userEvent.setup();
|
|
55
|
+
render(
|
|
56
|
+
<Tabs>
|
|
57
|
+
<div title="Tab 1">Content 1</div>
|
|
58
|
+
<div title="Tab 2">Content 2</div>
|
|
59
|
+
<div title="Tab 3">Content 3</div>
|
|
60
|
+
</Tabs>,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await user.click(screen.getByRole('tab', { name: 'Tab 2' }));
|
|
64
|
+
expect(screen.getByText('Content 2')).toBeInTheDocument();
|
|
65
|
+
|
|
66
|
+
await user.click(screen.getByRole('tab', { name: 'Tab 3' }));
|
|
67
|
+
expect(screen.getByText('Content 3')).toBeInTheDocument();
|
|
68
|
+
|
|
69
|
+
await user.click(screen.getByRole('tab', { name: 'Tab 1' }));
|
|
70
|
+
expect(screen.getByText('Content 1')).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('applies custom className to root element', () => {
|
|
74
|
+
const { container } = render(
|
|
75
|
+
<Tabs className="custom-tabs-class">
|
|
76
|
+
<div title="Tab 1">Content 1</div>
|
|
77
|
+
</Tabs>,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const rootDiv = container.querySelector('.custom-tabs-class');
|
|
81
|
+
expect(rootDiv).toBeInTheDocument();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
it('handles tabs without title prop gracefully', () => {
|
|
86
|
+
render(
|
|
87
|
+
<Tabs>
|
|
88
|
+
<div title="Tab 1">Content 1</div>
|
|
89
|
+
<div>No Title Child</div>
|
|
90
|
+
<div title="Tab 2">Content 2</div>
|
|
91
|
+
</Tabs>,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const tabs = screen.getAllByRole('tab');
|
|
95
|
+
// Should only have 2 tabs since one doesn't have a title
|
|
96
|
+
expect(tabs).toHaveLength(2);
|
|
97
|
+
expect(screen.getByText('Tab 1')).toBeInTheDocument();
|
|
98
|
+
expect(screen.getByText('Tab 2')).toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('handles null children gracefully', () => {
|
|
102
|
+
render(
|
|
103
|
+
<Tabs>
|
|
104
|
+
<div title="Tab 1">Content 1</div>
|
|
105
|
+
{null}
|
|
106
|
+
<div title="Tab 2">Content 2</div>
|
|
107
|
+
</Tabs>,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const tabs = screen.getAllByRole('tab');
|
|
111
|
+
expect(tabs).toHaveLength(2);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('handles complex content in tabs', () => {
|
|
115
|
+
render(
|
|
116
|
+
<Tabs>
|
|
117
|
+
<div title="Tab 1">
|
|
118
|
+
<div>
|
|
119
|
+
<h2>Tab 1 Header</h2>
|
|
120
|
+
<p>Tab 1 description</p>
|
|
121
|
+
<button>Button in Tab 1</button>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
<div title="Tab 2">
|
|
125
|
+
<div>
|
|
126
|
+
<h2>Tab 2 Header</h2>
|
|
127
|
+
<input type="text" placeholder="Input in Tab 2" />
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
</Tabs>,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(screen.getByText('Tab 1 Header')).toBeInTheDocument();
|
|
134
|
+
expect(screen.getByRole('button', { name: 'Button in Tab 1' })).toBeInTheDocument();
|
|
135
|
+
|
|
136
|
+
const tab2 = screen.getByRole('tab', { name: 'Tab 2' });
|
|
137
|
+
expect(tab2).toBeInTheDocument();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('renders all tabs in MuiTabs component', () => {
|
|
141
|
+
const { container } = render(
|
|
142
|
+
<Tabs>
|
|
143
|
+
<div title="Tab A">Content A</div>
|
|
144
|
+
<div title="Tab B">Content B</div>
|
|
145
|
+
<div title="Tab C">Content C</div>
|
|
146
|
+
</Tabs>,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const tabsComponent = container.querySelector('[role="tablist"]');
|
|
150
|
+
expect(tabsComponent).toBeInTheDocument();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('applies correct value prop to MuiTabs', async () => {
|
|
154
|
+
const user = userEvent.setup();
|
|
155
|
+
render(
|
|
156
|
+
<Tabs>
|
|
157
|
+
<div title="Tab 1">Content 1</div>
|
|
158
|
+
<div title="Tab 2">Content 2</div>
|
|
159
|
+
</Tabs>,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// Initially first tab should be selected (value 0)
|
|
163
|
+
const tab1 = screen.getByRole('tab', { name: 'Tab 1' });
|
|
164
|
+
expect(tab1).toHaveAttribute('aria-selected', 'true');
|
|
165
|
+
|
|
166
|
+
// Click second tab
|
|
167
|
+
await user.click(screen.getByRole('tab', { name: 'Tab 2' }));
|
|
168
|
+
const tab2 = screen.getByRole('tab', { name: 'Tab 2' });
|
|
169
|
+
expect(tab2).toHaveAttribute('aria-selected', 'true');
|
|
170
|
+
expect(tab1).toHaveAttribute('aria-selected', 'false');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('renders with empty children array', () => {
|
|
174
|
+
const { container } = render(<Tabs>{[]}</Tabs>);
|
|
175
|
+
expect(container).toBeInTheDocument();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('handles long tab titles', () => {
|
|
179
|
+
render(
|
|
180
|
+
<Tabs>
|
|
181
|
+
<div title="This is a very long tab title that should still render correctly">
|
|
182
|
+
Content 1
|
|
183
|
+
</div>
|
|
184
|
+
<div title="Short">Content 2</div>
|
|
185
|
+
</Tabs>,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(
|
|
189
|
+
screen.getByText('This is a very long tab title that should still render correctly'),
|
|
190
|
+
).toBeInTheDocument();
|
|
191
|
+
expect(screen.getByText('Short')).toBeInTheDocument();
|
|
192
|
+
});
|
|
193
|
+
});
|