@remoteoss/json-schema-form 0.11.11-dev.20250220174843 → 1.0.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/.nvmrc +1 -0
- package/.vscode/settings.json +51 -0
- package/README.md +29 -24
- package/babel.config.mjs +14 -0
- package/eslint.config.mjs +3 -0
- package/jest.config.mjs +52 -0
- package/package.json +27 -71
- package/src/form.ts +3 -0
- package/src/index.ts +1 -0
- package/src/utils.ts +24 -0
- package/test/form.test.ts +11 -0
- package/tsconfig.json +13 -0
- package/tsup.config.json +10 -0
- package/CHANGELOG.md +0 -320
- package/LICENSE +0 -21
- package/dist/index.cjs +0 -2171
- package/dist/index.js +0 -2140
- package/dist/standalone.js +0 -13656
- package/json-schema-form.d.ts +0 -175
- package/json-schema-form.schema.json +0 -188
- package/src/tests/checkIfConditionMatches.test.js +0 -65
- package/src/tests/conditions.test.js +0 -938
- package/src/tests/const.test.js +0 -236
- package/src/tests/createHeadlessForm.customValidations.test.js +0 -803
- package/src/tests/createHeadlessForm.test.js +0 -4324
- package/src/tests/helpers.custom.js +0 -222
- package/src/tests/helpers.js +0 -2385
- package/src/tests/internals.helpers.test.js +0 -175
- package/src/tests/jsonLogic.fixtures.js +0 -986
- package/src/tests/jsonLogic.test.js +0 -588
- package/src/tests/modify.test.js +0 -939
- package/src/tests/testUtils.js +0 -11
- package/src/tests/utils.test.jsx +0 -32
package/src/tests/const.test.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { createHeadlessForm } from '@/createHeadlessForm';
|
|
2
|
-
|
|
3
|
-
describe('validations: const', () => {
|
|
4
|
-
it('Should work for number', () => {
|
|
5
|
-
const { handleValidation } = createHeadlessForm(
|
|
6
|
-
{
|
|
7
|
-
properties: {
|
|
8
|
-
ten_only: { type: 'number', const: 10 },
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
{ strictInputType: false }
|
|
12
|
-
);
|
|
13
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
14
|
-
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
15
|
-
ten_only: 'The only accepted value is 10.',
|
|
16
|
-
});
|
|
17
|
-
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
18
|
-
// null is also considered valid until we fix @BUG RMT-518
|
|
19
|
-
// Expectation: To fail with error "The only accepted value is 10."
|
|
20
|
-
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Should work for when the number is 0', () => {
|
|
24
|
-
const { handleValidation } = createHeadlessForm(
|
|
25
|
-
{
|
|
26
|
-
properties: {
|
|
27
|
-
zero_only: { type: 'number', const: 0 },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
{ strictInputType: false }
|
|
31
|
-
);
|
|
32
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
33
|
-
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
34
|
-
zero_only: 'The only accepted value is 0.',
|
|
35
|
-
});
|
|
36
|
-
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
37
|
-
// null is also considered valid until we fix @BUG RMT-518
|
|
38
|
-
// Expectation: To fail with error "The only accepted value is 0."
|
|
39
|
-
expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Should work for text', () => {
|
|
43
|
-
const { handleValidation } = createHeadlessForm(
|
|
44
|
-
{
|
|
45
|
-
properties: {
|
|
46
|
-
hello_only: { type: 'string', const: 'hello' },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{ strictInputType: false }
|
|
50
|
-
);
|
|
51
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
52
|
-
expect(handleValidation({ hello_only: 'what' }).formErrors).toEqual({
|
|
53
|
-
hello_only: 'The only accepted value is hello.',
|
|
54
|
-
});
|
|
55
|
-
expect(handleValidation({ hello_only: 'hello' }).formErrors).toEqual(undefined);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('Should work for a conditionally applied const', () => {
|
|
59
|
-
const { handleValidation } = createHeadlessForm(
|
|
60
|
-
{
|
|
61
|
-
properties: {
|
|
62
|
-
answer: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] },
|
|
63
|
-
amount: {
|
|
64
|
-
description: 'If you select yes, this needs to be exactly 10.',
|
|
65
|
-
type: 'number',
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
allOf: [
|
|
69
|
-
{
|
|
70
|
-
if: { properties: { answer: { const: 'yes' } }, required: ['answer'] },
|
|
71
|
-
then: { properties: { amount: { const: 10 } }, required: ['amount'] },
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
{ strictInputType: false }
|
|
76
|
-
);
|
|
77
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
78
|
-
expect(handleValidation({ answer: 'no' }).formErrors).toEqual(undefined);
|
|
79
|
-
expect(handleValidation({ answer: 'yes' }).formErrors).toEqual({ amount: 'Required field' });
|
|
80
|
-
expect(handleValidation({ answer: 'yes', amount: 1 }).formErrors).toEqual({
|
|
81
|
-
amount: 'The only accepted value is 10.',
|
|
82
|
-
});
|
|
83
|
-
expect(handleValidation({ answer: 'yes', amount: 10 }).formErrors).toEqual(undefined);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('Should show the custom error message', () => {
|
|
87
|
-
const { handleValidation } = createHeadlessForm(
|
|
88
|
-
{
|
|
89
|
-
properties: {
|
|
90
|
-
string: {
|
|
91
|
-
type: 'string',
|
|
92
|
-
const: 'hello',
|
|
93
|
-
'x-jsf-errorMessage': { const: 'You must say hello!!!' },
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{ strictInputType: false }
|
|
98
|
-
);
|
|
99
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
100
|
-
expect(handleValidation({ string: 'hi' }).formErrors).toEqual({
|
|
101
|
-
string: 'You must say hello!!!',
|
|
102
|
-
});
|
|
103
|
-
expect(handleValidation({ string: 'hello' }).formErrors).toEqual(undefined);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('Should have value attribute for when const & default is present', () => {
|
|
107
|
-
const { fields } = createHeadlessForm(
|
|
108
|
-
{
|
|
109
|
-
properties: {
|
|
110
|
-
ten_only: { type: 'number', const: 10, default: 10 },
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{ strictInputType: false }
|
|
114
|
-
);
|
|
115
|
-
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('const/default with forced values', () => {
|
|
120
|
-
it('Should work for when the number is 0', () => {
|
|
121
|
-
const { fields, handleValidation } = createHeadlessForm(
|
|
122
|
-
{
|
|
123
|
-
properties: {
|
|
124
|
-
zero_only: { type: 'number', const: 0, default: 0 },
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
{ strictInputType: false }
|
|
128
|
-
);
|
|
129
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
130
|
-
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
131
|
-
zero_only: 'The only accepted value is 0.',
|
|
132
|
-
});
|
|
133
|
-
expect(fields[0]).toMatchObject({ forcedValue: 0, const: 0, default: 0 });
|
|
134
|
-
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
135
|
-
// null is also considered valid until we fix @BUG RMT-518
|
|
136
|
-
// Expectation: To fail with error "The only accepted value is 0."
|
|
137
|
-
expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('Should work for number', () => {
|
|
141
|
-
const { fields, handleValidation } = createHeadlessForm(
|
|
142
|
-
{
|
|
143
|
-
properties: {
|
|
144
|
-
ten_only: { type: 'number', const: 10, default: 10 },
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{ strictInputType: false }
|
|
148
|
-
);
|
|
149
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
150
|
-
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
151
|
-
ten_only: 'The only accepted value is 10.',
|
|
152
|
-
});
|
|
153
|
-
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
154
|
-
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
155
|
-
// null is also considered valid until we fix @BUG RMT-518
|
|
156
|
-
// Expectation: To fail with error "The only accepted value is 10."
|
|
157
|
-
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('do not set a forced value if const and default do not equal', () => {
|
|
161
|
-
const { fields } = createHeadlessForm(
|
|
162
|
-
{
|
|
163
|
-
properties: {
|
|
164
|
-
bad_field_for_number: { type: 'number', const: 10, default: 20 },
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
{ strictInputType: false }
|
|
168
|
-
);
|
|
169
|
-
expect(fields[0]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('Should work numbers with non-standard input types', () => {
|
|
173
|
-
const { fields, handleValidation } = createHeadlessForm(
|
|
174
|
-
{
|
|
175
|
-
properties: {
|
|
176
|
-
number: {
|
|
177
|
-
type: 'integer',
|
|
178
|
-
const: 300,
|
|
179
|
-
default: 300,
|
|
180
|
-
'x-jsf-presentation': {
|
|
181
|
-
inputType: 'money',
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
required: ['number'],
|
|
186
|
-
},
|
|
187
|
-
{ strictInputType: true }
|
|
188
|
-
);
|
|
189
|
-
expect(handleValidation({ number: 0 }).formErrors).toEqual({
|
|
190
|
-
number: 'The only accepted value is 300.',
|
|
191
|
-
});
|
|
192
|
-
expect(handleValidation({ number: 300 }).formErrors).toBeUndefined();
|
|
193
|
-
expect(fields[0]).toMatchObject({ forcedValue: 300 });
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe('OneOf const', () => {
|
|
198
|
-
it('Validates numbers or strings correctly', () => {
|
|
199
|
-
const { handleValidation } = createHeadlessForm(
|
|
200
|
-
{
|
|
201
|
-
properties: {
|
|
202
|
-
number: { type: 'number', oneOf: [{ const: 0 }, { const: 1 }, { const: 2 }] },
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
{ strictInputType: false }
|
|
206
|
-
);
|
|
207
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
208
|
-
expect(handleValidation({ number: 3 }).formErrors).toEqual({
|
|
209
|
-
number: 'The option 3 is not valid.',
|
|
210
|
-
});
|
|
211
|
-
expect(handleValidation({ number: 2 }).formErrors).toBeUndefined();
|
|
212
|
-
expect(handleValidation({ number: '2' }).formErrors).toEqual({
|
|
213
|
-
number: 'The option "2" is not valid.',
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('Validates numbers or strings when type is an array with null', () => {
|
|
218
|
-
const { handleValidation } = createHeadlessForm(
|
|
219
|
-
{
|
|
220
|
-
properties: {
|
|
221
|
-
number: { type: ['number', 'null'], oneOf: [{ const: 0 }, { const: 1 }, { const: 2 }] },
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
{ strictInputType: false }
|
|
225
|
-
);
|
|
226
|
-
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
227
|
-
expect(handleValidation({ number: 3 }).formErrors).toEqual({
|
|
228
|
-
number: 'The option 3 is not valid.',
|
|
229
|
-
});
|
|
230
|
-
expect(handleValidation({ number: 2 }).formErrors).toBeUndefined();
|
|
231
|
-
expect(handleValidation({ number: '2' }).formErrors).toEqual({
|
|
232
|
-
number: 'The option "2" is not valid.',
|
|
233
|
-
});
|
|
234
|
-
expect(handleValidation({ number: null }).formErrors).toEqual(undefined);
|
|
235
|
-
});
|
|
236
|
-
});
|