@fogpipe/forma-core 0.17.0 → 0.18.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/package.json +1 -1
- package/src/__tests__/matrix.test.ts +31 -12
package/package.json
CHANGED
|
@@ -17,11 +17,7 @@ function createMatrixSpec(options: {
|
|
|
17
17
|
required?: string[];
|
|
18
18
|
data?: Record<string, unknown>;
|
|
19
19
|
}): Forma {
|
|
20
|
-
const {
|
|
21
|
-
fieldDef = {},
|
|
22
|
-
schemaProperties,
|
|
23
|
-
required = [],
|
|
24
|
-
} = options;
|
|
20
|
+
const { fieldDef = {}, schemaProperties, required = [] } = options;
|
|
25
21
|
|
|
26
22
|
const matrixField: MatrixFieldDefinition = {
|
|
27
23
|
type: "matrix",
|
|
@@ -134,7 +130,11 @@ describe("matrix validation", () => {
|
|
|
134
130
|
},
|
|
135
131
|
});
|
|
136
132
|
const data = {
|
|
137
|
-
service_rating: {
|
|
133
|
+
service_rating: {
|
|
134
|
+
speed: "agree",
|
|
135
|
+
quality: "disagree",
|
|
136
|
+
support: "agree",
|
|
137
|
+
},
|
|
138
138
|
};
|
|
139
139
|
const result = validate(data, spec);
|
|
140
140
|
expect(result.valid).toBe(true);
|
|
@@ -172,7 +172,9 @@ describe("matrix validation", () => {
|
|
|
172
172
|
const spec = createMatrixSpec({ required: ["service_rating"] });
|
|
173
173
|
const result = validate({}, spec);
|
|
174
174
|
expect(result.valid).toBe(false);
|
|
175
|
-
expect(result.errors.some((e) => e.field === "service_rating")).toBe(
|
|
175
|
+
expect(result.errors.some((e) => e.field === "service_rating")).toBe(
|
|
176
|
+
true,
|
|
177
|
+
);
|
|
176
178
|
});
|
|
177
179
|
|
|
178
180
|
it("should fail when required and not all visible rows answered", () => {
|
|
@@ -214,15 +216,24 @@ describe("matrix validation", () => {
|
|
|
214
216
|
properties: {
|
|
215
217
|
speed: {
|
|
216
218
|
type: "array",
|
|
217
|
-
items: {
|
|
219
|
+
items: {
|
|
220
|
+
type: "string",
|
|
221
|
+
enum: ["beginner", "intermediate", "advanced"],
|
|
222
|
+
},
|
|
218
223
|
},
|
|
219
224
|
quality: {
|
|
220
225
|
type: "array",
|
|
221
|
-
items: {
|
|
226
|
+
items: {
|
|
227
|
+
type: "string",
|
|
228
|
+
enum: ["beginner", "intermediate", "advanced"],
|
|
229
|
+
},
|
|
222
230
|
},
|
|
223
231
|
support: {
|
|
224
232
|
type: "array",
|
|
225
|
-
items: {
|
|
233
|
+
items: {
|
|
234
|
+
type: "string",
|
|
235
|
+
enum: ["beginner", "intermediate", "advanced"],
|
|
236
|
+
},
|
|
226
237
|
},
|
|
227
238
|
},
|
|
228
239
|
},
|
|
@@ -344,7 +355,11 @@ describe("matrix visibility", () => {
|
|
|
344
355
|
fieldDef: {
|
|
345
356
|
rows: [
|
|
346
357
|
{ id: "speed", label: "Speed" },
|
|
347
|
-
{
|
|
358
|
+
{
|
|
359
|
+
id: "quality",
|
|
360
|
+
label: "Quality",
|
|
361
|
+
visibleWhen: "show_quality = true",
|
|
362
|
+
},
|
|
348
363
|
{ id: "support", label: "Support" },
|
|
349
364
|
],
|
|
350
365
|
},
|
|
@@ -364,7 +379,11 @@ describe("matrix visibility", () => {
|
|
|
364
379
|
fieldDef: {
|
|
365
380
|
rows: [
|
|
366
381
|
{ id: "speed", label: "Speed" },
|
|
367
|
-
{
|
|
382
|
+
{
|
|
383
|
+
id: "quality",
|
|
384
|
+
label: "Quality",
|
|
385
|
+
visibleWhen: "show_quality = true",
|
|
386
|
+
},
|
|
368
387
|
{ id: "support", label: "Support" },
|
|
369
388
|
],
|
|
370
389
|
},
|