@remoteoss/json-schema-form 0.6.4-beta.0 → 0.6.5-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.6.4-beta.0",
3
+ "version": "0.6.5-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",
@@ -1,12 +1,12 @@
1
- import { checkIfConditionMatches } from '../checkIfConditionMatches';
1
+ import { checkIfConditionMatchesProperties } from '../checkIfConditionMatches';
2
2
 
3
3
  it('Empty if is always going to be true', () => {
4
- expect(checkIfConditionMatches({ if: { properties: {} } })).toBe(true);
4
+ expect(checkIfConditionMatchesProperties({ if: { properties: {} } })).toBe(true);
5
5
  });
6
6
 
7
7
  it('Basic if check passes with correct value', () => {
8
8
  expect(
9
- checkIfConditionMatches(
9
+ checkIfConditionMatchesProperties(
10
10
  { if: { properties: { a: { const: 'hello' } } } },
11
11
  {
12
12
  a: 'hello',
@@ -17,7 +17,7 @@ it('Basic if check passes with correct value', () => {
17
17
 
18
18
  it('Basic if check fails with incorrect value', () => {
19
19
  expect(
20
- checkIfConditionMatches(
20
+ checkIfConditionMatchesProperties(
21
21
  { if: { properties: { a: { const: 'hello' } } } },
22
22
  {
23
23
  a: 'goodbye',
@@ -28,7 +28,7 @@ it('Basic if check fails with incorrect value', () => {
28
28
 
29
29
  it('Nested properties check passes with correct value', () => {
30
30
  expect(
31
- checkIfConditionMatches(
31
+ checkIfConditionMatchesProperties(
32
32
  { if: { properties: { parent: { properties: { child: { const: 'hello from child' } } } } } },
33
33
  {
34
34
  parent: { child: 'hello from child' },
@@ -40,7 +40,7 @@ it('Nested properties check passes with correct value', () => {
40
40
 
41
41
  it('Nested properties check passes with correct value', () => {
42
42
  expect(
43
- checkIfConditionMatches(
43
+ checkIfConditionMatchesProperties(
44
44
  { if: { properties: { parent: { properties: { child: { const: 'hello from child' } } } } } },
45
45
  {
46
46
  parent: { child: 'goodbye from child' },
@@ -504,7 +504,6 @@ export const schemaInlineComputedAttrForMaximumMinimumValues = {
504
504
  properties: {
505
505
  field_a: {
506
506
  type: 'number',
507
- default: 0,
508
507
  },
509
508
  field_b: {
510
509
  type: 'number',
@@ -551,3 +550,408 @@ export const schemaWithJSFLogicAndInlineRule = {
551
550
  },
552
551
  },
553
552
  };
553
+
554
+ export const schemaWithGreaterThanChecksForThreeFields = {
555
+ properties: {
556
+ field_a: {
557
+ type: 'number',
558
+ },
559
+ field_b: {
560
+ type: 'number',
561
+ },
562
+ field_c: {
563
+ type: 'number',
564
+ },
565
+ },
566
+ required: ['field_a', 'field_b'],
567
+ 'x-jsf-logic': {
568
+ validations: {
569
+ require_c: {
570
+ rule: {
571
+ and: [{ '>': [{ var: 'field_a' }, { var: 'field_b' }] }],
572
+ },
573
+ },
574
+ },
575
+ allOf: [
576
+ {
577
+ if: {
578
+ validations: {
579
+ require_c: {
580
+ const: true,
581
+ },
582
+ },
583
+ },
584
+ then: {
585
+ required: ['field_c'],
586
+ },
587
+ else: {
588
+ properties: {
589
+ field_c: false,
590
+ },
591
+ },
592
+ },
593
+ ],
594
+ },
595
+ };
596
+
597
+ export const schemaWithPropertiesCheckAndValidationsInAIf = {
598
+ properties: {
599
+ field_a: {
600
+ type: 'number',
601
+ },
602
+ field_b: {
603
+ type: 'number',
604
+ },
605
+ field_c: {
606
+ type: 'number',
607
+ },
608
+ },
609
+ required: ['field_a', 'field_b'],
610
+ 'x-jsf-logic': {
611
+ validations: {
612
+ require_c: {
613
+ rule: {
614
+ and: [{ '>': [{ var: 'field_a' }, { var: 'field_b' }] }],
615
+ },
616
+ },
617
+ },
618
+ allOf: [
619
+ {
620
+ if: {
621
+ validations: {
622
+ require_c: {
623
+ const: true,
624
+ },
625
+ },
626
+ properties: {
627
+ field_a: {
628
+ const: 10,
629
+ },
630
+ },
631
+ },
632
+ then: {
633
+ required: ['field_c'],
634
+ },
635
+ else: {
636
+ properties: {
637
+ field_c: false,
638
+ },
639
+ },
640
+ },
641
+ ],
642
+ },
643
+ };
644
+
645
+ export const schemaWithChecksAndThenValidationsOnThen = {
646
+ properties: {
647
+ field_a: {
648
+ type: 'number',
649
+ },
650
+ field_b: {
651
+ type: 'number',
652
+ },
653
+ field_c: {
654
+ type: 'number',
655
+ },
656
+ },
657
+ required: ['field_a', 'field_b'],
658
+ 'x-jsf-logic': {
659
+ validations: {
660
+ c_must_be_large: {
661
+ errorMessage: 'Needs more numbers',
662
+ rule: {
663
+ '>': [{ var: 'field_c' }, 200],
664
+ },
665
+ },
666
+ require_c: {
667
+ rule: {
668
+ and: [{ '>': [{ var: 'field_a' }, { var: 'field_b' }] }],
669
+ },
670
+ },
671
+ },
672
+ allOf: [
673
+ {
674
+ if: {
675
+ validations: {
676
+ require_c: {
677
+ const: true,
678
+ },
679
+ },
680
+ },
681
+ then: {
682
+ required: ['field_c'],
683
+ properties: {
684
+ field_c: {
685
+ description: 'I am a description!',
686
+ 'x-jsf-logic-validations': ['c_must_be_large'],
687
+ },
688
+ },
689
+ },
690
+ else: {
691
+ properties: {
692
+ field_c: false,
693
+ },
694
+ },
695
+ },
696
+ ],
697
+ },
698
+ };
699
+
700
+ export const schemaWithComputedValueChecksInIf = {
701
+ properties: {
702
+ field_a: {
703
+ type: 'number',
704
+ },
705
+ field_b: {
706
+ type: 'number',
707
+ },
708
+ field_c: {
709
+ type: 'number',
710
+ },
711
+ },
712
+ required: ['field_a', 'field_b'],
713
+ 'x-jsf-logic': {
714
+ computedValues: {
715
+ require_c: {
716
+ rule: {
717
+ and: [{ '>': [{ var: 'field_a' }, { var: 'field_b' }] }],
718
+ },
719
+ },
720
+ },
721
+ allOf: [
722
+ {
723
+ if: {
724
+ computedValues: {
725
+ require_c: {
726
+ const: true,
727
+ },
728
+ },
729
+ },
730
+ then: {
731
+ required: ['field_c'],
732
+ },
733
+ else: {
734
+ properties: {
735
+ field_c: false,
736
+ },
737
+ },
738
+ },
739
+ ],
740
+ },
741
+ };
742
+
743
+ export const schemaWithMultipleComputedValueChecks = {
744
+ properties: {
745
+ field_a: {
746
+ type: 'number',
747
+ },
748
+ field_b: {
749
+ type: 'number',
750
+ },
751
+ field_c: {
752
+ type: 'number',
753
+ },
754
+ },
755
+ required: ['field_a', 'field_b'],
756
+ 'x-jsf-logic': {
757
+ validations: {
758
+ double_b: {
759
+ errorMessage: 'Must be two times B',
760
+ rule: {
761
+ '>': [{ var: 'field_c' }, { '*': [{ var: 'field_b' }, 2] }],
762
+ },
763
+ },
764
+ },
765
+ computedValues: {
766
+ a_times_two: {
767
+ rule: {
768
+ '*': [{ var: 'field_a' }, 2],
769
+ },
770
+ },
771
+ mod_by_five: {
772
+ rule: {
773
+ '%': [{ var: 'field_b' }, 5],
774
+ },
775
+ },
776
+ },
777
+ allOf: [
778
+ {
779
+ if: {
780
+ computedValues: {
781
+ a_times_two: {
782
+ const: 20,
783
+ },
784
+ mod_by_five: {
785
+ const: 3,
786
+ },
787
+ },
788
+ },
789
+ then: {
790
+ required: ['field_c'],
791
+ properties: {
792
+ field_c: {
793
+ 'x-jsf-logic-validations': ['double_b'],
794
+ title: 'Adding a title.',
795
+ },
796
+ },
797
+ },
798
+ else: {
799
+ properties: {
800
+ field_c: false,
801
+ },
802
+ },
803
+ },
804
+ ],
805
+ },
806
+ };
807
+
808
+ export const schemaWithIfStatementWithComputedValuesAndValidationChecks = {
809
+ properties: {
810
+ field_a: {
811
+ type: 'number',
812
+ },
813
+ field_b: {
814
+ type: 'number',
815
+ },
816
+ field_c: {
817
+ type: 'number',
818
+ },
819
+ },
820
+ required: ['field_a', 'field_b'],
821
+ 'x-jsf-logic': {
822
+ validations: {
823
+ greater_than_b: {
824
+ rule: {
825
+ '>': [{ var: 'field_a' }, { var: 'field_b' }],
826
+ },
827
+ },
828
+ },
829
+ computedValues: {
830
+ a_times_two: {
831
+ rule: {
832
+ '*': [{ var: 'field_a' }, 2],
833
+ },
834
+ },
835
+ },
836
+ allOf: [
837
+ {
838
+ if: {
839
+ computedValues: {
840
+ a_times_two: {
841
+ const: 20,
842
+ },
843
+ },
844
+ validations: {
845
+ greater_than_b: {
846
+ const: true,
847
+ },
848
+ },
849
+ },
850
+ then: {
851
+ required: ['field_c'],
852
+ },
853
+ else: {
854
+ properties: {
855
+ field_c: false,
856
+ },
857
+ },
858
+ },
859
+ ],
860
+ },
861
+ };
862
+
863
+ export const schemaWhereValidationAndComputedValueIsAppliedOnNormalThenStatement = {
864
+ properties: {
865
+ field_a: {
866
+ type: 'number',
867
+ },
868
+ field_b: {
869
+ type: 'number',
870
+ },
871
+ },
872
+ 'x-jsf-logic': {
873
+ computedValues: {
874
+ a_plus_ten: {
875
+ rule: {
876
+ '+': [{ var: 'field_a' }, 10],
877
+ },
878
+ },
879
+ },
880
+ validations: {
881
+ greater_than_a_plus_ten: {
882
+ errorMessage: 'Must be greater than Field A + 10',
883
+ rule: {
884
+ '>': [{ var: 'field_b' }, { '+': [{ var: 'field_a' }, 10] }],
885
+ },
886
+ },
887
+ },
888
+ },
889
+ allOf: [
890
+ {
891
+ if: {
892
+ properties: {
893
+ field_a: {
894
+ const: 20,
895
+ },
896
+ },
897
+ },
898
+ then: {
899
+ properties: {
900
+ field_b: {
901
+ 'x-jsf-logic-computedAttrs': {
902
+ title: 'Must be greater than {{a_plus_ten}}.',
903
+ },
904
+ 'x-jsf-logic-validations': ['greater_than_a_plus_ten'],
905
+ },
906
+ },
907
+ },
908
+ },
909
+ ],
910
+ };
911
+
912
+ export const schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally = {
913
+ required: ['field_a', 'field_b'],
914
+ properties: {
915
+ field_a: {
916
+ type: 'number',
917
+ },
918
+ field_b: {
919
+ type: 'number',
920
+ 'x-jsf-logic-validations': ['greater_than_field_a'],
921
+ },
922
+ },
923
+ 'x-jsf-logic': {
924
+ validations: {
925
+ greater_than_field_a: {
926
+ errorMessage: 'Must be greater than A',
927
+ rule: {
928
+ '>': [{ var: 'field_b' }, { var: 'field_a' }],
929
+ },
930
+ },
931
+ greater_than_two_times_a: {
932
+ errorMessage: 'Must be greater than two times A',
933
+ rule: {
934
+ '>': [{ var: 'field_b' }, { '*': [{ var: 'field_a' }, 2] }],
935
+ },
936
+ },
937
+ },
938
+ },
939
+ allOf: [
940
+ {
941
+ if: {
942
+ properties: {
943
+ field_a: {
944
+ const: 20,
945
+ },
946
+ },
947
+ },
948
+ then: {
949
+ properties: {
950
+ field_b: {
951
+ 'x-jsf-logic-validations': ['greater_than_two_times_a'],
952
+ },
953
+ },
954
+ },
955
+ },
956
+ ],
957
+ };