@remoteoss/json-schema-form 0.2.0-beta.0 → 0.4.0-beta.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 +20 -2
- package/dist/index.cjs +28 -4
- package/dist/index.js +28 -4
- package/dist/standalone.js +811 -359
- package/package.json +3 -2
- package/src/tests/createHeadlessForm.test.js +48 -14
- package/src/tests/helpers.js +56 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-beta.0",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "node scripts/build.js",
|
|
26
26
|
"test": "jest",
|
|
27
|
+
"test:watch": "jest --watchAll",
|
|
27
28
|
"lint": "eslint \"src/**/*.{js,ts}\"",
|
|
28
29
|
"format": "npm run format:prettier && npm run format:eslint",
|
|
29
30
|
"prepare": "husky install",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"lodash": "^4.17.21",
|
|
50
51
|
"randexp": "^0.5.3",
|
|
51
|
-
"yup": "^0.
|
|
52
|
+
"yup": "^0.30.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@babel/core": "^7.21.5",
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
schemaInputTypeRadioDeprecated,
|
|
11
11
|
schemaInputTypeRadio,
|
|
12
12
|
schemaInputTypeRadioRequiredAndOptional,
|
|
13
|
+
schemaInputTypeRadioOptionsWithDetails,
|
|
13
14
|
schemaInputTypeSelectSoloDeprecated,
|
|
14
15
|
schemaInputTypeSelectSolo,
|
|
15
16
|
schemaInputTypeSelectMultipleDeprecated,
|
|
@@ -420,7 +421,7 @@ describe('createHeadlessForm', () => {
|
|
|
420
421
|
|
|
421
422
|
describe('field support', () => {
|
|
422
423
|
it('support "text" field type', () => {
|
|
423
|
-
const { fields } = createHeadlessForm(schemaInputTypeText);
|
|
424
|
+
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeText);
|
|
424
425
|
|
|
425
426
|
expect(fields[0]).toMatchObject({
|
|
426
427
|
description: 'The number of your national identification (max 10 digits)',
|
|
@@ -437,9 +438,13 @@ describe('createHeadlessForm', () => {
|
|
|
437
438
|
|
|
438
439
|
const fieldValidator = fields[0].schema;
|
|
439
440
|
expect(fieldValidator.isValidSync('CI007')).toBe(true);
|
|
440
|
-
expect(fieldValidator.isValidSync(true)).toBe(
|
|
441
|
-
expect(fieldValidator.isValidSync(1)).toBe(
|
|
442
|
-
expect(fieldValidator.isValidSync(0)).toBe(
|
|
441
|
+
expect(fieldValidator.isValidSync(true)).toBe(false);
|
|
442
|
+
expect(fieldValidator.isValidSync(1)).toBe(false);
|
|
443
|
+
expect(fieldValidator.isValidSync(0)).toBe(false);
|
|
444
|
+
|
|
445
|
+
expect(handleValidation({ id_number: 1 }).formErrors).toEqual({
|
|
446
|
+
id_number: 'id_number must be a `string` type, but the final value was: `1`.',
|
|
447
|
+
});
|
|
443
448
|
|
|
444
449
|
expect(() => fieldValidator.validateSync('')).toThrowError('Required field');
|
|
445
450
|
});
|
|
@@ -753,6 +758,35 @@ describe('createHeadlessForm', () => {
|
|
|
753
758
|
expect(() => fieldValidator.validateSync('')).toThrowError('Required field');
|
|
754
759
|
});
|
|
755
760
|
|
|
761
|
+
it('support "radio" field type with extra info inside each option', () => {
|
|
762
|
+
const result = createHeadlessForm(schemaInputTypeRadioOptionsWithDetails);
|
|
763
|
+
|
|
764
|
+
expect(result.fields).toHaveLength(1);
|
|
765
|
+
|
|
766
|
+
const fieldOptions = result.fields[0].options;
|
|
767
|
+
|
|
768
|
+
// The x-jsf-presentation content was spread to the root:
|
|
769
|
+
expect(fieldOptions[0]).not.toHaveProperty('x-jsf-presentation');
|
|
770
|
+
expect(fieldOptions).toEqual([
|
|
771
|
+
{
|
|
772
|
+
label: 'Basic',
|
|
773
|
+
value: 'basic',
|
|
774
|
+
meta: {
|
|
775
|
+
displayCost: '$30.00/mo',
|
|
776
|
+
},
|
|
777
|
+
// Other x-* keywords are kept as it is.
|
|
778
|
+
'x-another': 'extra-thing',
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
label: 'Standard',
|
|
782
|
+
value: 'standard',
|
|
783
|
+
meta: {
|
|
784
|
+
displayCost: '$50.00/mo',
|
|
785
|
+
},
|
|
786
|
+
},
|
|
787
|
+
]);
|
|
788
|
+
});
|
|
789
|
+
|
|
756
790
|
it('support "number" field type', () => {
|
|
757
791
|
const result = createHeadlessForm(schemaInputTypeNumber);
|
|
758
792
|
expect(result).toMatchObject({
|
|
@@ -2327,7 +2361,7 @@ describe('createHeadlessForm', () => {
|
|
|
2327
2361
|
validateForm({
|
|
2328
2362
|
validate_tabs: 'no',
|
|
2329
2363
|
a_fieldset: {
|
|
2330
|
-
id_number: 123,
|
|
2364
|
+
id_number: '123',
|
|
2331
2365
|
},
|
|
2332
2366
|
mandatory_group_array: 'no',
|
|
2333
2367
|
})
|
|
@@ -2342,7 +2376,7 @@ describe('createHeadlessForm', () => {
|
|
|
2342
2376
|
validateForm({
|
|
2343
2377
|
validate_tabs: 'yes',
|
|
2344
2378
|
a_fieldset: {
|
|
2345
|
-
id_number: 123,
|
|
2379
|
+
id_number: '123',
|
|
2346
2380
|
},
|
|
2347
2381
|
mandatory_group_array: 'no',
|
|
2348
2382
|
})
|
|
@@ -2358,7 +2392,7 @@ describe('createHeadlessForm', () => {
|
|
|
2358
2392
|
validateForm({
|
|
2359
2393
|
validate_tabs: 'yes',
|
|
2360
2394
|
a_fieldset: {
|
|
2361
|
-
id_number: 123,
|
|
2395
|
+
id_number: '123',
|
|
2362
2396
|
},
|
|
2363
2397
|
mandatory_group_array: 'yes',
|
|
2364
2398
|
a_group_array: [{ full_name: 'adfs' }],
|
|
@@ -2369,7 +2403,7 @@ describe('createHeadlessForm', () => {
|
|
|
2369
2403
|
validateForm({
|
|
2370
2404
|
validate_tabs: 'yes',
|
|
2371
2405
|
a_fieldset: {
|
|
2372
|
-
id_number: 123,
|
|
2406
|
+
id_number: '123',
|
|
2373
2407
|
tabs: 2,
|
|
2374
2408
|
},
|
|
2375
2409
|
mandatory_group_array: 'no',
|
|
@@ -2460,7 +2494,7 @@ describe('createHeadlessForm', () => {
|
|
|
2460
2494
|
validateForm({
|
|
2461
2495
|
validate_fieldset: ['id_number'],
|
|
2462
2496
|
a_fieldset: {
|
|
2463
|
-
id_number: 123,
|
|
2497
|
+
id_number: '123',
|
|
2464
2498
|
},
|
|
2465
2499
|
})
|
|
2466
2500
|
).toBeUndefined();
|
|
@@ -2469,7 +2503,7 @@ describe('createHeadlessForm', () => {
|
|
|
2469
2503
|
validateForm({
|
|
2470
2504
|
validate_fieldset: ['id_number', 'all'],
|
|
2471
2505
|
a_fieldset: {
|
|
2472
|
-
id_number: 123,
|
|
2506
|
+
id_number: '123',
|
|
2473
2507
|
},
|
|
2474
2508
|
})
|
|
2475
2509
|
).toEqual({
|
|
@@ -2482,7 +2516,7 @@ describe('createHeadlessForm', () => {
|
|
|
2482
2516
|
validateForm({
|
|
2483
2517
|
validate_fieldset: ['id_number', 'all'],
|
|
2484
2518
|
a_fieldset: {
|
|
2485
|
-
id_number: 123,
|
|
2519
|
+
id_number: '123',
|
|
2486
2520
|
tabs: 2,
|
|
2487
2521
|
},
|
|
2488
2522
|
})
|
|
@@ -2497,7 +2531,7 @@ describe('createHeadlessForm', () => {
|
|
|
2497
2531
|
validateForm({
|
|
2498
2532
|
validate_fieldset: ['id_number'],
|
|
2499
2533
|
a_fieldset: {
|
|
2500
|
-
id_number: 123,
|
|
2534
|
+
id_number: '123',
|
|
2501
2535
|
},
|
|
2502
2536
|
})
|
|
2503
2537
|
).toBeUndefined();
|
|
@@ -2506,7 +2540,7 @@ describe('createHeadlessForm', () => {
|
|
|
2506
2540
|
validateForm({
|
|
2507
2541
|
validate_fieldset: ['id_number', 'all'],
|
|
2508
2542
|
a_fieldset: {
|
|
2509
|
-
id_number: 123,
|
|
2543
|
+
id_number: '123',
|
|
2510
2544
|
},
|
|
2511
2545
|
})
|
|
2512
2546
|
).toEqual({
|
|
@@ -2519,7 +2553,7 @@ describe('createHeadlessForm', () => {
|
|
|
2519
2553
|
validateForm({
|
|
2520
2554
|
validate_fieldset: ['id_number', 'all'],
|
|
2521
2555
|
a_fieldset: {
|
|
2522
|
-
id_number: 123,
|
|
2556
|
+
id_number: '123',
|
|
2523
2557
|
tabs: 2,
|
|
2524
2558
|
},
|
|
2525
2559
|
})
|
package/src/tests/helpers.js
CHANGED
|
@@ -871,34 +871,70 @@ export const schemaInputDeprecated = JSONSchemaBuilder()
|
|
|
871
871
|
.build();
|
|
872
872
|
|
|
873
873
|
/** @deprecated */
|
|
874
|
-
export const schemaInputTypeRadioDeprecated =
|
|
875
|
-
|
|
874
|
+
export const schemaInputTypeRadioDeprecated = {
|
|
875
|
+
properties: {
|
|
876
876
|
has_siblings: mockRadioInputDeprecated,
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
877
|
+
},
|
|
878
|
+
required: ['has_siblings'],
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
export const schemaInputTypeRadio = {
|
|
882
|
+
properties: {
|
|
882
883
|
has_siblings: mockRadioInput,
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
|
|
884
|
+
},
|
|
885
|
+
required: ['has_siblings'],
|
|
886
|
+
};
|
|
886
887
|
|
|
887
|
-
export const schemaInputTypeRadioRequiredAndOptional =
|
|
888
|
-
|
|
888
|
+
export const schemaInputTypeRadioRequiredAndOptional = {
|
|
889
|
+
properties: {
|
|
889
890
|
has_siblings: mockRadioInput,
|
|
890
891
|
has_car: mockRadioInputOptional,
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
|
|
892
|
+
},
|
|
893
|
+
required: ['has_siblings'],
|
|
894
|
+
};
|
|
894
895
|
|
|
895
|
-
export const schemaInputTypeRadioCard =
|
|
896
|
-
|
|
896
|
+
export const schemaInputTypeRadioCard = {
|
|
897
|
+
properties: {
|
|
897
898
|
experience_level: mockRadioCardExpandableInput,
|
|
898
899
|
payment_method: mockRadioCardInput,
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
900
|
+
},
|
|
901
|
+
required: ['experience_level'],
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
export const schemaInputTypeRadioOptionsWithDetails = {
|
|
905
|
+
properties: {
|
|
906
|
+
health_perks: {
|
|
907
|
+
title: 'Health perks',
|
|
908
|
+
description:
|
|
909
|
+
'This example contains options with more custom details, under the x-jsf-presentation key',
|
|
910
|
+
oneOf: [
|
|
911
|
+
{
|
|
912
|
+
const: 'basic',
|
|
913
|
+
title: 'Basic',
|
|
914
|
+
'x-jsf-presentation': {
|
|
915
|
+
meta: {
|
|
916
|
+
displayCost: '$30.00/mo',
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
'x-another': 'extra-thing',
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
const: 'standard',
|
|
923
|
+
title: 'Standard',
|
|
924
|
+
'x-jsf-presentation': {
|
|
925
|
+
meta: {
|
|
926
|
+
displayCost: '$50.00/mo',
|
|
927
|
+
},
|
|
928
|
+
},
|
|
929
|
+
},
|
|
930
|
+
],
|
|
931
|
+
'x-jsf-presentation': {
|
|
932
|
+
inputType: 'radio',
|
|
933
|
+
},
|
|
934
|
+
type: 'string',
|
|
935
|
+
},
|
|
936
|
+
},
|
|
937
|
+
};
|
|
902
938
|
|
|
903
939
|
/** @deprecated */
|
|
904
940
|
export const schemaInputTypeSelectSoloDeprecated = JSONSchemaBuilder()
|