@capillarytech/creatives-library 8.0.216 → 8.0.218
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/utils/commonUtils.js +59 -0
- package/utils/tests/commonUtil.test.js +473 -1
- package/utils/tests/vendorDataTransformers.test.js +431 -0
- package/utils/vendorDataTransformers.js +70 -11
- package/v2Containers/Whatsapp/constants.js +1 -1
- package/v2Containers/Whatsapp/index.js +58 -24
- package/v2Containers/Whatsapp/tests/index.test.js +250 -83
package/package.json
CHANGED
package/utils/commonUtils.js
CHANGED
|
@@ -429,3 +429,62 @@ export const validateInAppContent = async (formData, options) => {
|
|
|
429
429
|
// Errors already reported via the 'onError' callback passed to _validatePlatformSpecificContent
|
|
430
430
|
return false;
|
|
431
431
|
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Validate carousel cards for errors
|
|
435
|
+
* Checks each card for body errors, missing text, missing media, and unsaved buttons
|
|
436
|
+
*
|
|
437
|
+
* @param {Array} carouselData - Array of carousel card objects
|
|
438
|
+
* @param {string} mediaType - Media type ('image' or 'video', case-insensitive)
|
|
439
|
+
* @param {Object} options - Optional configuration
|
|
440
|
+
* @param {string} options.imageConstant - Constant for image media type (default: 'IMAGE')
|
|
441
|
+
* @param {string} options.videoConstant - Constant for video media type (default: 'VIDEO')
|
|
442
|
+
* @returns {Object} Object containing validation results: { isValid: boolean, reasons: string[] }
|
|
443
|
+
*/
|
|
444
|
+
export const validateCarouselCards = (
|
|
445
|
+
carouselData = [],
|
|
446
|
+
mediaType = '',
|
|
447
|
+
options = {}
|
|
448
|
+
) => {
|
|
449
|
+
const {
|
|
450
|
+
imageConstant = 'IMAGE',
|
|
451
|
+
videoConstant = 'VIDEO',
|
|
452
|
+
} = options;
|
|
453
|
+
|
|
454
|
+
const reasons = [];
|
|
455
|
+
const normalizedMediaType = mediaType?.toLowerCase() || '';
|
|
456
|
+
const normalizedImageType = imageConstant?.toLowerCase() || '';
|
|
457
|
+
const normalizedVideoType = videoConstant?.toLowerCase() || '';
|
|
458
|
+
|
|
459
|
+
carouselData?.forEach((card, idx) => {
|
|
460
|
+
// Check for body errors
|
|
461
|
+
if (card?.bodyError) {
|
|
462
|
+
reasons.push(`card ${idx + 1}: bodyError=${card.bodyError}`);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Check for empty body text
|
|
466
|
+
if (!card?.bodyText) {
|
|
467
|
+
reasons.push(`card ${idx + 1}: bodyText empty`);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Check for missing image source when media type is image
|
|
471
|
+
if (normalizedMediaType === normalizedImageType && !card?.imageSrc) {
|
|
472
|
+
reasons.push(`card ${idx + 1}: imageSrc missing`);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Check for missing video source when media type is video
|
|
476
|
+
if (normalizedMediaType === normalizedVideoType && !card?.videoSrc) {
|
|
477
|
+
reasons.push(`card ${idx + 1}: videoSrc missing`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Check if all buttons are saved
|
|
481
|
+
if (card?.buttons && !card.buttons.every((b) => b?.isSaved === true)) {
|
|
482
|
+
reasons.push(`card ${idx + 1}: some buttons not saved`);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
isValid: reasons.length === 0,
|
|
488
|
+
reasons,
|
|
489
|
+
};
|
|
490
|
+
};
|
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
validateMobilePushContent,
|
|
4
4
|
validateInAppContent,
|
|
5
5
|
getChannelData,
|
|
6
|
-
extractContent,
|
|
6
|
+
extractContent,
|
|
7
|
+
addBaseToTemplate,
|
|
8
|
+
validateCarouselCards,
|
|
7
9
|
} from "../commonUtils";
|
|
8
10
|
import { SMS_TRAI_VAR } from '../../v2Containers/SmsTrai/Edit/constants';
|
|
9
11
|
import { ANDROID, IOS } from '../../v2Containers/CreativesContainer/constants';
|
|
@@ -656,3 +658,473 @@ describe("extractContent", () => {
|
|
|
656
658
|
expect(extractContent({ title: "T", message: "M" })).toBe("T M");
|
|
657
659
|
});
|
|
658
660
|
});
|
|
661
|
+
|
|
662
|
+
describe("validateCarouselCards", () => {
|
|
663
|
+
describe("Valid carousel cards", () => {
|
|
664
|
+
it("should return isValid true for valid image carousel cards", () => {
|
|
665
|
+
const carouselData = [
|
|
666
|
+
{
|
|
667
|
+
bodyText: "Card 1 text",
|
|
668
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
669
|
+
buttons: [{ isSaved: true }],
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
bodyText: "Card 2 text",
|
|
673
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
674
|
+
buttons: [{ isSaved: true }, { isSaved: true }],
|
|
675
|
+
},
|
|
676
|
+
];
|
|
677
|
+
|
|
678
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
679
|
+
imageConstant: "IMAGE",
|
|
680
|
+
videoConstant: "VIDEO",
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
expect(result.isValid).toBe(true);
|
|
684
|
+
expect(result.reasons).toEqual([]);
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
it("should return isValid true for valid video carousel cards", () => {
|
|
688
|
+
const carouselData = [
|
|
689
|
+
{
|
|
690
|
+
bodyText: "Card 1 text",
|
|
691
|
+
videoSrc: "https://example.com/video1.mp4",
|
|
692
|
+
buttons: [{ isSaved: true }],
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
bodyText: "Card 2 text",
|
|
696
|
+
videoSrc: "https://example.com/video2.mp4",
|
|
697
|
+
buttons: [{ isSaved: true }],
|
|
698
|
+
},
|
|
699
|
+
];
|
|
700
|
+
|
|
701
|
+
const result = validateCarouselCards(carouselData, "video", {
|
|
702
|
+
imageConstant: "IMAGE",
|
|
703
|
+
videoConstant: "VIDEO",
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
expect(result.isValid).toBe(true);
|
|
707
|
+
expect(result.reasons).toEqual([]);
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it("should return isValid true for cards without buttons", () => {
|
|
711
|
+
const carouselData = [
|
|
712
|
+
{
|
|
713
|
+
bodyText: "Card 1 text",
|
|
714
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
bodyText: "Card 2 text",
|
|
718
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
719
|
+
},
|
|
720
|
+
];
|
|
721
|
+
|
|
722
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
723
|
+
imageConstant: "IMAGE",
|
|
724
|
+
videoConstant: "VIDEO",
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
expect(result.isValid).toBe(true);
|
|
728
|
+
expect(result.reasons).toEqual([]);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
describe("Body errors", () => {
|
|
733
|
+
it("should detect body errors in carousel cards", () => {
|
|
734
|
+
const carouselData = [
|
|
735
|
+
{
|
|
736
|
+
bodyText: "Card 1 text",
|
|
737
|
+
bodyError: "Invalid characters",
|
|
738
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
739
|
+
buttons: [{ isSaved: true }],
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
bodyText: "Card 2 text",
|
|
743
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
744
|
+
buttons: [{ isSaved: true }],
|
|
745
|
+
},
|
|
746
|
+
];
|
|
747
|
+
|
|
748
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
749
|
+
imageConstant: "IMAGE",
|
|
750
|
+
videoConstant: "VIDEO",
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
expect(result.isValid).toBe(false);
|
|
754
|
+
expect(result.reasons).toContain("card 1: bodyError=Invalid characters");
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
it("should detect body errors in multiple cards", () => {
|
|
758
|
+
const carouselData = [
|
|
759
|
+
{
|
|
760
|
+
bodyText: "Card 1 text",
|
|
761
|
+
bodyError: "Error 1",
|
|
762
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
bodyText: "Card 2 text",
|
|
766
|
+
bodyError: "Error 2",
|
|
767
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
768
|
+
},
|
|
769
|
+
];
|
|
770
|
+
|
|
771
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
772
|
+
imageConstant: "IMAGE",
|
|
773
|
+
videoConstant: "VIDEO",
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
expect(result.isValid).toBe(false);
|
|
777
|
+
expect(result.reasons).toContain("card 1: bodyError=Error 1");
|
|
778
|
+
expect(result.reasons).toContain("card 2: bodyError=Error 2");
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
describe("Empty body text", () => {
|
|
783
|
+
it("should detect empty body text", () => {
|
|
784
|
+
const carouselData = [
|
|
785
|
+
{
|
|
786
|
+
bodyText: "",
|
|
787
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
788
|
+
buttons: [{ isSaved: true }],
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
bodyText: "Card 2 text",
|
|
792
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
793
|
+
buttons: [{ isSaved: true }],
|
|
794
|
+
},
|
|
795
|
+
];
|
|
796
|
+
|
|
797
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
798
|
+
imageConstant: "IMAGE",
|
|
799
|
+
videoConstant: "VIDEO",
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
expect(result.isValid).toBe(false);
|
|
803
|
+
expect(result.reasons).toContain("card 1: bodyText empty");
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
it("should detect missing body text", () => {
|
|
807
|
+
const carouselData = [
|
|
808
|
+
{
|
|
809
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
810
|
+
buttons: [{ isSaved: true }],
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
bodyText: "Card 2 text",
|
|
814
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
815
|
+
buttons: [{ isSaved: true }],
|
|
816
|
+
},
|
|
817
|
+
];
|
|
818
|
+
|
|
819
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
820
|
+
imageConstant: "IMAGE",
|
|
821
|
+
videoConstant: "VIDEO",
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
expect(result.isValid).toBe(false);
|
|
825
|
+
expect(result.reasons).toContain("card 1: bodyText empty");
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
describe("Missing image source", () => {
|
|
830
|
+
it("should detect missing imageSrc for image carousel", () => {
|
|
831
|
+
const carouselData = [
|
|
832
|
+
{
|
|
833
|
+
bodyText: "Card 1 text",
|
|
834
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
835
|
+
buttons: [{ isSaved: true }],
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
bodyText: "Card 2 text",
|
|
839
|
+
buttons: [{ isSaved: true }],
|
|
840
|
+
},
|
|
841
|
+
];
|
|
842
|
+
|
|
843
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
844
|
+
imageConstant: "IMAGE",
|
|
845
|
+
videoConstant: "VIDEO",
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
expect(result.isValid).toBe(false);
|
|
849
|
+
expect(result.reasons).toContain("card 2: imageSrc missing");
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
it("should not check imageSrc for video carousel", () => {
|
|
853
|
+
const carouselData = [
|
|
854
|
+
{
|
|
855
|
+
bodyText: "Card 1 text",
|
|
856
|
+
videoSrc: "https://example.com/video1.mp4",
|
|
857
|
+
buttons: [{ isSaved: true }],
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
bodyText: "Card 2 text",
|
|
861
|
+
videoSrc: "https://example.com/video2.mp4",
|
|
862
|
+
buttons: [{ isSaved: true }],
|
|
863
|
+
},
|
|
864
|
+
];
|
|
865
|
+
|
|
866
|
+
const result = validateCarouselCards(carouselData, "video", {
|
|
867
|
+
imageConstant: "IMAGE",
|
|
868
|
+
videoConstant: "VIDEO",
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
expect(result.isValid).toBe(true);
|
|
872
|
+
expect(result.reasons).not.toContain(expect.stringContaining("imageSrc"));
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
describe("Missing video source", () => {
|
|
877
|
+
it("should detect missing videoSrc for video carousel", () => {
|
|
878
|
+
const carouselData = [
|
|
879
|
+
{
|
|
880
|
+
bodyText: "Card 1 text",
|
|
881
|
+
videoSrc: "https://example.com/video1.mp4",
|
|
882
|
+
buttons: [{ isSaved: true }],
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
bodyText: "Card 2 text",
|
|
886
|
+
buttons: [{ isSaved: true }],
|
|
887
|
+
},
|
|
888
|
+
];
|
|
889
|
+
|
|
890
|
+
const result = validateCarouselCards(carouselData, "video", {
|
|
891
|
+
imageConstant: "IMAGE",
|
|
892
|
+
videoConstant: "VIDEO",
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
expect(result.isValid).toBe(false);
|
|
896
|
+
expect(result.reasons).toContain("card 2: videoSrc missing");
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
it("should not check videoSrc for image carousel", () => {
|
|
900
|
+
const carouselData = [
|
|
901
|
+
{
|
|
902
|
+
bodyText: "Card 1 text",
|
|
903
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
904
|
+
buttons: [{ isSaved: true }],
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
bodyText: "Card 2 text",
|
|
908
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
909
|
+
buttons: [{ isSaved: true }],
|
|
910
|
+
},
|
|
911
|
+
];
|
|
912
|
+
|
|
913
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
914
|
+
imageConstant: "IMAGE",
|
|
915
|
+
videoConstant: "VIDEO",
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
expect(result.isValid).toBe(true);
|
|
919
|
+
expect(result.reasons).not.toContain(expect.stringContaining("videoSrc"));
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
describe("Unsaved buttons", () => {
|
|
924
|
+
it("should detect unsaved buttons", () => {
|
|
925
|
+
const carouselData = [
|
|
926
|
+
{
|
|
927
|
+
bodyText: "Card 1 text",
|
|
928
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
929
|
+
buttons: [{ isSaved: false }],
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
bodyText: "Card 2 text",
|
|
933
|
+
imageSrc: "https://example.com/image2.jpg",
|
|
934
|
+
buttons: [{ isSaved: true }],
|
|
935
|
+
},
|
|
936
|
+
];
|
|
937
|
+
|
|
938
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
939
|
+
imageConstant: "IMAGE",
|
|
940
|
+
videoConstant: "VIDEO",
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
expect(result.isValid).toBe(false);
|
|
944
|
+
expect(result.reasons).toContain("card 1: some buttons not saved");
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("should detect when some buttons are saved and some are not", () => {
|
|
948
|
+
const carouselData = [
|
|
949
|
+
{
|
|
950
|
+
bodyText: "Card 1 text",
|
|
951
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
952
|
+
buttons: [{ isSaved: true }, { isSaved: false }],
|
|
953
|
+
},
|
|
954
|
+
];
|
|
955
|
+
|
|
956
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
957
|
+
imageConstant: "IMAGE",
|
|
958
|
+
videoConstant: "VIDEO",
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
expect(result.isValid).toBe(false);
|
|
962
|
+
expect(result.reasons).toContain("card 1: some buttons not saved");
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
it("should pass when all buttons are saved", () => {
|
|
966
|
+
const carouselData = [
|
|
967
|
+
{
|
|
968
|
+
bodyText: "Card 1 text",
|
|
969
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
970
|
+
buttons: [{ isSaved: true }, { isSaved: true }],
|
|
971
|
+
},
|
|
972
|
+
];
|
|
973
|
+
|
|
974
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
975
|
+
imageConstant: "IMAGE",
|
|
976
|
+
videoConstant: "VIDEO",
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
expect(result.isValid).toBe(true);
|
|
980
|
+
expect(result.reasons).not.toContain(expect.stringContaining("buttons"));
|
|
981
|
+
});
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
describe("Multiple errors", () => {
|
|
985
|
+
it("should collect all errors from a single card", () => {
|
|
986
|
+
const carouselData = [
|
|
987
|
+
{
|
|
988
|
+
bodyError: "Error message",
|
|
989
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
990
|
+
buttons: [{ isSaved: false }],
|
|
991
|
+
},
|
|
992
|
+
];
|
|
993
|
+
|
|
994
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
995
|
+
imageConstant: "IMAGE",
|
|
996
|
+
videoConstant: "VIDEO",
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
expect(result.isValid).toBe(false);
|
|
1000
|
+
expect(result.reasons).toContain("card 1: bodyError=Error message");
|
|
1001
|
+
expect(result.reasons).toContain("card 1: bodyText empty");
|
|
1002
|
+
expect(result.reasons).toContain("card 1: some buttons not saved");
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
it("should collect errors from multiple cards", () => {
|
|
1006
|
+
const carouselData = [
|
|
1007
|
+
{
|
|
1008
|
+
bodyError: "Error 1",
|
|
1009
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
1010
|
+
},
|
|
1011
|
+
{
|
|
1012
|
+
bodyText: "Card 2 text",
|
|
1013
|
+
buttons: [{ isSaved: false }],
|
|
1014
|
+
},
|
|
1015
|
+
];
|
|
1016
|
+
|
|
1017
|
+
const result = validateCarouselCards(carouselData, "image", {
|
|
1018
|
+
imageConstant: "IMAGE",
|
|
1019
|
+
videoConstant: "VIDEO",
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
expect(result.isValid).toBe(false);
|
|
1023
|
+
expect(result.reasons.length).toBeGreaterThan(1);
|
|
1024
|
+
expect(result.reasons).toContain("card 1: bodyError=Error 1");
|
|
1025
|
+
expect(result.reasons).toContain("card 1: bodyText empty");
|
|
1026
|
+
expect(result.reasons).toContain("card 2: imageSrc missing");
|
|
1027
|
+
expect(result.reasons).toContain("card 2: some buttons not saved");
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
describe("Case insensitivity", () => {
|
|
1032
|
+
it("should handle uppercase media type", () => {
|
|
1033
|
+
const carouselData = [
|
|
1034
|
+
{
|
|
1035
|
+
bodyText: "Card 1 text",
|
|
1036
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
1037
|
+
buttons: [{ isSaved: true }],
|
|
1038
|
+
},
|
|
1039
|
+
];
|
|
1040
|
+
|
|
1041
|
+
const result = validateCarouselCards(carouselData, "IMAGE", {
|
|
1042
|
+
imageConstant: "IMAGE",
|
|
1043
|
+
videoConstant: "VIDEO",
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
expect(result.isValid).toBe(true);
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
it("should handle mixed case media type", () => {
|
|
1050
|
+
const carouselData = [
|
|
1051
|
+
{
|
|
1052
|
+
bodyText: "Card 1 text",
|
|
1053
|
+
videoSrc: "https://example.com/video1.mp4",
|
|
1054
|
+
buttons: [{ isSaved: true }],
|
|
1055
|
+
},
|
|
1056
|
+
];
|
|
1057
|
+
|
|
1058
|
+
const result = validateCarouselCards(carouselData, "ViDeO", {
|
|
1059
|
+
imageConstant: "IMAGE",
|
|
1060
|
+
videoConstant: "VIDEO",
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
expect(result.isValid).toBe(true);
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
describe("Edge cases", () => {
|
|
1068
|
+
it("should handle empty array", () => {
|
|
1069
|
+
const result = validateCarouselCards([], "image", {
|
|
1070
|
+
imageConstant: "IMAGE",
|
|
1071
|
+
videoConstant: "VIDEO",
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
expect(result.isValid).toBe(true);
|
|
1075
|
+
expect(result.reasons).toEqual([]);
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
it("should handle null carouselData", () => {
|
|
1079
|
+
const result = validateCarouselCards(null, "image", {
|
|
1080
|
+
imageConstant: "IMAGE",
|
|
1081
|
+
videoConstant: "VIDEO",
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
expect(result.isValid).toBe(true);
|
|
1085
|
+
expect(result.reasons).toEqual([]);
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
it("should handle undefined carouselData", () => {
|
|
1089
|
+
const result = validateCarouselCards(undefined, "image", {
|
|
1090
|
+
imageConstant: "IMAGE",
|
|
1091
|
+
videoConstant: "VIDEO",
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
expect(result.isValid).toBe(true);
|
|
1095
|
+
expect(result.reasons).toEqual([]);
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
it("should handle empty media type", () => {
|
|
1099
|
+
const carouselData = [
|
|
1100
|
+
{
|
|
1101
|
+
bodyText: "Card 1 text",
|
|
1102
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
1103
|
+
buttons: [{ isSaved: true }],
|
|
1104
|
+
},
|
|
1105
|
+
];
|
|
1106
|
+
|
|
1107
|
+
const result = validateCarouselCards(carouselData, "", {
|
|
1108
|
+
imageConstant: "IMAGE",
|
|
1109
|
+
videoConstant: "VIDEO",
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
// Should not check for imageSrc or videoSrc when mediaType is empty
|
|
1113
|
+
expect(result.isValid).toBe(true);
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
it("should use default constants when options are not provided", () => {
|
|
1117
|
+
const carouselData = [
|
|
1118
|
+
{
|
|
1119
|
+
bodyText: "Card 1 text",
|
|
1120
|
+
imageSrc: "https://example.com/image1.jpg",
|
|
1121
|
+
buttons: [{ isSaved: true }],
|
|
1122
|
+
},
|
|
1123
|
+
];
|
|
1124
|
+
|
|
1125
|
+
const result = validateCarouselCards(carouselData, "image");
|
|
1126
|
+
|
|
1127
|
+
expect(result.isValid).toBe(true);
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
});
|