@usertour/helpers 0.0.51 → 0.0.53
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/dist/__tests__/content-helper.test.cjs +540 -65
- package/dist/__tests__/content-helper.test.js +542 -58
- package/dist/{chunk-YR6T3KNN.js → chunk-2TMOS3DN.js} +2 -18
- package/dist/{chunk-QWYOGIRR.js → chunk-S2HECK2C.js} +2 -1
- package/dist/content-helper.cjs +1 -19
- package/dist/content-helper.d.cts +4 -19
- package/dist/content-helper.d.ts +4 -19
- package/dist/content-helper.js +1 -5
- package/dist/error.cjs +2 -1
- package/dist/error.js +1 -1
- package/dist/index.cjs +3 -20
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -6
- package/package.json +2 -2
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
duplicateChecklistData,
|
|
3
3
|
duplicateConfig,
|
|
4
4
|
duplicateData,
|
|
5
|
-
|
|
5
|
+
duplicateLauncherData,
|
|
6
|
+
duplicateStep,
|
|
6
7
|
duplicateTarget,
|
|
7
8
|
duplicateTriggers,
|
|
8
9
|
extractQuestionData,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
isQuestionElement,
|
|
14
15
|
isRestrictedType,
|
|
15
16
|
processQuestionElements
|
|
16
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-2TMOS3DN.js";
|
|
17
18
|
import "../chunk-7ODE2AIC.js";
|
|
18
19
|
import "../chunk-SIG4WTEF.js";
|
|
19
20
|
import "../chunk-YYIGUZNZ.js";
|
|
@@ -453,6 +454,69 @@ describe("duplicateTriggers", () => {
|
|
|
453
454
|
expect(result[0].actions).toBeUndefined();
|
|
454
455
|
expect(result[0].conditions).toBeUndefined();
|
|
455
456
|
});
|
|
457
|
+
test("should handle empty array", () => {
|
|
458
|
+
const triggers = [];
|
|
459
|
+
const result = duplicateTriggers(triggers);
|
|
460
|
+
expect(result).toEqual([]);
|
|
461
|
+
});
|
|
462
|
+
test("should handle multiple triggers", () => {
|
|
463
|
+
const triggers = [
|
|
464
|
+
{
|
|
465
|
+
id: "trigger-1",
|
|
466
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
|
|
467
|
+
conditions: []
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
id: "trigger-2",
|
|
471
|
+
actions: [],
|
|
472
|
+
conditions: [{ id: "condition-1", type: "test", operators: "and", data: {} }]
|
|
473
|
+
}
|
|
474
|
+
];
|
|
475
|
+
const result = duplicateTriggers(triggers);
|
|
476
|
+
expect(result).toHaveLength(2);
|
|
477
|
+
expect(result[0].id).toBe("mock-cuid");
|
|
478
|
+
expect(result[1].id).toBe("mock-cuid");
|
|
479
|
+
expect(result[0].actions[0].id).toBe("regenerated-action-1");
|
|
480
|
+
expect(result[1].conditions[0].id).toBe("regenerated-condition-1");
|
|
481
|
+
});
|
|
482
|
+
test("should preserve other trigger properties", () => {
|
|
483
|
+
const triggers = [
|
|
484
|
+
{
|
|
485
|
+
id: "trigger-1",
|
|
486
|
+
customType: "click",
|
|
487
|
+
customSelector: ".button",
|
|
488
|
+
delay: 1e3,
|
|
489
|
+
actions: [],
|
|
490
|
+
conditions: []
|
|
491
|
+
}
|
|
492
|
+
];
|
|
493
|
+
const result = duplicateTriggers(triggers);
|
|
494
|
+
expect(result[0].customType).toBe("click");
|
|
495
|
+
expect(result[0].customSelector).toBe(".button");
|
|
496
|
+
expect(result[0].delay).toBe(1e3);
|
|
497
|
+
});
|
|
498
|
+
test("should handle triggers with non-array actions", () => {
|
|
499
|
+
const triggers = [
|
|
500
|
+
{
|
|
501
|
+
id: "trigger-1",
|
|
502
|
+
actions: "not-an-array",
|
|
503
|
+
conditions: []
|
|
504
|
+
}
|
|
505
|
+
];
|
|
506
|
+
const result = duplicateTriggers(triggers);
|
|
507
|
+
expect(result[0].actions).toBe("not-an-array");
|
|
508
|
+
});
|
|
509
|
+
test("should handle triggers with non-array conditions", () => {
|
|
510
|
+
const triggers = [
|
|
511
|
+
{
|
|
512
|
+
id: "trigger-1",
|
|
513
|
+
actions: [],
|
|
514
|
+
conditions: "not-an-array"
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
const result = duplicateTriggers(triggers);
|
|
518
|
+
expect(result[0].conditions).toBe("not-an-array");
|
|
519
|
+
});
|
|
456
520
|
});
|
|
457
521
|
describe("duplicateTarget", () => {
|
|
458
522
|
test("should return undefined for undefined target", () => {
|
|
@@ -485,6 +549,42 @@ describe("duplicateTarget", () => {
|
|
|
485
549
|
const result = duplicateTarget(target);
|
|
486
550
|
expect(result).toEqual(target);
|
|
487
551
|
});
|
|
552
|
+
test("should handle target with empty actions array", () => {
|
|
553
|
+
const target = {
|
|
554
|
+
selector: ".test",
|
|
555
|
+
actions: []
|
|
556
|
+
};
|
|
557
|
+
const result = duplicateTarget(target);
|
|
558
|
+
expect(result == null ? void 0 : result.actions).toEqual([]);
|
|
559
|
+
});
|
|
560
|
+
test("should handle target with multiple actions", () => {
|
|
561
|
+
var _a, _b;
|
|
562
|
+
const target = {
|
|
563
|
+
selector: ".test",
|
|
564
|
+
actions: [
|
|
565
|
+
{ id: "action-1", type: "test1", operators: "and", data: {} },
|
|
566
|
+
{ id: "action-2", type: "test2", operators: "or", data: {} }
|
|
567
|
+
]
|
|
568
|
+
};
|
|
569
|
+
const result = duplicateTarget(target);
|
|
570
|
+
expect(result == null ? void 0 : result.actions).toHaveLength(2);
|
|
571
|
+
expect((_a = result == null ? void 0 : result.actions) == null ? void 0 : _a[0].id).toBe("regenerated-action-1");
|
|
572
|
+
expect((_b = result == null ? void 0 : result.actions) == null ? void 0 : _b[1].id).toBe("regenerated-action-2");
|
|
573
|
+
});
|
|
574
|
+
test("should preserve other target properties", () => {
|
|
575
|
+
var _a;
|
|
576
|
+
const target = {
|
|
577
|
+
selectors: [".test-selector"],
|
|
578
|
+
customPlacement: "bottom",
|
|
579
|
+
offset: { x: 10, y: 20 },
|
|
580
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
581
|
+
};
|
|
582
|
+
const result = duplicateTarget(target);
|
|
583
|
+
expect(result == null ? void 0 : result.selectors).toEqual([".test-selector"]);
|
|
584
|
+
expect(result == null ? void 0 : result.customPlacement).toBe("bottom");
|
|
585
|
+
expect(result == null ? void 0 : result.offset).toEqual({ x: 10, y: 20 });
|
|
586
|
+
expect((_a = result == null ? void 0 : result.actions) == null ? void 0 : _a[0].id).toBe("regenerated-action-1");
|
|
587
|
+
});
|
|
488
588
|
});
|
|
489
589
|
describe("duplicateChecklistData", () => {
|
|
490
590
|
test("should return data as-is for null", () => {
|
|
@@ -561,6 +661,247 @@ describe("duplicateChecklistData", () => {
|
|
|
561
661
|
const result = duplicateChecklistData(data);
|
|
562
662
|
expect(result.items[0].onlyShowTaskConditions[0].id).toBe("regenerated-condition-1");
|
|
563
663
|
});
|
|
664
|
+
test("should process content field with question elements", () => {
|
|
665
|
+
var _a;
|
|
666
|
+
const questionElement = {
|
|
667
|
+
type: ContentEditorElementType.NPS,
|
|
668
|
+
data: { name: "NPS Question", cvid: "old-cvid" }
|
|
669
|
+
};
|
|
670
|
+
const data = {
|
|
671
|
+
content: [
|
|
672
|
+
{
|
|
673
|
+
type: "root",
|
|
674
|
+
children: [
|
|
675
|
+
{
|
|
676
|
+
type: "column",
|
|
677
|
+
children: [
|
|
678
|
+
{
|
|
679
|
+
type: "element",
|
|
680
|
+
element: questionElement
|
|
681
|
+
}
|
|
682
|
+
]
|
|
683
|
+
}
|
|
684
|
+
]
|
|
685
|
+
}
|
|
686
|
+
],
|
|
687
|
+
items: [
|
|
688
|
+
{
|
|
689
|
+
id: "item-1",
|
|
690
|
+
clickedActions: [],
|
|
691
|
+
completeConditions: [],
|
|
692
|
+
onlyShowTaskConditions: []
|
|
693
|
+
}
|
|
694
|
+
]
|
|
695
|
+
};
|
|
696
|
+
const result = duplicateChecklistData(data);
|
|
697
|
+
const processedElement = (_a = result.content) == null ? void 0 : _a[0].children[0].children[0].element;
|
|
698
|
+
expect(processedElement.data.cvid).toBe("mock-cuid");
|
|
699
|
+
});
|
|
700
|
+
test("should handle multiple items", () => {
|
|
701
|
+
const data = {
|
|
702
|
+
items: [
|
|
703
|
+
{
|
|
704
|
+
id: "item-1",
|
|
705
|
+
title: "Task 1",
|
|
706
|
+
clickedActions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
|
|
707
|
+
completeConditions: [],
|
|
708
|
+
onlyShowTaskConditions: []
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
id: "item-2",
|
|
712
|
+
title: "Task 2",
|
|
713
|
+
clickedActions: [],
|
|
714
|
+
completeConditions: [{ id: "condition-2", type: "test", operators: "and", data: {} }],
|
|
715
|
+
onlyShowTaskConditions: []
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
};
|
|
719
|
+
const result = duplicateChecklistData(data);
|
|
720
|
+
expect(result.items).toHaveLength(2);
|
|
721
|
+
expect(result.items[0].id).toBe("mock-uuid");
|
|
722
|
+
expect(result.items[1].id).toBe("mock-uuid");
|
|
723
|
+
expect(result.items[0].clickedActions[0].id).toBe("regenerated-action-1");
|
|
724
|
+
expect(result.items[1].completeConditions[0].id).toBe("regenerated-condition-2");
|
|
725
|
+
});
|
|
726
|
+
test("should handle items without conditions arrays", () => {
|
|
727
|
+
const data = {
|
|
728
|
+
items: [
|
|
729
|
+
{
|
|
730
|
+
id: "item-1",
|
|
731
|
+
title: "Task 1"
|
|
732
|
+
}
|
|
733
|
+
]
|
|
734
|
+
};
|
|
735
|
+
const result = duplicateChecklistData(data);
|
|
736
|
+
expect(result.items[0].id).toBe("mock-uuid");
|
|
737
|
+
expect(result.items[0].clickedActions).toBeUndefined();
|
|
738
|
+
expect(result.items[0].completeConditions).toBeUndefined();
|
|
739
|
+
expect(result.items[0].onlyShowTaskConditions).toBeUndefined();
|
|
740
|
+
});
|
|
741
|
+
test("should preserve other item properties", () => {
|
|
742
|
+
const data = {
|
|
743
|
+
items: [
|
|
744
|
+
{
|
|
745
|
+
id: "item-1",
|
|
746
|
+
name: "Task 1",
|
|
747
|
+
description: "A task description",
|
|
748
|
+
isCompleted: false,
|
|
749
|
+
clickedActions: [],
|
|
750
|
+
completeConditions: [],
|
|
751
|
+
onlyShowTaskConditions: []
|
|
752
|
+
}
|
|
753
|
+
]
|
|
754
|
+
};
|
|
755
|
+
const result = duplicateChecklistData(data);
|
|
756
|
+
expect(result.items[0].name).toBe("Task 1");
|
|
757
|
+
expect(result.items[0].description).toBe("A task description");
|
|
758
|
+
expect(result.items[0].isCompleted).toBe(false);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
describe("duplicateLauncherData", () => {
|
|
762
|
+
test("should return data as-is for null", () => {
|
|
763
|
+
const result = duplicateLauncherData(null);
|
|
764
|
+
expect(result).toBeNull();
|
|
765
|
+
});
|
|
766
|
+
test("should return data as-is for undefined", () => {
|
|
767
|
+
const result = duplicateLauncherData(void 0);
|
|
768
|
+
expect(result).toBeUndefined();
|
|
769
|
+
});
|
|
770
|
+
test("should return data as-is for non-object", () => {
|
|
771
|
+
const result = duplicateLauncherData("string");
|
|
772
|
+
expect(result).toBe("string");
|
|
773
|
+
});
|
|
774
|
+
test("should return data as-is for number", () => {
|
|
775
|
+
const result = duplicateLauncherData(123);
|
|
776
|
+
expect(result).toBe(123);
|
|
777
|
+
});
|
|
778
|
+
test("should regenerate behavior.actions IDs", () => {
|
|
779
|
+
var _a;
|
|
780
|
+
const data = {
|
|
781
|
+
behavior: {
|
|
782
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
const result = duplicateLauncherData(data);
|
|
786
|
+
expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
|
|
787
|
+
});
|
|
788
|
+
test("should handle behavior without actions", () => {
|
|
789
|
+
var _a, _b;
|
|
790
|
+
const data = {
|
|
791
|
+
behavior: {
|
|
792
|
+
behaviorType: "click"
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const result = duplicateLauncherData(data);
|
|
796
|
+
expect((_a = result.behavior) == null ? void 0 : _a.behaviorType).toBe("click");
|
|
797
|
+
expect((_b = result.behavior) == null ? void 0 : _b.actions).toBeUndefined();
|
|
798
|
+
});
|
|
799
|
+
test("should handle behavior with non-array actions", () => {
|
|
800
|
+
var _a;
|
|
801
|
+
const data = {
|
|
802
|
+
behavior: {
|
|
803
|
+
actions: "not-an-array"
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
const result = duplicateLauncherData(data);
|
|
807
|
+
expect((_a = result.behavior) == null ? void 0 : _a.actions).toBe("not-an-array");
|
|
808
|
+
});
|
|
809
|
+
test("should process tooltip.content with question elements", () => {
|
|
810
|
+
var _a, _b;
|
|
811
|
+
const questionElement = {
|
|
812
|
+
type: ContentEditorElementType.NPS,
|
|
813
|
+
data: { name: "NPS Question", cvid: "old-cvid" }
|
|
814
|
+
};
|
|
815
|
+
const data = {
|
|
816
|
+
tooltip: {
|
|
817
|
+
content: [
|
|
818
|
+
{
|
|
819
|
+
type: "root",
|
|
820
|
+
children: [
|
|
821
|
+
{
|
|
822
|
+
type: "column",
|
|
823
|
+
children: [
|
|
824
|
+
{
|
|
825
|
+
type: "element",
|
|
826
|
+
element: questionElement
|
|
827
|
+
}
|
|
828
|
+
]
|
|
829
|
+
}
|
|
830
|
+
]
|
|
831
|
+
}
|
|
832
|
+
]
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
const result = duplicateLauncherData(data);
|
|
836
|
+
const processedElement = (_b = (_a = result.tooltip) == null ? void 0 : _a.content) == null ? void 0 : _b[0].children[0].children[0].element;
|
|
837
|
+
expect(processedElement.data.cvid).toBe("mock-cuid");
|
|
838
|
+
});
|
|
839
|
+
test("should handle data without behavior", () => {
|
|
840
|
+
var _a;
|
|
841
|
+
const data = {
|
|
842
|
+
tooltip: {
|
|
843
|
+
content: []
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
const result = duplicateLauncherData(data);
|
|
847
|
+
expect(result.behavior).toBeUndefined();
|
|
848
|
+
expect((_a = result.tooltip) == null ? void 0 : _a.content).toEqual([]);
|
|
849
|
+
});
|
|
850
|
+
test("should handle data without tooltip", () => {
|
|
851
|
+
var _a;
|
|
852
|
+
const data = {
|
|
853
|
+
behavior: {
|
|
854
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
const result = duplicateLauncherData(data);
|
|
858
|
+
expect(result.tooltip).toBeUndefined();
|
|
859
|
+
expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
|
|
860
|
+
});
|
|
861
|
+
test("should handle both behavior and tooltip", () => {
|
|
862
|
+
var _a, _b, _c;
|
|
863
|
+
const questionElement = {
|
|
864
|
+
type: ContentEditorElementType.NPS,
|
|
865
|
+
data: { name: "NPS Question", cvid: "old-cvid" }
|
|
866
|
+
};
|
|
867
|
+
const data = {
|
|
868
|
+
behavior: {
|
|
869
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
870
|
+
},
|
|
871
|
+
tooltip: {
|
|
872
|
+
content: [
|
|
873
|
+
{
|
|
874
|
+
type: "root",
|
|
875
|
+
children: [
|
|
876
|
+
{
|
|
877
|
+
type: "column",
|
|
878
|
+
children: [
|
|
879
|
+
{
|
|
880
|
+
type: "element",
|
|
881
|
+
element: questionElement
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
}
|
|
885
|
+
]
|
|
886
|
+
}
|
|
887
|
+
]
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
const result = duplicateLauncherData(data);
|
|
891
|
+
expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
|
|
892
|
+
const processedElement = (_c = (_b = result.tooltip) == null ? void 0 : _b.content) == null ? void 0 : _c[0].children[0].children[0].element;
|
|
893
|
+
expect(processedElement.data.cvid).toBe("mock-cuid");
|
|
894
|
+
});
|
|
895
|
+
test("should preserve other data properties", () => {
|
|
896
|
+
const data = {
|
|
897
|
+
customProperty: "value",
|
|
898
|
+
behavior: {
|
|
899
|
+
actions: []
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
const result = duplicateLauncherData(data);
|
|
903
|
+
expect(result.customProperty).toBe("value");
|
|
904
|
+
});
|
|
564
905
|
});
|
|
565
906
|
describe("duplicateConfig", () => {
|
|
566
907
|
test("should return config as-is for null", () => {
|
|
@@ -595,6 +936,57 @@ describe("duplicateConfig", () => {
|
|
|
595
936
|
expect(result.autoStartRules).toBeUndefined();
|
|
596
937
|
expect(result.hideRules).toBeUndefined();
|
|
597
938
|
});
|
|
939
|
+
test("should handle config with both autoStartRules and hideRules", () => {
|
|
940
|
+
var _a, _b;
|
|
941
|
+
const config = {
|
|
942
|
+
autoStartRules: [{ id: "auto-rule-1", type: "test", operators: "and", data: {} }],
|
|
943
|
+
hideRules: [{ id: "hide-rule-1", type: "test", operators: "and", data: {} }]
|
|
944
|
+
};
|
|
945
|
+
const result = duplicateConfig(config);
|
|
946
|
+
expect((_a = result.autoStartRules) == null ? void 0 : _a[0].id).toBe("regenerated-auto-rule-1");
|
|
947
|
+
expect((_b = result.hideRules) == null ? void 0 : _b[0].id).toBe("regenerated-hide-rule-1");
|
|
948
|
+
});
|
|
949
|
+
test("should handle config with empty rules arrays", () => {
|
|
950
|
+
const config = {
|
|
951
|
+
autoStartRules: [],
|
|
952
|
+
hideRules: []
|
|
953
|
+
};
|
|
954
|
+
const result = duplicateConfig(config);
|
|
955
|
+
expect(result.autoStartRules).toEqual([]);
|
|
956
|
+
expect(result.hideRules).toEqual([]);
|
|
957
|
+
});
|
|
958
|
+
test("should preserve other config properties", () => {
|
|
959
|
+
const config = {
|
|
960
|
+
autoStartRules: [{ id: "rule-1", type: "test", operators: "and", data: {} }],
|
|
961
|
+
frequency: "once",
|
|
962
|
+
dismissible: true,
|
|
963
|
+
priority: 100
|
|
964
|
+
};
|
|
965
|
+
const result = duplicateConfig(config);
|
|
966
|
+
expect(result.frequency).toBe("once");
|
|
967
|
+
expect(result.dismissible).toBe(true);
|
|
968
|
+
expect(result.priority).toBe(100);
|
|
969
|
+
});
|
|
970
|
+
test("should handle config with multiple rules in arrays", () => {
|
|
971
|
+
var _a, _b, _c, _d;
|
|
972
|
+
const config = {
|
|
973
|
+
autoStartRules: [
|
|
974
|
+
{ id: "rule-1", type: "test1", operators: "and", data: {} },
|
|
975
|
+
{ id: "rule-2", type: "test2", operators: "or", data: {} }
|
|
976
|
+
],
|
|
977
|
+
hideRules: [
|
|
978
|
+
{ id: "rule-3", type: "test3", operators: "and", data: {} },
|
|
979
|
+
{ id: "rule-4", type: "test4", operators: "or", data: {} }
|
|
980
|
+
]
|
|
981
|
+
};
|
|
982
|
+
const result = duplicateConfig(config);
|
|
983
|
+
expect(result.autoStartRules).toHaveLength(2);
|
|
984
|
+
expect(result.hideRules).toHaveLength(2);
|
|
985
|
+
expect((_a = result.autoStartRules) == null ? void 0 : _a[0].id).toBe("regenerated-rule-1");
|
|
986
|
+
expect((_b = result.autoStartRules) == null ? void 0 : _b[1].id).toBe("regenerated-rule-2");
|
|
987
|
+
expect((_c = result.hideRules) == null ? void 0 : _c[0].id).toBe("regenerated-rule-3");
|
|
988
|
+
expect((_d = result.hideRules) == null ? void 0 : _d[1].id).toBe("regenerated-rule-4");
|
|
989
|
+
});
|
|
598
990
|
});
|
|
599
991
|
describe("duplicateData", () => {
|
|
600
992
|
test("should process checklist data for CHECKLIST content type", () => {
|
|
@@ -611,106 +1003,198 @@ describe("duplicateData", () => {
|
|
|
611
1003
|
const result = duplicateData(data, ContentDataType.CHECKLIST);
|
|
612
1004
|
expect(result.items[0].id).toBe("mock-uuid");
|
|
613
1005
|
});
|
|
614
|
-
test("should
|
|
1006
|
+
test("should process launcher data for LAUNCHER content type", () => {
|
|
1007
|
+
var _a;
|
|
1008
|
+
const data = {
|
|
1009
|
+
behavior: {
|
|
1010
|
+
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
const result = duplicateData(data, ContentDataType.LAUNCHER);
|
|
1014
|
+
expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
|
|
1015
|
+
});
|
|
1016
|
+
test("should return data as-is for FLOW content type", () => {
|
|
615
1017
|
const data = { someData: "value" };
|
|
616
1018
|
const result = duplicateData(data, "flow");
|
|
617
1019
|
expect(result).toEqual(data);
|
|
618
1020
|
});
|
|
1021
|
+
test("should return data as-is for unknown content type", () => {
|
|
1022
|
+
const data = { someData: "value" };
|
|
1023
|
+
const result = duplicateData(data, "unknown-type");
|
|
1024
|
+
expect(result).toEqual(data);
|
|
1025
|
+
});
|
|
1026
|
+
test("should return null data as-is", () => {
|
|
1027
|
+
const result = duplicateData(null, ContentDataType.CHECKLIST);
|
|
1028
|
+
expect(result).toBeNull();
|
|
1029
|
+
});
|
|
1030
|
+
test("should return undefined data as-is", () => {
|
|
1031
|
+
const result = duplicateData(void 0, ContentDataType.LAUNCHER);
|
|
1032
|
+
expect(result).toBeUndefined();
|
|
1033
|
+
});
|
|
619
1034
|
});
|
|
620
|
-
describe("
|
|
621
|
-
test("should
|
|
622
|
-
const
|
|
623
|
-
id: "step-
|
|
624
|
-
cvid: "cvid
|
|
625
|
-
name: "
|
|
1035
|
+
describe("duplicateStep", () => {
|
|
1036
|
+
test("should remove id, createdAt, updatedAt, versionId fields but preserve cvid", () => {
|
|
1037
|
+
const step = {
|
|
1038
|
+
id: "step-id",
|
|
1039
|
+
cvid: "step-cvid",
|
|
1040
|
+
name: "Test Step",
|
|
626
1041
|
sequence: 0,
|
|
627
|
-
|
|
1042
|
+
createdAt: /* @__PURE__ */ new Date("2024-01-01"),
|
|
1043
|
+
updatedAt: /* @__PURE__ */ new Date("2024-01-02"),
|
|
1044
|
+
versionId: "version-id",
|
|
628
1045
|
data: [],
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1046
|
+
trigger: [],
|
|
1047
|
+
target: void 0
|
|
632
1048
|
};
|
|
633
|
-
const result =
|
|
634
|
-
expect(result.name).toBe("Original Step (copy)");
|
|
635
|
-
expect(result.sequence).toBe(1);
|
|
1049
|
+
const result = duplicateStep(step);
|
|
636
1050
|
expect(result).not.toHaveProperty("id");
|
|
637
|
-
expect(result).
|
|
1051
|
+
expect(result).toHaveProperty("cvid");
|
|
1052
|
+
expect(result.cvid).toBe("step-cvid");
|
|
638
1053
|
expect(result).not.toHaveProperty("createdAt");
|
|
639
1054
|
expect(result).not.toHaveProperty("updatedAt");
|
|
1055
|
+
expect(result).not.toHaveProperty("versionId");
|
|
1056
|
+
});
|
|
1057
|
+
test("should preserve name and sequence", () => {
|
|
1058
|
+
const step = {
|
|
1059
|
+
id: "step-id",
|
|
1060
|
+
cvid: "step-cvid",
|
|
1061
|
+
name: "Test Step",
|
|
1062
|
+
sequence: 5,
|
|
1063
|
+
data: [],
|
|
1064
|
+
trigger: [],
|
|
1065
|
+
target: void 0
|
|
1066
|
+
};
|
|
1067
|
+
const result = duplicateStep(step);
|
|
1068
|
+
expect(result.name).toBe("Test Step");
|
|
1069
|
+
expect(result.sequence).toBe(5);
|
|
640
1070
|
});
|
|
641
|
-
test("should
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
name: "
|
|
1071
|
+
test("should process data field with question elements", () => {
|
|
1072
|
+
var _a;
|
|
1073
|
+
const questionElement = {
|
|
1074
|
+
type: ContentEditorElementType.NPS,
|
|
1075
|
+
data: { name: "NPS Question", cvid: "old-cvid" }
|
|
1076
|
+
};
|
|
1077
|
+
const step = {
|
|
1078
|
+
id: "step-id",
|
|
1079
|
+
cvid: "step-cvid",
|
|
1080
|
+
name: "Test Step",
|
|
646
1081
|
sequence: 0,
|
|
1082
|
+
data: [
|
|
1083
|
+
{
|
|
1084
|
+
type: "root",
|
|
1085
|
+
children: [
|
|
1086
|
+
{
|
|
1087
|
+
type: "column",
|
|
1088
|
+
children: [
|
|
1089
|
+
{
|
|
1090
|
+
type: "element",
|
|
1091
|
+
element: questionElement
|
|
1092
|
+
}
|
|
1093
|
+
]
|
|
1094
|
+
}
|
|
1095
|
+
]
|
|
1096
|
+
}
|
|
1097
|
+
],
|
|
647
1098
|
trigger: [],
|
|
648
|
-
data: [],
|
|
649
1099
|
target: void 0
|
|
650
1100
|
};
|
|
651
|
-
const result =
|
|
652
|
-
|
|
1101
|
+
const result = duplicateStep(step);
|
|
1102
|
+
const processedElement = (_a = result.data) == null ? void 0 : _a[0].children[0].children[0].element;
|
|
1103
|
+
expect(processedElement.data.cvid).toBe("mock-cuid");
|
|
653
1104
|
});
|
|
654
|
-
test("should process
|
|
655
|
-
var _a;
|
|
656
|
-
const
|
|
657
|
-
id: "step-
|
|
658
|
-
cvid: "cvid
|
|
659
|
-
name: "Step",
|
|
1105
|
+
test("should process trigger field", () => {
|
|
1106
|
+
var _a, _b, _c;
|
|
1107
|
+
const step = {
|
|
1108
|
+
id: "step-id",
|
|
1109
|
+
cvid: "step-cvid",
|
|
1110
|
+
name: "Test Step",
|
|
660
1111
|
sequence: 0,
|
|
1112
|
+
data: [],
|
|
661
1113
|
trigger: [
|
|
662
1114
|
{
|
|
663
1115
|
id: "trigger-1",
|
|
664
1116
|
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
|
|
665
|
-
conditions: []
|
|
1117
|
+
conditions: [{ id: "condition-1", type: "test", operators: "and", data: {} }]
|
|
666
1118
|
}
|
|
667
1119
|
],
|
|
668
|
-
data: [],
|
|
669
1120
|
target: void 0
|
|
670
1121
|
};
|
|
671
|
-
const result =
|
|
1122
|
+
const result = duplicateStep(step);
|
|
672
1123
|
expect((_a = result.trigger) == null ? void 0 : _a[0].id).toBe("mock-cuid");
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
1124
|
+
expect((_b = result.trigger) == null ? void 0 : _b[0].actions[0].id).toBe("regenerated-action-1");
|
|
1125
|
+
expect((_c = result.trigger) == null ? void 0 : _c[0].conditions[0].id).toBe("regenerated-condition-1");
|
|
1126
|
+
});
|
|
1127
|
+
test("should process target field with actions", () => {
|
|
1128
|
+
var _a, _b, _c;
|
|
1129
|
+
const step = {
|
|
1130
|
+
id: "step-id",
|
|
1131
|
+
cvid: "step-cvid",
|
|
1132
|
+
name: "Test Step",
|
|
680
1133
|
sequence: 0,
|
|
681
|
-
trigger: [],
|
|
682
1134
|
data: [],
|
|
1135
|
+
trigger: [],
|
|
683
1136
|
target: {
|
|
1137
|
+
selector: ".test",
|
|
684
1138
|
actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
|
|
685
1139
|
}
|
|
686
1140
|
};
|
|
687
|
-
const result =
|
|
1141
|
+
const result = duplicateStep(step);
|
|
688
1142
|
expect((_b = (_a = result.target) == null ? void 0 : _a.actions) == null ? void 0 : _b[0].id).toBe("regenerated-action-1");
|
|
1143
|
+
expect((_c = result.target) == null ? void 0 : _c.selector).toBe(".test");
|
|
689
1144
|
});
|
|
690
|
-
test("should
|
|
691
|
-
const
|
|
692
|
-
id: "step-
|
|
693
|
-
cvid: "cvid
|
|
694
|
-
name: "Step",
|
|
1145
|
+
test("should return empty array for undefined data", () => {
|
|
1146
|
+
const step = {
|
|
1147
|
+
id: "step-id",
|
|
1148
|
+
cvid: "step-cvid",
|
|
1149
|
+
name: "Test Step",
|
|
1150
|
+
sequence: 0,
|
|
1151
|
+
data: void 0,
|
|
1152
|
+
trigger: [],
|
|
1153
|
+
target: void 0
|
|
1154
|
+
};
|
|
1155
|
+
const result = duplicateStep(step);
|
|
1156
|
+
expect(result.data).toEqual([]);
|
|
1157
|
+
});
|
|
1158
|
+
test("should return empty array for undefined trigger", () => {
|
|
1159
|
+
const step = {
|
|
1160
|
+
id: "step-id",
|
|
1161
|
+
cvid: "step-cvid",
|
|
1162
|
+
name: "Test Step",
|
|
695
1163
|
sequence: 0,
|
|
696
|
-
trigger: void 0,
|
|
697
1164
|
data: [],
|
|
1165
|
+
trigger: void 0,
|
|
698
1166
|
target: void 0
|
|
699
1167
|
};
|
|
700
|
-
const result =
|
|
1168
|
+
const result = duplicateStep(step);
|
|
701
1169
|
expect(result.trigger).toEqual([]);
|
|
702
1170
|
});
|
|
703
|
-
test("should
|
|
704
|
-
const
|
|
705
|
-
id: "step-
|
|
706
|
-
cvid: "cvid
|
|
707
|
-
name: "Step",
|
|
1171
|
+
test("should return undefined for undefined target", () => {
|
|
1172
|
+
const step = {
|
|
1173
|
+
id: "step-id",
|
|
1174
|
+
cvid: "step-cvid",
|
|
1175
|
+
name: "Test Step",
|
|
708
1176
|
sequence: 0,
|
|
1177
|
+
data: [],
|
|
709
1178
|
trigger: [],
|
|
710
|
-
data: void 0,
|
|
711
1179
|
target: void 0
|
|
712
1180
|
};
|
|
713
|
-
const result =
|
|
714
|
-
expect(result.
|
|
1181
|
+
const result = duplicateStep(step);
|
|
1182
|
+
expect(result.target).toBeUndefined();
|
|
1183
|
+
});
|
|
1184
|
+
test("should preserve custom properties", () => {
|
|
1185
|
+
const step = {
|
|
1186
|
+
id: "step-id",
|
|
1187
|
+
cvid: "step-cvid",
|
|
1188
|
+
name: "Test Step",
|
|
1189
|
+
sequence: 0,
|
|
1190
|
+
data: [],
|
|
1191
|
+
trigger: [],
|
|
1192
|
+
target: void 0,
|
|
1193
|
+
customField: "custom-value",
|
|
1194
|
+
anotherField: 123
|
|
1195
|
+
};
|
|
1196
|
+
const result = duplicateStep(step);
|
|
1197
|
+
expect(result.customField).toBe("custom-value");
|
|
1198
|
+
expect(result.anotherField).toBe(123);
|
|
715
1199
|
});
|
|
716
1200
|
});
|