@object-ui/components 3.0.3 → 3.1.1
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/.turbo/turbo-build.log +12 -12
- package/CHANGELOG.md +9 -0
- package/dist/index.css +1 -1
- package/dist/index.js +24932 -23139
- package/dist/index.umd.cjs +37 -37
- package/dist/src/custom/config-field-renderer.d.ts +21 -0
- package/dist/src/custom/config-panel-renderer.d.ts +81 -0
- package/dist/src/custom/config-row.d.ts +27 -0
- package/dist/src/custom/filter-builder.d.ts +1 -1
- package/dist/src/custom/index.d.ts +5 -0
- package/dist/src/custom/mobile-dialog-content.d.ts +20 -0
- package/dist/src/custom/navigation-overlay.d.ts +8 -0
- package/dist/src/custom/section-header.d.ts +31 -0
- package/dist/src/debug/DebugPanel.d.ts +39 -0
- package/dist/src/debug/index.d.ts +9 -0
- package/dist/src/hooks/use-config-draft.d.ts +46 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/renderers/action/action-bar.d.ts +25 -0
- package/dist/src/renderers/action/action-button.d.ts +1 -0
- package/dist/src/types/config-panel.d.ts +92 -0
- package/dist/src/ui/sheet.d.ts +2 -0
- package/dist/src/ui/sidebar.d.ts +4 -0
- package/package.json +17 -17
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +3 -3
- package/src/__tests__/action-bar.test.tsx +206 -0
- package/src/__tests__/config-field-renderer.test.tsx +307 -0
- package/src/__tests__/config-panel-renderer.test.tsx +580 -0
- package/src/__tests__/config-primitives.test.tsx +106 -0
- package/src/__tests__/filter-builder.test.tsx +409 -0
- package/src/__tests__/mobile-accessibility.test.tsx +120 -0
- package/src/__tests__/navigation-overlay.test.tsx +97 -0
- package/src/__tests__/use-config-draft.test.tsx +295 -0
- package/src/custom/config-field-renderer.tsx +276 -0
- package/src/custom/config-panel-renderer.tsx +306 -0
- package/src/custom/config-row.tsx +50 -0
- package/src/custom/filter-builder.tsx +76 -25
- package/src/custom/index.ts +5 -0
- package/src/custom/mobile-dialog-content.tsx +67 -0
- package/src/custom/navigation-overlay.tsx +42 -4
- package/src/custom/section-header.tsx +68 -0
- package/src/debug/DebugPanel.tsx +313 -0
- package/src/debug/__tests__/DebugPanel.test.tsx +134 -0
- package/src/debug/index.ts +10 -0
- package/src/hooks/use-config-draft.ts +127 -0
- package/src/index.css +4 -0
- package/src/index.ts +15 -0
- package/src/renderers/action/action-bar.tsx +221 -0
- package/src/renderers/action/action-button.tsx +17 -6
- package/src/renderers/action/index.ts +1 -0
- package/src/renderers/complex/__tests__/data-table-airtable-ux.test.tsx +239 -0
- package/src/renderers/complex/__tests__/data-table.test.ts +16 -0
- package/src/renderers/complex/data-table.tsx +346 -43
- package/src/renderers/data-display/breadcrumb.tsx +3 -2
- package/src/renderers/form/form.tsx +4 -4
- package/src/renderers/navigation/header-bar.tsx +69 -10
- package/src/stories/ConfigPanel.stories.tsx +232 -0
- package/src/types/config-panel.ts +101 -0
- package/src/ui/dialog.tsx +20 -3
- package/src/ui/sheet.tsx +6 -3
- package/src/ui/sidebar.tsx +93 -9
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
10
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
11
|
+
import { ConfigPanelRenderer } from '../custom/config-panel-renderer';
|
|
12
|
+
import type { ConfigPanelSchema } from '../types/config-panel';
|
|
13
|
+
|
|
14
|
+
const basicSchema: ConfigPanelSchema = {
|
|
15
|
+
breadcrumb: ['Settings', 'General'],
|
|
16
|
+
sections: [
|
|
17
|
+
{
|
|
18
|
+
key: 'basic',
|
|
19
|
+
title: 'Basic Settings',
|
|
20
|
+
fields: [
|
|
21
|
+
{ key: 'name', label: 'Name', type: 'input' },
|
|
22
|
+
{ key: 'enabled', label: 'Enabled', type: 'switch' },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const collapsibleSchema: ConfigPanelSchema = {
|
|
29
|
+
breadcrumb: ['Dashboard'],
|
|
30
|
+
sections: [
|
|
31
|
+
{
|
|
32
|
+
key: 'layout',
|
|
33
|
+
title: 'Layout',
|
|
34
|
+
fields: [
|
|
35
|
+
{ key: 'columns', label: 'Columns', type: 'input' },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: 'appearance',
|
|
40
|
+
title: 'Appearance',
|
|
41
|
+
collapsible: true,
|
|
42
|
+
defaultCollapsed: true,
|
|
43
|
+
fields: [
|
|
44
|
+
{ key: 'theme', label: 'Theme', type: 'input' },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'data',
|
|
49
|
+
title: 'Data',
|
|
50
|
+
collapsible: true,
|
|
51
|
+
fields: [
|
|
52
|
+
{ key: 'source', label: 'Source', type: 'input' },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const conditionalSchema: ConfigPanelSchema = {
|
|
59
|
+
breadcrumb: ['Config'],
|
|
60
|
+
sections: [
|
|
61
|
+
{
|
|
62
|
+
key: 'main',
|
|
63
|
+
title: 'Main',
|
|
64
|
+
fields: [
|
|
65
|
+
{ key: 'mode', label: 'Mode', type: 'input' },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: 'advanced',
|
|
70
|
+
title: 'Advanced',
|
|
71
|
+
visibleWhen: (draft) => draft.mode === 'advanced',
|
|
72
|
+
fields: [
|
|
73
|
+
{ key: 'setting', label: 'Setting', type: 'input' },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const defaultProps = {
|
|
80
|
+
open: true,
|
|
81
|
+
onClose: vi.fn(),
|
|
82
|
+
draft: { name: 'Test', enabled: true },
|
|
83
|
+
isDirty: false,
|
|
84
|
+
onFieldChange: vi.fn(),
|
|
85
|
+
onSave: vi.fn(),
|
|
86
|
+
onDiscard: vi.fn(),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
describe('ConfigPanelRenderer', () => {
|
|
90
|
+
describe('rendering', () => {
|
|
91
|
+
it('should render nothing when closed', () => {
|
|
92
|
+
const { container } = render(
|
|
93
|
+
<ConfigPanelRenderer {...defaultProps} schema={basicSchema} open={false} />,
|
|
94
|
+
);
|
|
95
|
+
expect(container.innerHTML).toBe('');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should render panel when open', () => {
|
|
99
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
100
|
+
expect(screen.getByTestId('config-panel')).toBeDefined();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should render breadcrumb segments', () => {
|
|
104
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
105
|
+
expect(screen.getByText('Settings')).toBeDefined();
|
|
106
|
+
expect(screen.getByText('General')).toBeDefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should render section titles', () => {
|
|
110
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
111
|
+
expect(screen.getByText('Basic Settings')).toBeDefined();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should render field labels', () => {
|
|
115
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
116
|
+
expect(screen.getByText('Name')).toBeDefined();
|
|
117
|
+
expect(screen.getByText('Enabled')).toBeDefined();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should render close button', () => {
|
|
121
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
122
|
+
expect(screen.getByTestId('config-panel-close')).toBeDefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should render header extra content', () => {
|
|
126
|
+
render(
|
|
127
|
+
<ConfigPanelRenderer
|
|
128
|
+
{...defaultProps}
|
|
129
|
+
schema={basicSchema}
|
|
130
|
+
headerExtra={<span data-testid="extra">Extra</span>}
|
|
131
|
+
/>,
|
|
132
|
+
);
|
|
133
|
+
expect(screen.getByTestId('extra')).toBeDefined();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('close behavior', () => {
|
|
138
|
+
it('should call onClose when close button clicked', () => {
|
|
139
|
+
const onClose = vi.fn();
|
|
140
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} onClose={onClose} />);
|
|
141
|
+
fireEvent.click(screen.getByTestId('config-panel-close'));
|
|
142
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('dirty state & footer', () => {
|
|
147
|
+
it('should not show footer when not dirty', () => {
|
|
148
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} isDirty={false} />);
|
|
149
|
+
expect(screen.queryByTestId('config-panel-footer')).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should show footer with save/discard when dirty', () => {
|
|
153
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} isDirty={true} />);
|
|
154
|
+
expect(screen.getByTestId('config-panel-footer')).toBeDefined();
|
|
155
|
+
expect(screen.getByTestId('config-panel-save')).toBeDefined();
|
|
156
|
+
expect(screen.getByTestId('config-panel-discard')).toBeDefined();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should call onSave when save clicked', () => {
|
|
160
|
+
const onSave = vi.fn();
|
|
161
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} isDirty={true} onSave={onSave} />);
|
|
162
|
+
fireEvent.click(screen.getByTestId('config-panel-save'));
|
|
163
|
+
expect(onSave).toHaveBeenCalledTimes(1);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should call onDiscard when discard clicked', () => {
|
|
167
|
+
const onDiscard = vi.fn();
|
|
168
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} isDirty={true} onDiscard={onDiscard} />);
|
|
169
|
+
fireEvent.click(screen.getByTestId('config-panel-discard'));
|
|
170
|
+
expect(onDiscard).toHaveBeenCalledTimes(1);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should support custom save/discard labels', () => {
|
|
174
|
+
render(
|
|
175
|
+
<ConfigPanelRenderer
|
|
176
|
+
{...defaultProps}
|
|
177
|
+
schema={basicSchema}
|
|
178
|
+
isDirty={true}
|
|
179
|
+
saveLabel="Apply"
|
|
180
|
+
discardLabel="Reset"
|
|
181
|
+
/>,
|
|
182
|
+
);
|
|
183
|
+
expect(screen.getByText('Apply')).toBeDefined();
|
|
184
|
+
expect(screen.getByText('Reset')).toBeDefined();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('collapsible sections', () => {
|
|
189
|
+
it('should show defaultCollapsed section as collapsed', () => {
|
|
190
|
+
render(
|
|
191
|
+
<ConfigPanelRenderer
|
|
192
|
+
{...defaultProps}
|
|
193
|
+
schema={collapsibleSchema}
|
|
194
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
195
|
+
/>,
|
|
196
|
+
);
|
|
197
|
+
// Appearance is defaultCollapsed, so Theme should not be visible
|
|
198
|
+
expect(screen.queryByText('Theme')).toBeNull();
|
|
199
|
+
// Data is collapsible but not defaultCollapsed, so Source should be visible
|
|
200
|
+
expect(screen.getByText('Source')).toBeDefined();
|
|
201
|
+
// Layout is not collapsible, so Columns should be visible
|
|
202
|
+
expect(screen.getByText('Columns')).toBeDefined();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should toggle collapsible section on click', () => {
|
|
206
|
+
render(
|
|
207
|
+
<ConfigPanelRenderer
|
|
208
|
+
{...defaultProps}
|
|
209
|
+
schema={collapsibleSchema}
|
|
210
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
211
|
+
/>,
|
|
212
|
+
);
|
|
213
|
+
// Appearance is collapsed by default
|
|
214
|
+
expect(screen.queryByText('Theme')).toBeNull();
|
|
215
|
+
|
|
216
|
+
// Click to expand
|
|
217
|
+
fireEvent.click(screen.getByTestId('section-header-appearance'));
|
|
218
|
+
expect(screen.getByText('Theme')).toBeDefined();
|
|
219
|
+
|
|
220
|
+
// Click to collapse again
|
|
221
|
+
fireEvent.click(screen.getByTestId('section-header-appearance'));
|
|
222
|
+
expect(screen.queryByText('Theme')).toBeNull();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should toggle non-defaultCollapsed section', () => {
|
|
226
|
+
render(
|
|
227
|
+
<ConfigPanelRenderer
|
|
228
|
+
{...defaultProps}
|
|
229
|
+
schema={collapsibleSchema}
|
|
230
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
231
|
+
/>,
|
|
232
|
+
);
|
|
233
|
+
// Data is expanded by default
|
|
234
|
+
expect(screen.getByText('Source')).toBeDefined();
|
|
235
|
+
|
|
236
|
+
// Click to collapse
|
|
237
|
+
fireEvent.click(screen.getByTestId('section-header-data'));
|
|
238
|
+
expect(screen.queryByText('Source')).toBeNull();
|
|
239
|
+
|
|
240
|
+
// Click to expand again
|
|
241
|
+
fireEvent.click(screen.getByTestId('section-header-data'));
|
|
242
|
+
expect(screen.getByText('Source')).toBeDefined();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should use aria-expanded on collapsible sections', () => {
|
|
246
|
+
render(
|
|
247
|
+
<ConfigPanelRenderer
|
|
248
|
+
{...defaultProps}
|
|
249
|
+
schema={collapsibleSchema}
|
|
250
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
251
|
+
/>,
|
|
252
|
+
);
|
|
253
|
+
const appearance = screen.getByTestId('section-header-appearance');
|
|
254
|
+
expect(appearance.getAttribute('aria-expanded')).toBe('false');
|
|
255
|
+
|
|
256
|
+
const data = screen.getByTestId('section-header-data');
|
|
257
|
+
expect(data.getAttribute('aria-expanded')).toBe('true');
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('conditional sections', () => {
|
|
262
|
+
it('should hide section when visibleWhen returns false', () => {
|
|
263
|
+
render(
|
|
264
|
+
<ConfigPanelRenderer
|
|
265
|
+
{...defaultProps}
|
|
266
|
+
schema={conditionalSchema}
|
|
267
|
+
draft={{ mode: 'simple' }}
|
|
268
|
+
/>,
|
|
269
|
+
);
|
|
270
|
+
expect(screen.getByText('Main')).toBeDefined();
|
|
271
|
+
expect(screen.queryByText('Advanced')).toBeNull();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('should show section when visibleWhen returns true', () => {
|
|
275
|
+
render(
|
|
276
|
+
<ConfigPanelRenderer
|
|
277
|
+
{...defaultProps}
|
|
278
|
+
schema={conditionalSchema}
|
|
279
|
+
draft={{ mode: 'advanced' }}
|
|
280
|
+
/>,
|
|
281
|
+
);
|
|
282
|
+
expect(screen.getByText('Main')).toBeDefined();
|
|
283
|
+
expect(screen.getByText('Advanced')).toBeDefined();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('section hints', () => {
|
|
288
|
+
it('should render section hint text', () => {
|
|
289
|
+
const schemaWithHint: ConfigPanelSchema = {
|
|
290
|
+
breadcrumb: ['Test'],
|
|
291
|
+
sections: [
|
|
292
|
+
{
|
|
293
|
+
key: 'sec',
|
|
294
|
+
title: 'Section',
|
|
295
|
+
hint: 'This is a helpful hint',
|
|
296
|
+
fields: [{ key: 'x', label: 'X', type: 'input' }],
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
};
|
|
300
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithHint} />);
|
|
301
|
+
expect(screen.getByText('This is a helpful hint')).toBeDefined();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe('field change propagation', () => {
|
|
306
|
+
it('should call onFieldChange when a field changes', () => {
|
|
307
|
+
const onFieldChange = vi.fn();
|
|
308
|
+
render(
|
|
309
|
+
<ConfigPanelRenderer
|
|
310
|
+
{...defaultProps}
|
|
311
|
+
schema={basicSchema}
|
|
312
|
+
onFieldChange={onFieldChange}
|
|
313
|
+
/>,
|
|
314
|
+
);
|
|
315
|
+
const nameInput = screen.getByTestId('config-field-name');
|
|
316
|
+
fireEvent.change(nameInput, { target: { value: 'NewName' } });
|
|
317
|
+
expect(onFieldChange).toHaveBeenCalledWith('name', 'NewName');
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('expandedSections prop', () => {
|
|
322
|
+
it('should override defaultCollapsed when section is in expandedSections', () => {
|
|
323
|
+
render(
|
|
324
|
+
<ConfigPanelRenderer
|
|
325
|
+
{...defaultProps}
|
|
326
|
+
schema={collapsibleSchema}
|
|
327
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
328
|
+
expandedSections={['appearance']}
|
|
329
|
+
/>,
|
|
330
|
+
);
|
|
331
|
+
// Appearance is defaultCollapsed=true but expandedSections overrides it
|
|
332
|
+
expect(screen.getByText('Theme')).toBeDefined();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('should not affect sections not in expandedSections', () => {
|
|
336
|
+
render(
|
|
337
|
+
<ConfigPanelRenderer
|
|
338
|
+
{...defaultProps}
|
|
339
|
+
schema={collapsibleSchema}
|
|
340
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
341
|
+
expandedSections={['appearance']}
|
|
342
|
+
/>,
|
|
343
|
+
);
|
|
344
|
+
// Data section is not in expandedSections, should remain expanded (its default)
|
|
345
|
+
expect(screen.getByText('Source')).toBeDefined();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should allow local toggle to still work alongside expandedSections', () => {
|
|
349
|
+
render(
|
|
350
|
+
<ConfigPanelRenderer
|
|
351
|
+
{...defaultProps}
|
|
352
|
+
schema={collapsibleSchema}
|
|
353
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
354
|
+
expandedSections={['appearance']}
|
|
355
|
+
/>,
|
|
356
|
+
);
|
|
357
|
+
// Appearance is forced expanded by expandedSections
|
|
358
|
+
expect(screen.getByText('Theme')).toBeDefined();
|
|
359
|
+
|
|
360
|
+
// Data section can still be toggled locally
|
|
361
|
+
expect(screen.getByText('Source')).toBeDefined();
|
|
362
|
+
fireEvent.click(screen.getByTestId('section-header-data'));
|
|
363
|
+
expect(screen.queryByText('Source')).toBeNull();
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('disabledWhen on fields', () => {
|
|
368
|
+
it('should disable input field when disabledWhen returns true', () => {
|
|
369
|
+
const schemaWithDisabledWhen: ConfigPanelSchema = {
|
|
370
|
+
breadcrumb: ['Test'],
|
|
371
|
+
sections: [
|
|
372
|
+
{
|
|
373
|
+
key: 'sec',
|
|
374
|
+
title: 'Section',
|
|
375
|
+
fields: [
|
|
376
|
+
{
|
|
377
|
+
key: 'name',
|
|
378
|
+
label: 'Name',
|
|
379
|
+
type: 'input',
|
|
380
|
+
disabledWhen: (draft) => draft.locked === true,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
render(
|
|
387
|
+
<ConfigPanelRenderer
|
|
388
|
+
{...defaultProps}
|
|
389
|
+
schema={schemaWithDisabledWhen}
|
|
390
|
+
draft={{ name: 'Test', locked: true }}
|
|
391
|
+
/>,
|
|
392
|
+
);
|
|
393
|
+
const input = screen.getByTestId('config-field-name');
|
|
394
|
+
expect((input as HTMLInputElement).disabled).toBe(true);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('should enable input field when disabledWhen returns false', () => {
|
|
398
|
+
const schemaWithDisabledWhen: ConfigPanelSchema = {
|
|
399
|
+
breadcrumb: ['Test'],
|
|
400
|
+
sections: [
|
|
401
|
+
{
|
|
402
|
+
key: 'sec',
|
|
403
|
+
title: 'Section',
|
|
404
|
+
fields: [
|
|
405
|
+
{
|
|
406
|
+
key: 'name',
|
|
407
|
+
label: 'Name',
|
|
408
|
+
type: 'input',
|
|
409
|
+
disabledWhen: (draft) => draft.locked === true,
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
};
|
|
415
|
+
render(
|
|
416
|
+
<ConfigPanelRenderer
|
|
417
|
+
{...defaultProps}
|
|
418
|
+
schema={schemaWithDisabledWhen}
|
|
419
|
+
draft={{ name: 'Test', locked: false }}
|
|
420
|
+
/>,
|
|
421
|
+
);
|
|
422
|
+
const input = screen.getByTestId('config-field-name');
|
|
423
|
+
expect((input as HTMLInputElement).disabled).toBe(false);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe('section icons', () => {
|
|
428
|
+
it('should render section icon when provided', () => {
|
|
429
|
+
const React = require('react');
|
|
430
|
+
const schemaWithIcon: ConfigPanelSchema = {
|
|
431
|
+
breadcrumb: ['Test'],
|
|
432
|
+
sections: [
|
|
433
|
+
{
|
|
434
|
+
key: 'sec',
|
|
435
|
+
title: 'Section With Icon',
|
|
436
|
+
icon: React.createElement('span', { 'data-testid': 'section-icon' }, '⚙'),
|
|
437
|
+
fields: [{ key: 'x', label: 'X', type: 'input' }],
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
};
|
|
441
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithIcon} />);
|
|
442
|
+
expect(screen.getByTestId('section-icon')).toBeDefined();
|
|
443
|
+
expect(screen.getByText('Section With Icon')).toBeDefined();
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
describe('subsections', () => {
|
|
448
|
+
it('should render subsections within a section', () => {
|
|
449
|
+
const schemaWithSub: ConfigPanelSchema = {
|
|
450
|
+
breadcrumb: ['Test'],
|
|
451
|
+
sections: [
|
|
452
|
+
{
|
|
453
|
+
key: 'parent',
|
|
454
|
+
title: 'Parent',
|
|
455
|
+
fields: [{ key: 'a', label: 'Field A', type: 'input' }],
|
|
456
|
+
subsections: [
|
|
457
|
+
{
|
|
458
|
+
key: 'child',
|
|
459
|
+
title: 'Child Section',
|
|
460
|
+
fields: [{ key: 'b', label: 'Field B', type: 'input' }],
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
},
|
|
464
|
+
],
|
|
465
|
+
};
|
|
466
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithSub} />);
|
|
467
|
+
expect(screen.getByText('Parent')).toBeDefined();
|
|
468
|
+
expect(screen.getByText('Child Section')).toBeDefined();
|
|
469
|
+
expect(screen.getByText('Field A')).toBeDefined();
|
|
470
|
+
expect(screen.getByText('Field B')).toBeDefined();
|
|
471
|
+
expect(screen.getByTestId('config-subsection-child')).toBeDefined();
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('should support collapsible subsections', () => {
|
|
475
|
+
const schemaWithCollapsibleSub: ConfigPanelSchema = {
|
|
476
|
+
breadcrumb: ['Test'],
|
|
477
|
+
sections: [
|
|
478
|
+
{
|
|
479
|
+
key: 'parent',
|
|
480
|
+
title: 'Parent',
|
|
481
|
+
fields: [{ key: 'a', label: 'Field A', type: 'input' }],
|
|
482
|
+
subsections: [
|
|
483
|
+
{
|
|
484
|
+
key: 'child',
|
|
485
|
+
title: 'Child',
|
|
486
|
+
collapsible: true,
|
|
487
|
+
defaultCollapsed: true,
|
|
488
|
+
fields: [{ key: 'b', label: 'Field B', type: 'input' }],
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
};
|
|
494
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithCollapsibleSub} />);
|
|
495
|
+
// Child is defaultCollapsed, so Field B should not be visible
|
|
496
|
+
expect(screen.queryByText('Field B')).toBeNull();
|
|
497
|
+
// Click to expand
|
|
498
|
+
fireEvent.click(screen.getByTestId('section-header-child'));
|
|
499
|
+
expect(screen.getByText('Field B')).toBeDefined();
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
describe('summary control type', () => {
|
|
504
|
+
it('should render summary field with text and gear icon', () => {
|
|
505
|
+
const onSummaryClick = vi.fn();
|
|
506
|
+
const schemaWithSummary: ConfigPanelSchema = {
|
|
507
|
+
breadcrumb: ['Test'],
|
|
508
|
+
sections: [
|
|
509
|
+
{
|
|
510
|
+
key: 'sec',
|
|
511
|
+
title: 'Section',
|
|
512
|
+
fields: [
|
|
513
|
+
{
|
|
514
|
+
key: 'viz',
|
|
515
|
+
label: 'Visualizations',
|
|
516
|
+
type: 'summary',
|
|
517
|
+
summaryText: 'List, Gallery, Kanban',
|
|
518
|
+
onSummaryClick,
|
|
519
|
+
},
|
|
520
|
+
],
|
|
521
|
+
},
|
|
522
|
+
],
|
|
523
|
+
};
|
|
524
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithSummary} />);
|
|
525
|
+
expect(screen.getByText('Visualizations')).toBeDefined();
|
|
526
|
+
expect(screen.getByTestId('config-field-viz-text')).toBeDefined();
|
|
527
|
+
expect(screen.getByText('List, Gallery, Kanban')).toBeDefined();
|
|
528
|
+
expect(screen.getByTestId('config-field-viz-gear')).toBeDefined();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('should call onSummaryClick when summary row is clicked', () => {
|
|
532
|
+
const onSummaryClick = vi.fn();
|
|
533
|
+
const schemaWithSummary: ConfigPanelSchema = {
|
|
534
|
+
breadcrumb: ['Test'],
|
|
535
|
+
sections: [
|
|
536
|
+
{
|
|
537
|
+
key: 'sec',
|
|
538
|
+
title: 'Section',
|
|
539
|
+
fields: [
|
|
540
|
+
{
|
|
541
|
+
key: 'viz',
|
|
542
|
+
label: 'Viz',
|
|
543
|
+
type: 'summary',
|
|
544
|
+
summaryText: 'Items',
|
|
545
|
+
onSummaryClick,
|
|
546
|
+
},
|
|
547
|
+
],
|
|
548
|
+
},
|
|
549
|
+
],
|
|
550
|
+
};
|
|
551
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={schemaWithSummary} />);
|
|
552
|
+
// The ConfigRow wraps in a button when onClick is provided
|
|
553
|
+
const row = screen.getByText('Viz').closest('button');
|
|
554
|
+
if (row) fireEvent.click(row);
|
|
555
|
+
expect(onSummaryClick).toHaveBeenCalledTimes(1);
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
describe('increased section spacing', () => {
|
|
560
|
+
it('should use space-y-1 for field spacing within sections', () => {
|
|
561
|
+
render(<ConfigPanelRenderer {...defaultProps} schema={basicSchema} />);
|
|
562
|
+
const section = screen.getByTestId('config-section-basic');
|
|
563
|
+
const fieldContainer = section.querySelector('.space-y-1');
|
|
564
|
+
expect(fieldContainer).not.toBeNull();
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
it('should use my-3 separator between sections', () => {
|
|
568
|
+
render(
|
|
569
|
+
<ConfigPanelRenderer
|
|
570
|
+
{...defaultProps}
|
|
571
|
+
schema={collapsibleSchema}
|
|
572
|
+
draft={{ columns: '3', theme: 'dark', source: 'api' }}
|
|
573
|
+
/>,
|
|
574
|
+
);
|
|
575
|
+
const panel = screen.getByTestId('config-panel');
|
|
576
|
+
const separators = panel.querySelectorAll('.my-3');
|
|
577
|
+
expect(separators.length).toBeGreaterThan(0);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
10
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
11
|
+
import { ConfigRow } from '../custom/config-row';
|
|
12
|
+
import { SectionHeader } from '../custom/section-header';
|
|
13
|
+
|
|
14
|
+
describe('ConfigRow', () => {
|
|
15
|
+
it('should render label and value', () => {
|
|
16
|
+
render(<ConfigRow label="Color" value="Blue" />);
|
|
17
|
+
expect(screen.getByText('Color')).toBeDefined();
|
|
18
|
+
expect(screen.getByText('Blue')).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should render as div when not clickable', () => {
|
|
22
|
+
const { container } = render(<ConfigRow label="Label" value="Value" />);
|
|
23
|
+
expect(container.querySelector('button')).toBeNull();
|
|
24
|
+
expect(container.querySelector('div')).not.toBeNull();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should render as button when onClick is provided', () => {
|
|
28
|
+
const onClick = vi.fn();
|
|
29
|
+
const { container } = render(<ConfigRow label="Label" value="Value" onClick={onClick} />);
|
|
30
|
+
const button = container.querySelector('button');
|
|
31
|
+
expect(button).not.toBeNull();
|
|
32
|
+
fireEvent.click(button!);
|
|
33
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should render children instead of value when provided', () => {
|
|
37
|
+
render(
|
|
38
|
+
<ConfigRow label="Custom">
|
|
39
|
+
<span data-testid="custom-child">Custom Content</span>
|
|
40
|
+
</ConfigRow>,
|
|
41
|
+
);
|
|
42
|
+
expect(screen.getByTestId('custom-child')).toBeDefined();
|
|
43
|
+
expect(screen.getByText('Custom Content')).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should apply custom className', () => {
|
|
47
|
+
const { container } = render(<ConfigRow label="Label" className="custom-class" />);
|
|
48
|
+
expect(container.firstElementChild?.className).toContain('custom-class');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('SectionHeader', () => {
|
|
53
|
+
it('should render title text', () => {
|
|
54
|
+
render(<SectionHeader title="Data" />);
|
|
55
|
+
expect(screen.getByText('Data')).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should render as div when not collapsible', () => {
|
|
59
|
+
const { container } = render(<SectionHeader title="Data" testId="section" />);
|
|
60
|
+
const element = screen.getByTestId('section');
|
|
61
|
+
expect(element.tagName).toBe('DIV');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should render as button when collapsible', () => {
|
|
65
|
+
render(<SectionHeader title="Data" collapsible testId="section" />);
|
|
66
|
+
const element = screen.getByTestId('section');
|
|
67
|
+
expect(element.tagName).toBe('BUTTON');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should set aria-expanded when collapsible', () => {
|
|
71
|
+
render(<SectionHeader title="Data" collapsible collapsed={false} testId="section" />);
|
|
72
|
+
const element = screen.getByTestId('section');
|
|
73
|
+
expect(element.getAttribute('aria-expanded')).toBe('true');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should set aria-expanded=false when collapsed', () => {
|
|
77
|
+
render(<SectionHeader title="Data" collapsible collapsed testId="section" />);
|
|
78
|
+
const element = screen.getByTestId('section');
|
|
79
|
+
expect(element.getAttribute('aria-expanded')).toBe('false');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should call onToggle when collapsible button is clicked', () => {
|
|
83
|
+
const onToggle = vi.fn();
|
|
84
|
+
render(<SectionHeader title="Data" collapsible onToggle={onToggle} testId="section" />);
|
|
85
|
+
fireEvent.click(screen.getByTestId('section'));
|
|
86
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should apply custom className', () => {
|
|
90
|
+
render(<SectionHeader title="Data" collapsible className="custom-class" testId="section" />);
|
|
91
|
+
const element = screen.getByTestId('section');
|
|
92
|
+
expect(element.className).toContain('custom-class');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should render icon when provided', () => {
|
|
96
|
+
render(<SectionHeader title="Data" icon={<span data-testid="icon">📊</span>} testId="section" />);
|
|
97
|
+
expect(screen.getByTestId('icon')).toBeDefined();
|
|
98
|
+
expect(screen.getByText('Data')).toBeDefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should render icon alongside collapsible title', () => {
|
|
102
|
+
render(<SectionHeader title="Data" icon={<span data-testid="icon">📊</span>} collapsible testId="section" />);
|
|
103
|
+
expect(screen.getByTestId('icon')).toBeDefined();
|
|
104
|
+
expect(screen.getByTestId('section').tagName).toBe('BUTTON');
|
|
105
|
+
});
|
|
106
|
+
});
|