@object-ui/react 0.3.0 → 0.5.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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +8 -0
- package/dist/LazyPluginLoader.d.ts +38 -0
- package/dist/LazyPluginLoader.js +35 -0
- package/dist/SchemaRenderer.d.ts +7 -0
- package/dist/SchemaRenderer.js +51 -12
- package/dist/__tests__/LazyPluginLoader.test.d.ts +8 -0
- package/dist/__tests__/LazyPluginLoader.test.js +49 -0
- package/dist/components/form/FieldFactory.d.ts +43 -0
- package/dist/components/form/FieldFactory.js +157 -0
- package/dist/components/form/FormRenderer.d.ts +40 -0
- package/dist/components/form/FormRenderer.js +87 -0
- package/dist/components/form/FormRenderer.test.d.ts +8 -0
- package/dist/components/form/FormRenderer.test.js +534 -0
- package/dist/components/form/index.d.ts +11 -0
- package/dist/components/form/index.js +9 -0
- package/dist/context/SchemaRendererContext.d.ts +14 -0
- package/dist/context/SchemaRendererContext.js +23 -0
- package/dist/context/index.d.ts +8 -1
- package/dist/context/index.js +8 -1
- package/dist/hooks/index.d.ts +9 -1
- package/dist/hooks/index.js +9 -1
- package/dist/hooks/useActionRunner.d.ts +32 -0
- package/dist/hooks/useActionRunner.js +65 -0
- package/dist/hooks/useExpression.d.ts +27 -0
- package/dist/hooks/useExpression.js +41 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.test.d.ts +7 -0
- package/dist/index.test.js +7 -0
- package/package.json +26 -6
- package/src/LazyPluginLoader.tsx +52 -0
- package/src/SchemaRenderer.tsx +72 -12
- package/src/__tests__/LazyPluginLoader.test.tsx +80 -0
- package/src/components/form/FieldFactory.tsx +504 -0
- package/src/components/form/FormRenderer.test.tsx +599 -0
- package/src/components/form/FormRenderer.tsx +209 -0
- package/src/components/form/README.md +352 -0
- package/src/components/form/index.ts +12 -0
- package/src/context/SchemaRendererContext.tsx +43 -0
- package/src/context/index.ts +9 -1
- package/src/hooks/index.ts +11 -1
- package/src/hooks/useActionRunner.ts +81 -0
- package/src/hooks/useExpression.ts +56 -0
- package/src/index.test.ts +8 -0
- package/src/index.ts +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +2 -0
|
@@ -0,0 +1,599 @@
|
|
|
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 } from '@testing-library/react';
|
|
11
|
+
import '@testing-library/jest-dom';
|
|
12
|
+
import { FormRenderer } from './FormRenderer';
|
|
13
|
+
import type { FormView } from '@objectstack/spec/ui';
|
|
14
|
+
import type { ExtendedFormField } from './FieldFactory';
|
|
15
|
+
|
|
16
|
+
// Helper type for form views with extended fields
|
|
17
|
+
type ExtendedFormView = Omit<FormView, 'sections'> & {
|
|
18
|
+
sections?: Array<{
|
|
19
|
+
label?: string;
|
|
20
|
+
collapsible?: boolean;
|
|
21
|
+
collapsed?: boolean;
|
|
22
|
+
columns?: '1' | '2' | '3' | '4';
|
|
23
|
+
fields: (string | ExtendedFormField)[];
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('FormRenderer', () => {
|
|
28
|
+
it('should render a simple form with text fields', () => {
|
|
29
|
+
const schema: FormView = {
|
|
30
|
+
type: 'simple',
|
|
31
|
+
sections: [
|
|
32
|
+
{
|
|
33
|
+
label: 'Personal Information',
|
|
34
|
+
collapsible: false,
|
|
35
|
+
collapsed: false,
|
|
36
|
+
columns: 2,
|
|
37
|
+
fields: [
|
|
38
|
+
{
|
|
39
|
+
field: 'firstName',
|
|
40
|
+
label: 'First Name',
|
|
41
|
+
required: true,
|
|
42
|
+
widget: 'text',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
field: 'lastName',
|
|
46
|
+
label: 'Last Name',
|
|
47
|
+
required: true,
|
|
48
|
+
widget: 'text',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
56
|
+
|
|
57
|
+
expect(screen.getByText('Personal Information')).toBeInTheDocument();
|
|
58
|
+
expect(screen.getByLabelText(/First Name/)).toBeInTheDocument();
|
|
59
|
+
expect(screen.getByLabelText(/Last Name/)).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should render form with initial data', () => {
|
|
63
|
+
const schema: FormView = {
|
|
64
|
+
type: 'simple',
|
|
65
|
+
sections: [
|
|
66
|
+
{
|
|
67
|
+
label: 'User Details',
|
|
68
|
+
collapsible: false,
|
|
69
|
+
collapsed: false,
|
|
70
|
+
columns: 1,
|
|
71
|
+
fields: [
|
|
72
|
+
{
|
|
73
|
+
field: 'username',
|
|
74
|
+
label: 'Username',
|
|
75
|
+
widget: 'text',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const data = { username: 'john_doe' };
|
|
83
|
+
|
|
84
|
+
render(<FormRenderer schema={schema} data={data} />);
|
|
85
|
+
|
|
86
|
+
const input = screen.getByLabelText('Username') as HTMLInputElement;
|
|
87
|
+
expect(input.value).toBe('john_doe');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should handle multi-column layout', () => {
|
|
91
|
+
const schema: FormView = {
|
|
92
|
+
type: 'simple',
|
|
93
|
+
sections: [
|
|
94
|
+
{
|
|
95
|
+
label: 'Contact',
|
|
96
|
+
collapsible: false,
|
|
97
|
+
collapsed: false,
|
|
98
|
+
columns: 3,
|
|
99
|
+
fields: [
|
|
100
|
+
{
|
|
101
|
+
field: 'email',
|
|
102
|
+
label: 'Email',
|
|
103
|
+
widget: 'email',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
field: 'phone',
|
|
107
|
+
label: 'Phone',
|
|
108
|
+
widget: 'tel',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
field: 'address',
|
|
112
|
+
label: 'Address',
|
|
113
|
+
widget: 'textarea',
|
|
114
|
+
colSpan: 3,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
render(<FormRenderer schema={schema} />);
|
|
122
|
+
|
|
123
|
+
expect(screen.getByLabelText('Email')).toBeInTheDocument();
|
|
124
|
+
expect(screen.getByLabelText('Phone')).toBeInTheDocument();
|
|
125
|
+
expect(screen.getByLabelText('Address')).toBeInTheDocument();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should hide fields marked as hidden', () => {
|
|
129
|
+
const schema: FormView = {
|
|
130
|
+
type: 'simple',
|
|
131
|
+
sections: [
|
|
132
|
+
{
|
|
133
|
+
label: 'Form',
|
|
134
|
+
collapsible: false,
|
|
135
|
+
collapsed: false,
|
|
136
|
+
columns: 1,
|
|
137
|
+
fields: [
|
|
138
|
+
{
|
|
139
|
+
field: 'visible',
|
|
140
|
+
label: 'Visible Field',
|
|
141
|
+
widget: 'text',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
field: 'hidden',
|
|
145
|
+
label: 'Hidden Field',
|
|
146
|
+
widget: 'text',
|
|
147
|
+
hidden: true,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
render(<FormRenderer schema={schema} />);
|
|
155
|
+
|
|
156
|
+
expect(screen.getByLabelText('Visible Field')).toBeInTheDocument();
|
|
157
|
+
expect(screen.queryByLabelText('Hidden Field')).not.toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should support legacy string field format', () => {
|
|
161
|
+
const schema: FormView = {
|
|
162
|
+
type: 'simple',
|
|
163
|
+
sections: [
|
|
164
|
+
{
|
|
165
|
+
label: 'Legacy Form',
|
|
166
|
+
collapsible: false,
|
|
167
|
+
collapsed: false,
|
|
168
|
+
columns: 1,
|
|
169
|
+
fields: ['username', 'email'],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
175
|
+
|
|
176
|
+
// String fields should still render as inputs
|
|
177
|
+
const inputs = container.querySelectorAll('input[type="text"]');
|
|
178
|
+
expect(inputs.length).toBeGreaterThan(0);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should handle number fields', () => {
|
|
182
|
+
const schema: FormView = {
|
|
183
|
+
type: 'simple',
|
|
184
|
+
sections: [
|
|
185
|
+
{
|
|
186
|
+
label: 'Numbers',
|
|
187
|
+
collapsible: false,
|
|
188
|
+
collapsed: false,
|
|
189
|
+
columns: 1,
|
|
190
|
+
fields: [
|
|
191
|
+
{
|
|
192
|
+
field: 'age',
|
|
193
|
+
label: 'Age',
|
|
194
|
+
widget: 'number',
|
|
195
|
+
required: true,
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
render(<FormRenderer schema={schema} />);
|
|
203
|
+
|
|
204
|
+
const input = screen.getByLabelText(/Age/) as HTMLInputElement;
|
|
205
|
+
expect(input.type).toBe('number');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should handle checkbox fields', () => {
|
|
209
|
+
const schema: FormView = {
|
|
210
|
+
type: 'simple',
|
|
211
|
+
sections: [
|
|
212
|
+
{
|
|
213
|
+
label: 'Preferences',
|
|
214
|
+
collapsible: false,
|
|
215
|
+
collapsed: false,
|
|
216
|
+
columns: 1,
|
|
217
|
+
fields: [
|
|
218
|
+
{
|
|
219
|
+
field: 'subscribe',
|
|
220
|
+
label: 'Subscribe to newsletter',
|
|
221
|
+
widget: 'checkbox',
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
render(<FormRenderer schema={schema} />);
|
|
229
|
+
|
|
230
|
+
const checkbox = screen.getByLabelText('Subscribe to newsletter') as HTMLInputElement;
|
|
231
|
+
expect(checkbox.type).toBe('checkbox');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should render help text when provided', () => {
|
|
235
|
+
const schema: FormView = {
|
|
236
|
+
type: 'simple',
|
|
237
|
+
sections: [
|
|
238
|
+
{
|
|
239
|
+
label: 'Help Text',
|
|
240
|
+
collapsible: false,
|
|
241
|
+
collapsed: false,
|
|
242
|
+
columns: 1,
|
|
243
|
+
fields: [
|
|
244
|
+
{
|
|
245
|
+
field: 'password',
|
|
246
|
+
label: 'Password',
|
|
247
|
+
widget: 'password',
|
|
248
|
+
helpText: 'Must be at least 8 characters',
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
render(<FormRenderer schema={schema} />);
|
|
256
|
+
|
|
257
|
+
expect(screen.getByText('Must be at least 8 characters')).toBeInTheDocument();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should mark required fields with asterisk', () => {
|
|
261
|
+
const schema: FormView = {
|
|
262
|
+
type: 'simple',
|
|
263
|
+
sections: [
|
|
264
|
+
{
|
|
265
|
+
label: 'Required',
|
|
266
|
+
collapsible: false,
|
|
267
|
+
collapsed: false,
|
|
268
|
+
columns: 1,
|
|
269
|
+
fields: [
|
|
270
|
+
{
|
|
271
|
+
field: 'name',
|
|
272
|
+
label: 'Name',
|
|
273
|
+
widget: 'text',
|
|
274
|
+
required: true,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
282
|
+
|
|
283
|
+
// Check for asterisk
|
|
284
|
+
const asterisk = container.querySelector('.text-red-500');
|
|
285
|
+
expect(asterisk).toBeInTheDocument();
|
|
286
|
+
expect(asterisk?.textContent).toContain('*');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Test new field types
|
|
290
|
+
describe('Extended field types', () => {
|
|
291
|
+
it('should render currency field with dollar sign', () => {
|
|
292
|
+
const schema: FormView = {
|
|
293
|
+
type: 'simple',
|
|
294
|
+
sections: [
|
|
295
|
+
{
|
|
296
|
+
label: 'Pricing',
|
|
297
|
+
collapsible: false,
|
|
298
|
+
collapsed: false,
|
|
299
|
+
columns: 1,
|
|
300
|
+
fields: [
|
|
301
|
+
{
|
|
302
|
+
field: 'price',
|
|
303
|
+
label: 'Price',
|
|
304
|
+
widget: 'currency',
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
312
|
+
expect(screen.getByLabelText('Price')).toBeInTheDocument();
|
|
313
|
+
expect(container.querySelector('.absolute')?.textContent).toBe('$');
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should render percent field with percent sign', () => {
|
|
317
|
+
const schema: FormView = {
|
|
318
|
+
type: 'simple',
|
|
319
|
+
sections: [
|
|
320
|
+
{
|
|
321
|
+
label: 'Metrics',
|
|
322
|
+
collapsible: false,
|
|
323
|
+
collapsed: false,
|
|
324
|
+
columns: 1,
|
|
325
|
+
fields: [
|
|
326
|
+
{
|
|
327
|
+
field: 'discount',
|
|
328
|
+
label: 'Discount',
|
|
329
|
+
widget: 'percent',
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
337
|
+
expect(screen.getByLabelText('Discount')).toBeInTheDocument();
|
|
338
|
+
expect(container.querySelector('.absolute')?.textContent).toBe('%');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('should render phone field', () => {
|
|
342
|
+
const schema: FormView = {
|
|
343
|
+
type: 'simple',
|
|
344
|
+
sections: [
|
|
345
|
+
{
|
|
346
|
+
label: 'Contact',
|
|
347
|
+
collapsible: false,
|
|
348
|
+
collapsed: false,
|
|
349
|
+
columns: 1,
|
|
350
|
+
fields: [
|
|
351
|
+
{
|
|
352
|
+
field: 'phoneNumber',
|
|
353
|
+
label: 'Phone Number',
|
|
354
|
+
widget: 'phone',
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
render(<FormRenderer schema={schema} />);
|
|
362
|
+
const input = screen.getByLabelText('Phone Number') as HTMLInputElement;
|
|
363
|
+
expect(input.type).toBe('tel');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should render markdown field as textarea', () => {
|
|
367
|
+
const schema: FormView = {
|
|
368
|
+
type: 'simple',
|
|
369
|
+
sections: [
|
|
370
|
+
{
|
|
371
|
+
label: 'Content',
|
|
372
|
+
collapsible: false,
|
|
373
|
+
collapsed: false,
|
|
374
|
+
columns: 1,
|
|
375
|
+
fields: [
|
|
376
|
+
{
|
|
377
|
+
field: 'content',
|
|
378
|
+
label: 'Content',
|
|
379
|
+
widget: 'markdown',
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
},
|
|
383
|
+
],
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
render(<FormRenderer schema={schema} />);
|
|
387
|
+
const textarea = screen.getByLabelText('Content') as HTMLTextAreaElement;
|
|
388
|
+
expect(textarea.tagName).toBe('TEXTAREA');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('should render html field as textarea', () => {
|
|
392
|
+
const schema: FormView = {
|
|
393
|
+
type: 'simple',
|
|
394
|
+
sections: [
|
|
395
|
+
{
|
|
396
|
+
label: 'Content',
|
|
397
|
+
collapsible: false,
|
|
398
|
+
collapsed: false,
|
|
399
|
+
columns: 1,
|
|
400
|
+
fields: [
|
|
401
|
+
{
|
|
402
|
+
field: 'htmlContent',
|
|
403
|
+
label: 'HTML Content',
|
|
404
|
+
widget: 'html',
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
render(<FormRenderer schema={schema} />);
|
|
412
|
+
const textarea = screen.getByLabelText('HTML Content') as HTMLTextAreaElement;
|
|
413
|
+
expect(textarea.tagName).toBe('TEXTAREA');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it('should render file field', () => {
|
|
417
|
+
const schema: FormView = {
|
|
418
|
+
type: 'simple',
|
|
419
|
+
sections: [
|
|
420
|
+
{
|
|
421
|
+
label: 'Upload',
|
|
422
|
+
collapsible: false,
|
|
423
|
+
collapsed: false,
|
|
424
|
+
columns: 1,
|
|
425
|
+
fields: [
|
|
426
|
+
{
|
|
427
|
+
field: 'document',
|
|
428
|
+
label: 'Document',
|
|
429
|
+
widget: 'file',
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
render(<FormRenderer schema={schema} />);
|
|
437
|
+
const input = screen.getByLabelText('Document') as HTMLInputElement;
|
|
438
|
+
expect(input.type).toBe('file');
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('should render image field', () => {
|
|
442
|
+
const schema: FormView = {
|
|
443
|
+
type: 'simple',
|
|
444
|
+
sections: [
|
|
445
|
+
{
|
|
446
|
+
label: 'Upload',
|
|
447
|
+
collapsible: false,
|
|
448
|
+
collapsed: false,
|
|
449
|
+
columns: 1,
|
|
450
|
+
fields: [
|
|
451
|
+
{
|
|
452
|
+
field: 'avatar',
|
|
453
|
+
label: 'Avatar',
|
|
454
|
+
widget: 'image',
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
render(<FormRenderer schema={schema} />);
|
|
462
|
+
const input = screen.getByLabelText('Avatar') as HTMLInputElement;
|
|
463
|
+
expect(input.type).toBe('file');
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it('should render location field with lat/lng inputs', () => {
|
|
467
|
+
const schema: FormView = {
|
|
468
|
+
type: 'simple',
|
|
469
|
+
sections: [
|
|
470
|
+
{
|
|
471
|
+
label: 'Location',
|
|
472
|
+
collapsible: false,
|
|
473
|
+
collapsed: false,
|
|
474
|
+
columns: 1,
|
|
475
|
+
fields: [
|
|
476
|
+
{
|
|
477
|
+
field: 'coordinates',
|
|
478
|
+
label: 'Coordinates',
|
|
479
|
+
widget: 'location',
|
|
480
|
+
},
|
|
481
|
+
],
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
const { container } = render(<FormRenderer schema={schema} />);
|
|
487
|
+
const inputs = container.querySelectorAll('input[type="number"]');
|
|
488
|
+
expect(inputs.length).toBe(2);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it('should render lookup field as select', () => {
|
|
492
|
+
const schema: ExtendedFormView = {
|
|
493
|
+
type: 'simple',
|
|
494
|
+
sections: [
|
|
495
|
+
{
|
|
496
|
+
label: 'Relations',
|
|
497
|
+
collapsible: false,
|
|
498
|
+
collapsed: false,
|
|
499
|
+
columns: '1',
|
|
500
|
+
fields: [
|
|
501
|
+
{
|
|
502
|
+
field: 'account',
|
|
503
|
+
label: 'Account',
|
|
504
|
+
widget: 'lookup',
|
|
505
|
+
options: [
|
|
506
|
+
{ label: 'Account 1', value: '1' },
|
|
507
|
+
{ label: 'Account 2', value: '2' },
|
|
508
|
+
],
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
render(<FormRenderer schema={schema as FormView} />);
|
|
516
|
+
const select = screen.getByLabelText('Account') as HTMLSelectElement;
|
|
517
|
+
expect(select.tagName).toBe('SELECT');
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it('should render user field as select', () => {
|
|
521
|
+
const schema: ExtendedFormView = {
|
|
522
|
+
type: 'simple',
|
|
523
|
+
sections: [
|
|
524
|
+
{
|
|
525
|
+
label: 'Assignment',
|
|
526
|
+
collapsible: false,
|
|
527
|
+
collapsed: false,
|
|
528
|
+
columns: '1',
|
|
529
|
+
fields: [
|
|
530
|
+
{
|
|
531
|
+
field: 'assignedTo',
|
|
532
|
+
label: 'Assigned To',
|
|
533
|
+
widget: 'user',
|
|
534
|
+
options: [
|
|
535
|
+
{ label: 'User 1', value: 'user1' },
|
|
536
|
+
{ label: 'User 2', value: 'user2' },
|
|
537
|
+
],
|
|
538
|
+
},
|
|
539
|
+
],
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
render(<FormRenderer schema={schema as FormView} />);
|
|
545
|
+
const select = screen.getByLabelText('Assigned To') as HTMLSelectElement;
|
|
546
|
+
expect(select.tagName).toBe('SELECT');
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('should render formula field as disabled input', () => {
|
|
550
|
+
const schema: FormView = {
|
|
551
|
+
type: 'simple',
|
|
552
|
+
sections: [
|
|
553
|
+
{
|
|
554
|
+
label: 'Computed',
|
|
555
|
+
collapsible: false,
|
|
556
|
+
collapsed: false,
|
|
557
|
+
columns: 1,
|
|
558
|
+
fields: [
|
|
559
|
+
{
|
|
560
|
+
field: 'total',
|
|
561
|
+
label: 'Total',
|
|
562
|
+
widget: 'formula',
|
|
563
|
+
},
|
|
564
|
+
],
|
|
565
|
+
},
|
|
566
|
+
],
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
render(<FormRenderer schema={schema} />);
|
|
570
|
+
const input = screen.getByLabelText('Total') as HTMLInputElement;
|
|
571
|
+
expect(input.disabled).toBe(true);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('should render object field as JSON textarea', () => {
|
|
575
|
+
const schema: FormView = {
|
|
576
|
+
type: 'simple',
|
|
577
|
+
sections: [
|
|
578
|
+
{
|
|
579
|
+
label: 'Data',
|
|
580
|
+
collapsible: false,
|
|
581
|
+
collapsed: false,
|
|
582
|
+
columns: 1,
|
|
583
|
+
fields: [
|
|
584
|
+
{
|
|
585
|
+
field: 'metadata',
|
|
586
|
+
label: 'Metadata',
|
|
587
|
+
widget: 'object',
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
render(<FormRenderer schema={schema} />);
|
|
595
|
+
const textarea = screen.getByLabelText('Metadata') as HTMLTextAreaElement;
|
|
596
|
+
expect(textarea.tagName).toBe('TEXTAREA');
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
});
|