slice-machine-ui 2.16.2-alpha.jp-cr-ui-fix-invalid-fields-checked.7 → 2.16.2-alpha.jp-cr-ui-fix-invalid-fields-checked.9

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.
@@ -366,7 +366,7 @@ describe("ContentRelationshipFieldPicker", () => {
366
366
  });
367
367
 
368
368
  describe("createContentRelationshipFieldCheckMap", () => {
369
- it("should include existing/valid referenced fields", () => {
369
+ it("should include existing/valid referenced regular root fields", () => {
370
370
  const customType: CustomType = {
371
371
  id: "customType",
372
372
  label: "Custom Type",
@@ -515,21 +515,7 @@ describe("ContentRelationshipFieldPicker", () => {
515
515
  });
516
516
  });
517
517
 
518
- it("should not include non-existing/invalid referenced fields", () => {
519
- const customType2: CustomType = {
520
- id: "customType2",
521
- label: "Custom Type 2",
522
- repeatable: false,
523
- status: true,
524
- json: {
525
- Main: {
526
- booleanField: {
527
- type: "Boolean",
528
- },
529
- },
530
- },
531
- };
532
-
518
+ it("should include a correctly referenced group field", () => {
533
519
  const customType: CustomType = {
534
520
  id: "customType",
535
521
  label: "Custom Type",
@@ -537,22 +523,16 @@ describe("ContentRelationshipFieldPicker", () => {
537
523
  status: true,
538
524
  json: {
539
525
  Main: {
540
- mdField: {
541
- type: "StructuredText",
542
- },
543
- crField: {
544
- type: "Link",
545
- config: {
546
- select: "document",
547
- customtypes: ["customType2"],
548
- },
549
- },
550
526
  groupField: {
551
527
  type: "Group",
552
528
  config: {
529
+ label: "Group Field",
553
530
  fields: {
554
- groupFieldA: {
531
+ booleanField: {
555
532
  type: "Boolean",
533
+ config: {
534
+ label: "Boolean Field",
535
+ },
556
536
  },
557
537
  },
558
538
  },
@@ -566,42 +546,32 @@ describe("ContentRelationshipFieldPicker", () => {
566
546
  {
567
547
  id: "customType",
568
548
  fields: [
569
- "mdField",
570
- "nonExistingField",
571
- {
572
- id: "nonExistingGroup",
573
- fields: ["groupFieldA"],
574
- },
575
- {
576
- id: "crField",
577
- customtypes: [
578
- {
579
- id: "customType2",
580
- fields: ["nonExistingNestedField"],
581
- },
582
- ],
583
- },
584
549
  {
585
550
  id: "groupField",
586
- fields: ["nonExistingGroupField"],
551
+ fields: ["booleanField"],
587
552
  },
588
553
  ],
589
554
  },
590
555
  ],
591
- allCustomTypes: [customType, customType2],
556
+ allCustomTypes: [customType],
592
557
  });
593
558
 
594
559
  expect(result).toEqual({
595
560
  customType: {
596
- mdField: {
597
- type: "checkbox",
598
- value: true,
561
+ groupField: {
562
+ type: "group",
563
+ value: {
564
+ booleanField: {
565
+ type: "checkbox",
566
+ value: true,
567
+ },
568
+ },
599
569
  },
600
570
  },
601
571
  });
602
572
  });
603
573
 
604
- it("should not include an invalid field (uid, slices & choice)", () => {
574
+ it("should include a correctly referenced content relationship field", () => {
605
575
  const customType: CustomType = {
606
576
  id: "customType",
607
577
  label: "Custom Type",
@@ -612,76 +582,21 @@ describe("ContentRelationshipFieldPicker", () => {
612
582
  booleanField: {
613
583
  type: "Boolean",
614
584
  },
615
- typeUid: {
616
- type: "UID",
617
- },
618
- uid: {
619
- type: "Boolean",
620
- },
621
- choice: {
622
- type: "Choice",
623
- config: {
624
- choices: {
625
- choice1: {
626
- type: "Boolean",
627
- },
628
- },
629
- },
630
- },
631
- slices: {
632
- type: "Slices",
633
- config: {
634
- choices: {
635
- slice1: {
636
- type: "SharedSlice",
637
- },
638
- },
639
- },
640
- },
641
585
  },
642
586
  },
643
587
  };
644
-
645
- const result = convertLinkCustomtypesToFieldCheckMap({
646
- linkCustomtypes: [
647
- {
648
- id: "customType",
649
- fields: ["booleanField", "typeUid", "uid", "choice", "slices"],
650
- },
651
- ],
652
- allCustomTypes: [customType],
653
- });
654
-
655
- expect(result).toEqual({
656
- customType: {
657
- booleanField: {
658
- type: "checkbox",
659
- value: true,
660
- },
661
- },
662
- });
663
- });
664
-
665
- it("should include a correctly referenced group field", () => {
666
- const customType: CustomType = {
667
- id: "customType",
668
- label: "Custom Type",
588
+ const customTypeWithContentRelationship: CustomType = {
589
+ id: "customTypeWithContentRelationship",
590
+ label: "Custom Type With Content Relationship",
669
591
  repeatable: false,
670
592
  status: true,
671
593
  json: {
672
594
  Main: {
673
- groupField: {
674
- type: "Group",
595
+ contentRelationshipField: {
596
+ type: "Link",
675
597
  config: {
676
- label: "Group Field",
677
- fields: {
678
- booleanField: {
679
- type: "Boolean",
680
- config: {
681
- label: "Boolean Field",
682
- },
683
- },
684
- },
598
+ select: "document",
599
+ customtypes: ["customType"],
685
600
  },
686
601
  },
687
602
  },
@@ -691,26 +606,33 @@ describe("ContentRelationshipFieldPicker", () => {
691
606
  const result = convertLinkCustomtypesToFieldCheckMap({
692
607
  linkCustomtypes: [
693
608
  {
694
- id: "customType",
609
+ id: "customTypeWithContentRelationship",
695
610
  fields: [
696
611
  {
697
- id: "groupField",
698
- fields: ["booleanField"],
612
+ id: "contentRelationshipField",
613
+ customtypes: [
614
+ {
615
+ id: "customType",
616
+ fields: ["booleanField"],
617
+ },
618
+ ],
699
619
  },
700
620
  ],
701
621
  },
702
622
  ],
703
- allCustomTypes: [customType],
623
+ allCustomTypes: [customType, customTypeWithContentRelationship],
704
624
  });
705
625
 
706
626
  expect(result).toEqual({
707
- customType: {
708
- groupField: {
709
- type: "group",
627
+ customTypeWithContentRelationship: {
628
+ contentRelationshipField: {
629
+ type: "contentRelationship",
710
630
  value: {
711
- booleanField: {
712
- type: "checkbox",
713
- value: true,
631
+ customType: {
632
+ booleanField: {
633
+ type: "checkbox",
634
+ value: true,
635
+ },
714
636
  },
715
637
  },
716
638
  },
@@ -809,7 +731,187 @@ describe("ContentRelationshipFieldPicker", () => {
809
731
  });
810
732
  });
811
733
 
812
- it("should not include a field referenced as a group field when it's not one", () => {
734
+ it("should discard non-existing/invalid referenced fields", () => {
735
+ const customType2: CustomType = {
736
+ id: "customType2",
737
+ label: "Custom Type 2",
738
+ repeatable: false,
739
+ status: true,
740
+ json: {
741
+ Main: {
742
+ booleanField: {
743
+ type: "Boolean",
744
+ },
745
+ },
746
+ },
747
+ };
748
+
749
+ const customType: CustomType = {
750
+ id: "customType",
751
+ label: "Custom Type",
752
+ repeatable: false,
753
+ status: true,
754
+ json: {
755
+ Main: {
756
+ mdField: {
757
+ type: "StructuredText",
758
+ },
759
+ crField: {
760
+ type: "Link",
761
+ config: {
762
+ select: "document",
763
+ customtypes: ["customType2"],
764
+ },
765
+ },
766
+ groupField: {
767
+ type: "Group",
768
+ config: {
769
+ fields: {
770
+ groupFieldA: {
771
+ type: "Boolean",
772
+ },
773
+ },
774
+ },
775
+ },
776
+ },
777
+ },
778
+ };
779
+
780
+ const result = convertLinkCustomtypesToFieldCheckMap({
781
+ linkCustomtypes: [
782
+ {
783
+ id: "customType",
784
+ fields: [
785
+ "mdField",
786
+ "nonExistingField",
787
+ {
788
+ id: "nonExistingGroup",
789
+ fields: ["groupFieldA"],
790
+ },
791
+ {
792
+ id: "crField",
793
+ customtypes: [
794
+ {
795
+ id: "customType2",
796
+ fields: ["nonExistingNestedField"],
797
+ },
798
+ ],
799
+ },
800
+ {
801
+ id: "groupField",
802
+ fields: ["nonExistingGroupField"],
803
+ },
804
+ ],
805
+ },
806
+ ],
807
+ allCustomTypes: [customType, customType2],
808
+ });
809
+
810
+ expect(result).toEqual({
811
+ customType: {
812
+ mdField: {
813
+ type: "checkbox",
814
+ value: true,
815
+ },
816
+ },
817
+ });
818
+ });
819
+
820
+ it("should discard invalid fields (uid, slices & choice)", () => {
821
+ const customType: CustomType = {
822
+ id: "customType",
823
+ label: "Custom Type",
824
+ repeatable: false,
825
+ status: true,
826
+ json: {
827
+ Main: {
828
+ booleanField: {
829
+ type: "Boolean",
830
+ },
831
+ typeUid: {
832
+ type: "UID",
833
+ },
834
+ uid: {
835
+ type: "Boolean",
836
+ },
837
+ choice: {
838
+ type: "Choice",
839
+ config: {
840
+ choices: {
841
+ choice1: {
842
+ type: "Boolean",
843
+ },
844
+ },
845
+ },
846
+ },
847
+ slices: {
848
+ type: "Slices",
849
+ config: {
850
+ choices: {
851
+ slice1: {
852
+ type: "SharedSlice",
853
+ },
854
+ },
855
+ },
856
+ },
857
+ },
858
+ },
859
+ };
860
+
861
+ const result = convertLinkCustomtypesToFieldCheckMap({
862
+ linkCustomtypes: [
863
+ {
864
+ id: "customType",
865
+ fields: ["booleanField", "typeUid", "uid", "choice", "slices"],
866
+ },
867
+ ],
868
+ allCustomTypes: [customType],
869
+ });
870
+
871
+ expect(result).toEqual({
872
+ customType: {
873
+ booleanField: {
874
+ type: "checkbox",
875
+ value: true,
876
+ },
877
+ },
878
+ });
879
+ });
880
+
881
+ it("should discard a regular field referenced as a group field", () => {
882
+ const customType: CustomType = {
883
+ id: "customType",
884
+ label: "Custom Type",
885
+ repeatable: false,
886
+ status: true,
887
+ json: {
888
+ Main: {
889
+ booleanField: {
890
+ type: "Boolean",
891
+ },
892
+ },
893
+ },
894
+ };
895
+
896
+ const result = convertLinkCustomtypesToFieldCheckMap({
897
+ linkCustomtypes: [
898
+ {
899
+ id: "customType",
900
+ fields: [
901
+ {
902
+ id: "booleanField",
903
+ fields: ["something"],
904
+ },
905
+ ],
906
+ },
907
+ ],
908
+ allCustomTypes: [customType],
909
+ });
910
+
911
+ expect(result).toEqual({});
912
+ });
913
+
914
+ it("should discard a regular field referenced as a content relationship field", () => {
813
915
  const customType: CustomType = {
814
916
  id: "customType",
815
917
  label: "Custom Type",
@@ -831,7 +933,7 @@ describe("ContentRelationshipFieldPicker", () => {
831
933
  fields: [
832
934
  {
833
935
  id: "booleanField",
834
- fields: ["fieldA"],
936
+ customtypes: [],
835
937
  },
836
938
  ],
837
939
  },
@@ -842,7 +944,7 @@ describe("ContentRelationshipFieldPicker", () => {
842
944
  expect(result).toEqual({});
843
945
  });
844
946
 
845
- it("should not include a field referencing a group as a regular field (string/no picked fields)", () => {
947
+ it("should discard a group field referenced as a regular field (string/no picked fields)", () => {
846
948
  const customType: CustomType = {
847
949
  id: "customType",
848
950
  label: "Custom Type",
@@ -915,7 +1017,7 @@ describe("ContentRelationshipFieldPicker", () => {
915
1017
  expect(result).toEqual({});
916
1018
  });
917
1019
 
918
- it("should not include a field referenced as a content relationship field when it's not one", () => {
1020
+ it("should discard a content relationship field reference to a regular field", () => {
919
1021
  const customTypeA: CustomType = {
920
1022
  id: "customTypeA",
921
1023
  label: "Custom Type A",
@@ -966,7 +1068,7 @@ describe("ContentRelationshipFieldPicker", () => {
966
1068
  expect(result).toEqual({});
967
1069
  });
968
1070
 
969
- it("should not include a content relationship field if it references a non existing custom type", () => {
1071
+ it("should discard a content relationship field if it references a non existing custom type", () => {
970
1072
  const customTypeWithField: CustomType = {
971
1073
  id: "customTypeWithField",
972
1074
  label: "Custom Type With Field",
@@ -1052,10 +1154,10 @@ describe("ContentRelationshipFieldPicker", () => {
1052
1154
  expect(result).toEqual({});
1053
1155
  });
1054
1156
 
1055
- it("should not include a regular field referenced as a content relationship field", () => {
1056
- const customType: CustomType = {
1057
- id: "customType",
1058
- label: "Custom Type",
1157
+ it("should not consider content relationship fields referenced at a depth above 2", () => {
1158
+ const thirdCustomType: CustomType = {
1159
+ id: "thirdCustomType",
1160
+ label: "Third Custom Type",
1059
1161
  repeatable: false,
1060
1162
  status: true,
1061
1163
  json: {
@@ -1066,35 +1168,36 @@ describe("ContentRelationshipFieldPicker", () => {
1066
1168
  },
1067
1169
  },
1068
1170
  };
1069
-
1070
- const result = convertLinkCustomtypesToFieldCheckMap({
1071
- linkCustomtypes: [
1072
- {
1073
- id: "customType",
1074
- fields: [
1075
- {
1076
- id: "booleanField",
1077
- customtypes: [],
1171
+ const secondCustomType: CustomType = {
1172
+ id: "secondCustomType",
1173
+ label: "Second Custom Type",
1174
+ repeatable: false,
1175
+ status: true,
1176
+ json: {
1177
+ Main: {
1178
+ secondCr: {
1179
+ type: "Link",
1180
+ config: {
1181
+ select: "document",
1182
+ customtypes: ["customType2"],
1078
1183
  },
1079
- ],
1184
+ },
1080
1185
  },
1081
- ],
1082
- allCustomTypes: [customType],
1083
- });
1084
-
1085
- expect(result).toEqual({});
1086
- });
1087
-
1088
- it("should not include a regular field referenced as a group field", () => {
1089
- const customType: CustomType = {
1090
- id: "customType",
1091
- label: "Custom Type",
1186
+ },
1187
+ };
1188
+ const firstCustomType: CustomType = {
1189
+ id: "firstCustomType",
1190
+ label: "First Custom Type",
1092
1191
  repeatable: false,
1093
1192
  status: true,
1094
1193
  json: {
1095
1194
  Main: {
1096
- booleanField: {
1097
- type: "Boolean",
1195
+ firstCr: {
1196
+ type: "Link",
1197
+ config: {
1198
+ select: "document",
1199
+ customtypes: ["customType"],
1200
+ },
1098
1201
  },
1099
1202
  },
1100
1203
  },
@@ -1103,16 +1206,31 @@ describe("ContentRelationshipFieldPicker", () => {
1103
1206
  const result = convertLinkCustomtypesToFieldCheckMap({
1104
1207
  linkCustomtypes: [
1105
1208
  {
1106
- id: "customType",
1209
+ id: "firstCustomType",
1107
1210
  fields: [
1108
1211
  {
1109
- id: "booleanField",
1110
- fields: [],
1212
+ id: "firstCr",
1213
+ customtypes: [
1214
+ {
1215
+ id: "secondCustomType",
1216
+ fields: [
1217
+ {
1218
+ id: "secondCr",
1219
+ // @ts-expect-error - this is a test
1220
+ customtypes: [
1221
+ {
1222
+ id: "thirdCustomType",
1223
+ },
1224
+ ],
1225
+ },
1226
+ ],
1227
+ },
1228
+ ],
1111
1229
  },
1112
1230
  ],
1113
1231
  },
1114
1232
  ],
1115
- allCustomTypes: [customType],
1233
+ allCustomTypes: [secondCustomType, thirdCustomType, firstCustomType],
1116
1234
  });
1117
1235
 
1118
1236
  expect(result).toEqual({});