@fogpipe/forma-react 0.13.0 → 0.15.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/README.md +74 -9
- package/dist/index.d.ts +92 -1
- package/dist/index.js +276 -50
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/FieldRenderer.tsx +1 -0
- package/src/FormRenderer.tsx +1 -0
- package/src/__tests__/FieldRenderer.test.tsx +107 -0
- package/src/__tests__/events.test.ts +752 -0
- package/src/events.ts +186 -0
- package/src/index.ts +5 -0
- package/src/types.ts +9 -0
- package/src/useForma.ts +269 -58
|
@@ -507,6 +507,113 @@ describe("FieldRenderer", () => {
|
|
|
507
507
|
});
|
|
508
508
|
});
|
|
509
509
|
|
|
510
|
+
// ============================================================================
|
|
511
|
+
// itemFieldOrder Propagation
|
|
512
|
+
// ============================================================================
|
|
513
|
+
|
|
514
|
+
describe("itemFieldOrder propagation", () => {
|
|
515
|
+
it("should pass itemFieldOrder to array field props", () => {
|
|
516
|
+
let capturedProps: ArrayComponentProps["field"] | null = null;
|
|
517
|
+
|
|
518
|
+
const spec: Forma = {
|
|
519
|
+
version: "1.0",
|
|
520
|
+
meta: { id: "test", title: "Test" },
|
|
521
|
+
schema: {
|
|
522
|
+
type: "object",
|
|
523
|
+
properties: {
|
|
524
|
+
medications: {
|
|
525
|
+
type: "array",
|
|
526
|
+
items: {
|
|
527
|
+
type: "object",
|
|
528
|
+
properties: {
|
|
529
|
+
name: { type: "string" },
|
|
530
|
+
dosage: { type: "string" },
|
|
531
|
+
frequency: { type: "string" },
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
fields: {
|
|
538
|
+
medications: {
|
|
539
|
+
type: "array",
|
|
540
|
+
label: "Medications",
|
|
541
|
+
itemFields: {
|
|
542
|
+
name: { type: "text", label: "Name" },
|
|
543
|
+
dosage: { type: "text", label: "Dosage" },
|
|
544
|
+
frequency: { type: "text", label: "Frequency" },
|
|
545
|
+
},
|
|
546
|
+
itemFieldOrder: ["frequency", "name", "dosage"],
|
|
547
|
+
},
|
|
548
|
+
},
|
|
549
|
+
fieldOrder: ["medications"],
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
const components: ComponentMap = {
|
|
553
|
+
...createTestComponentMap(),
|
|
554
|
+
array: ({ field: props }: ArrayComponentProps) => {
|
|
555
|
+
capturedProps = props;
|
|
556
|
+
return <div data-testid="array-field">array</div>;
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
render(<FormRenderer spec={spec} components={components} />);
|
|
561
|
+
|
|
562
|
+
expect(capturedProps).not.toBeNull();
|
|
563
|
+
expect(capturedProps!.itemFieldOrder).toEqual([
|
|
564
|
+
"frequency",
|
|
565
|
+
"name",
|
|
566
|
+
"dosage",
|
|
567
|
+
]);
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it("should leave itemFieldOrder undefined when not specified", () => {
|
|
571
|
+
let capturedProps: ArrayComponentProps["field"] | null = null;
|
|
572
|
+
|
|
573
|
+
const spec: Forma = {
|
|
574
|
+
version: "1.0",
|
|
575
|
+
meta: { id: "test", title: "Test" },
|
|
576
|
+
schema: {
|
|
577
|
+
type: "object",
|
|
578
|
+
properties: {
|
|
579
|
+
items: {
|
|
580
|
+
type: "array",
|
|
581
|
+
items: {
|
|
582
|
+
type: "object",
|
|
583
|
+
properties: {
|
|
584
|
+
name: { type: "string" },
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
fields: {
|
|
591
|
+
items: {
|
|
592
|
+
type: "array",
|
|
593
|
+
label: "Items",
|
|
594
|
+
itemFields: {
|
|
595
|
+
name: { type: "text", label: "Name" },
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
fieldOrder: ["items"],
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
const components: ComponentMap = {
|
|
603
|
+
...createTestComponentMap(),
|
|
604
|
+
array: ({ field: props }: ArrayComponentProps) => {
|
|
605
|
+
capturedProps = props;
|
|
606
|
+
return <div data-testid="array-field">array</div>;
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
render(<FormRenderer spec={spec} components={components} />);
|
|
611
|
+
|
|
612
|
+
expect(capturedProps).not.toBeNull();
|
|
613
|
+
expect(capturedProps!.itemFieldOrder).toBeUndefined();
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
510
617
|
// ============================================================================
|
|
511
618
|
// FieldRenderer Visibility Wrapper Stability
|
|
512
619
|
// ============================================================================
|