@pie-lib/config-ui 11.30.3-next.2 → 11.30.3-next.203

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 (123) hide show
  1. package/CHANGELOG.md +19 -67
  2. package/lib/alert-dialog.js +35 -42
  3. package/lib/alert-dialog.js.map +1 -1
  4. package/lib/checkbox.js +56 -71
  5. package/lib/checkbox.js.map +1 -1
  6. package/lib/choice-configuration/feedback-menu.js +29 -64
  7. package/lib/choice-configuration/feedback-menu.js.map +1 -1
  8. package/lib/choice-configuration/index.js +202 -262
  9. package/lib/choice-configuration/index.js.map +1 -1
  10. package/lib/choice-utils.js +6 -18
  11. package/lib/choice-utils.js.map +1 -1
  12. package/lib/feedback-config/feedback-selector.js +79 -115
  13. package/lib/feedback-config/feedback-selector.js.map +1 -1
  14. package/lib/feedback-config/group.js +26 -40
  15. package/lib/feedback-config/group.js.map +1 -1
  16. package/lib/feedback-config/index.js +47 -90
  17. package/lib/feedback-config/index.js.map +1 -1
  18. package/lib/form-section.js +31 -33
  19. package/lib/form-section.js.map +1 -1
  20. package/lib/help.js +39 -80
  21. package/lib/help.js.map +1 -1
  22. package/lib/index.js +1 -31
  23. package/lib/index.js.map +1 -1
  24. package/lib/input.js +21 -54
  25. package/lib/input.js.map +1 -1
  26. package/lib/inputs.js +61 -95
  27. package/lib/inputs.js.map +1 -1
  28. package/lib/langs.js +58 -101
  29. package/lib/langs.js.map +1 -1
  30. package/lib/layout/config-layout.js +40 -70
  31. package/lib/layout/config-layout.js.map +1 -1
  32. package/lib/layout/index.js +0 -3
  33. package/lib/layout/index.js.map +1 -1
  34. package/lib/layout/layout-contents.js +72 -103
  35. package/lib/layout/layout-contents.js.map +1 -1
  36. package/lib/layout/settings-box.js +27 -56
  37. package/lib/layout/settings-box.js.map +1 -1
  38. package/lib/mui-box/index.js +41 -57
  39. package/lib/mui-box/index.js.map +1 -1
  40. package/lib/number-text-field-custom.js +79 -161
  41. package/lib/number-text-field-custom.js.map +1 -1
  42. package/lib/number-text-field.js +80 -114
  43. package/lib/number-text-field.js.map +1 -1
  44. package/lib/radio-with-label.js +30 -31
  45. package/lib/radio-with-label.js.map +1 -1
  46. package/lib/settings/display-size.js +16 -32
  47. package/lib/settings/display-size.js.map +1 -1
  48. package/lib/settings/index.js +14 -47
  49. package/lib/settings/index.js.map +1 -1
  50. package/lib/settings/panel.js +159 -229
  51. package/lib/settings/panel.js.map +1 -1
  52. package/lib/settings/settings-radio-label.js +28 -30
  53. package/lib/settings/settings-radio-label.js.map +1 -1
  54. package/lib/settings/toggle.js +35 -46
  55. package/lib/settings/toggle.js.map +1 -1
  56. package/lib/tabs/index.js +22 -57
  57. package/lib/tabs/index.js.map +1 -1
  58. package/lib/tags-input/index.js +50 -99
  59. package/lib/tags-input/index.js.map +1 -1
  60. package/lib/two-choice.js +46 -90
  61. package/lib/two-choice.js.map +1 -1
  62. package/lib/with-stateful-model.js +8 -31
  63. package/lib/with-stateful-model.js.map +1 -1
  64. package/package.json +12 -20
  65. package/src/__tests__/alert-dialog.test.jsx +283 -0
  66. package/src/__tests__/checkbox.test.jsx +249 -0
  67. package/src/__tests__/form-section.test.jsx +334 -0
  68. package/src/__tests__/help.test.jsx +184 -0
  69. package/src/__tests__/input.test.jsx +192 -0
  70. package/src/__tests__/langs.test.jsx +435 -15
  71. package/src/__tests__/number-text-field-custom.test.jsx +438 -0
  72. package/src/__tests__/number-text-field.test.jsx +295 -102
  73. package/src/__tests__/radio-with-label.test.jsx +259 -0
  74. package/src/__tests__/settings-panel.test.js +66 -83
  75. package/src/__tests__/settings.test.jsx +515 -0
  76. package/src/__tests__/tabs.test.jsx +193 -0
  77. package/src/__tests__/two-choice.test.js +104 -18
  78. package/src/__tests__/with-stateful-model.test.jsx +145 -0
  79. package/src/alert-dialog.jsx +21 -19
  80. package/src/checkbox.jsx +42 -46
  81. package/src/choice-configuration/__tests__/feedback-menu.test.jsx +157 -4
  82. package/src/choice-configuration/__tests__/index.test.jsx +198 -56
  83. package/src/choice-configuration/feedback-menu.jsx +6 -6
  84. package/src/choice-configuration/index.jsx +201 -203
  85. package/src/feedback-config/__tests__/feedback-config.test.jsx +130 -60
  86. package/src/feedback-config/__tests__/feedback-selector.test.jsx +81 -44
  87. package/src/feedback-config/feedback-selector.jsx +50 -55
  88. package/src/feedback-config/group.jsx +21 -22
  89. package/src/feedback-config/index.jsx +27 -29
  90. package/src/form-section.jsx +26 -18
  91. package/src/help.jsx +20 -28
  92. package/src/input.jsx +1 -1
  93. package/src/inputs.jsx +34 -50
  94. package/src/langs.jsx +41 -46
  95. package/src/layout/__tests__/config.layout.test.jsx +55 -38
  96. package/src/layout/config-layout.jsx +38 -32
  97. package/src/layout/layout-contents.jsx +38 -39
  98. package/src/layout/settings-box.jsx +16 -19
  99. package/src/mui-box/index.jsx +35 -43
  100. package/src/number-text-field-custom.jsx +30 -36
  101. package/src/number-text-field.jsx +45 -29
  102. package/src/radio-with-label.jsx +25 -13
  103. package/src/settings/display-size.jsx +12 -11
  104. package/src/settings/panel.jsx +97 -91
  105. package/src/settings/settings-radio-label.jsx +25 -13
  106. package/src/settings/toggle.jsx +30 -29
  107. package/src/tabs/index.jsx +8 -8
  108. package/src/tags-input/__tests__/index.test.jsx +88 -37
  109. package/src/tags-input/index.jsx +35 -38
  110. package/src/two-choice.jsx +15 -19
  111. package/esm/index.css +0 -847
  112. package/esm/index.js +0 -213950
  113. package/esm/index.js.map +0 -1
  114. package/esm/package.json +0 -3
  115. package/src/__tests__/__snapshots__/langs.test.jsx.snap +0 -32
  116. package/src/__tests__/__snapshots__/settings-panel.test.js.snap +0 -115
  117. package/src/__tests__/__snapshots__/two-choice.test.js.snap +0 -171
  118. package/src/choice-configuration/__tests__/__snapshots__/feedback-menu.test.jsx.snap +0 -51
  119. package/src/choice-configuration/__tests__/__snapshots__/index.test.jsx.snap +0 -519
  120. package/src/feedback-config/__tests__/__snapshots__/feedback-config.test.jsx.snap +0 -27
  121. package/src/feedback-config/__tests__/__snapshots__/feedback-selector.test.jsx.snap +0 -38
  122. package/src/layout/__tests__/__snapshots__/config.layout.test.jsx.snap +0 -59
  123. 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
+ });