@usertour/helpers 0.0.50 → 0.0.52

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.
@@ -323,25 +323,15 @@ var duplicateData = (data, contentType) => {
323
323
  }
324
324
  return data;
325
325
  };
326
- var duplicateStep = (step, options) => {
327
- var _a;
328
- const { id, cvid, createdAt, updatedAt, versionId, trigger, target, data, ...rest } = step;
329
- const preserveUndefined = (_a = options == null ? void 0 : options.preserveUndefined) != null ? _a : false;
326
+ var duplicateStep = (step) => {
327
+ const { id, createdAt, updatedAt, versionId, trigger, target, data, ...rest } = step;
330
328
  return {
331
329
  ...rest,
332
- data: data ? processQuestionElements(data) : preserveUndefined ? data : [],
333
- trigger: trigger ? duplicateTriggers(trigger) : preserveUndefined ? trigger : [],
330
+ data: data ? processQuestionElements(data) : [],
331
+ trigger: trigger ? duplicateTriggers(trigger) : [],
334
332
  target: duplicateTarget(target)
335
333
  };
336
334
  };
337
- var duplicateStepWithRename = (originalStep, sequence, existingStepNames) => {
338
- const duplicated = duplicateStep(originalStep);
339
- return {
340
- ...duplicated,
341
- name: generateUniqueCopyName(originalStep.name, existingStepNames),
342
- sequence
343
- };
344
- };
345
335
 
346
336
  // src/__tests__/content-helper.test.ts
347
337
  jest.mock("../helper", () => ({
@@ -771,6 +761,69 @@ describe("duplicateTriggers", () => {
771
761
  expect(result[0].actions).toBeUndefined();
772
762
  expect(result[0].conditions).toBeUndefined();
773
763
  });
764
+ test("should handle empty array", () => {
765
+ const triggers = [];
766
+ const result = duplicateTriggers(triggers);
767
+ expect(result).toEqual([]);
768
+ });
769
+ test("should handle multiple triggers", () => {
770
+ const triggers = [
771
+ {
772
+ id: "trigger-1",
773
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
774
+ conditions: []
775
+ },
776
+ {
777
+ id: "trigger-2",
778
+ actions: [],
779
+ conditions: [{ id: "condition-1", type: "test", operators: "and", data: {} }]
780
+ }
781
+ ];
782
+ const result = duplicateTriggers(triggers);
783
+ expect(result).toHaveLength(2);
784
+ expect(result[0].id).toBe("mock-cuid");
785
+ expect(result[1].id).toBe("mock-cuid");
786
+ expect(result[0].actions[0].id).toBe("regenerated-action-1");
787
+ expect(result[1].conditions[0].id).toBe("regenerated-condition-1");
788
+ });
789
+ test("should preserve other trigger properties", () => {
790
+ const triggers = [
791
+ {
792
+ id: "trigger-1",
793
+ customType: "click",
794
+ customSelector: ".button",
795
+ delay: 1e3,
796
+ actions: [],
797
+ conditions: []
798
+ }
799
+ ];
800
+ const result = duplicateTriggers(triggers);
801
+ expect(result[0].customType).toBe("click");
802
+ expect(result[0].customSelector).toBe(".button");
803
+ expect(result[0].delay).toBe(1e3);
804
+ });
805
+ test("should handle triggers with non-array actions", () => {
806
+ const triggers = [
807
+ {
808
+ id: "trigger-1",
809
+ actions: "not-an-array",
810
+ conditions: []
811
+ }
812
+ ];
813
+ const result = duplicateTriggers(triggers);
814
+ expect(result[0].actions).toBe("not-an-array");
815
+ });
816
+ test("should handle triggers with non-array conditions", () => {
817
+ const triggers = [
818
+ {
819
+ id: "trigger-1",
820
+ actions: [],
821
+ conditions: "not-an-array"
822
+ }
823
+ ];
824
+ const result = duplicateTriggers(triggers);
825
+ expect(result[0].conditions).toBe("not-an-array");
826
+ });
774
827
  });
775
828
  describe("duplicateTarget", () => {
776
829
  test("should return undefined for undefined target", () => {
@@ -803,6 +856,42 @@ describe("duplicateTarget", () => {
803
856
  const result = duplicateTarget(target);
804
857
  expect(result).toEqual(target);
805
858
  });
859
+ test("should handle target with empty actions array", () => {
860
+ const target = {
861
+ selector: ".test",
862
+ actions: []
863
+ };
864
+ const result = duplicateTarget(target);
865
+ expect(result == null ? void 0 : result.actions).toEqual([]);
866
+ });
867
+ test("should handle target with multiple actions", () => {
868
+ var _a, _b;
869
+ const target = {
870
+ selector: ".test",
871
+ actions: [
872
+ { id: "action-1", type: "test1", operators: "and", data: {} },
873
+ { id: "action-2", type: "test2", operators: "or", data: {} }
874
+ ]
875
+ };
876
+ const result = duplicateTarget(target);
877
+ expect(result == null ? void 0 : result.actions).toHaveLength(2);
878
+ expect((_a = result == null ? void 0 : result.actions) == null ? void 0 : _a[0].id).toBe("regenerated-action-1");
879
+ expect((_b = result == null ? void 0 : result.actions) == null ? void 0 : _b[1].id).toBe("regenerated-action-2");
880
+ });
881
+ test("should preserve other target properties", () => {
882
+ var _a;
883
+ const target = {
884
+ selectors: [".test-selector"],
885
+ customPlacement: "bottom",
886
+ offset: { x: 10, y: 20 },
887
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
888
+ };
889
+ const result = duplicateTarget(target);
890
+ expect(result == null ? void 0 : result.selectors).toEqual([".test-selector"]);
891
+ expect(result == null ? void 0 : result.customPlacement).toBe("bottom");
892
+ expect(result == null ? void 0 : result.offset).toEqual({ x: 10, y: 20 });
893
+ expect((_a = result == null ? void 0 : result.actions) == null ? void 0 : _a[0].id).toBe("regenerated-action-1");
894
+ });
806
895
  });
807
896
  describe("duplicateChecklistData", () => {
808
897
  test("should return data as-is for null", () => {
@@ -879,6 +968,247 @@ describe("duplicateChecklistData", () => {
879
968
  const result = duplicateChecklistData(data);
880
969
  expect(result.items[0].onlyShowTaskConditions[0].id).toBe("regenerated-condition-1");
881
970
  });
971
+ test("should process content field with question elements", () => {
972
+ var _a;
973
+ const questionElement = {
974
+ type: import_types4.ContentEditorElementType.NPS,
975
+ data: { name: "NPS Question", cvid: "old-cvid" }
976
+ };
977
+ const data = {
978
+ content: [
979
+ {
980
+ type: "root",
981
+ children: [
982
+ {
983
+ type: "column",
984
+ children: [
985
+ {
986
+ type: "element",
987
+ element: questionElement
988
+ }
989
+ ]
990
+ }
991
+ ]
992
+ }
993
+ ],
994
+ items: [
995
+ {
996
+ id: "item-1",
997
+ clickedActions: [],
998
+ completeConditions: [],
999
+ onlyShowTaskConditions: []
1000
+ }
1001
+ ]
1002
+ };
1003
+ const result = duplicateChecklistData(data);
1004
+ const processedElement = (_a = result.content) == null ? void 0 : _a[0].children[0].children[0].element;
1005
+ expect(processedElement.data.cvid).toBe("mock-cuid");
1006
+ });
1007
+ test("should handle multiple items", () => {
1008
+ const data = {
1009
+ items: [
1010
+ {
1011
+ id: "item-1",
1012
+ title: "Task 1",
1013
+ clickedActions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
1014
+ completeConditions: [],
1015
+ onlyShowTaskConditions: []
1016
+ },
1017
+ {
1018
+ id: "item-2",
1019
+ title: "Task 2",
1020
+ clickedActions: [],
1021
+ completeConditions: [{ id: "condition-2", type: "test", operators: "and", data: {} }],
1022
+ onlyShowTaskConditions: []
1023
+ }
1024
+ ]
1025
+ };
1026
+ const result = duplicateChecklistData(data);
1027
+ expect(result.items).toHaveLength(2);
1028
+ expect(result.items[0].id).toBe("mock-uuid");
1029
+ expect(result.items[1].id).toBe("mock-uuid");
1030
+ expect(result.items[0].clickedActions[0].id).toBe("regenerated-action-1");
1031
+ expect(result.items[1].completeConditions[0].id).toBe("regenerated-condition-2");
1032
+ });
1033
+ test("should handle items without conditions arrays", () => {
1034
+ const data = {
1035
+ items: [
1036
+ {
1037
+ id: "item-1",
1038
+ title: "Task 1"
1039
+ }
1040
+ ]
1041
+ };
1042
+ const result = duplicateChecklistData(data);
1043
+ expect(result.items[0].id).toBe("mock-uuid");
1044
+ expect(result.items[0].clickedActions).toBeUndefined();
1045
+ expect(result.items[0].completeConditions).toBeUndefined();
1046
+ expect(result.items[0].onlyShowTaskConditions).toBeUndefined();
1047
+ });
1048
+ test("should preserve other item properties", () => {
1049
+ const data = {
1050
+ items: [
1051
+ {
1052
+ id: "item-1",
1053
+ name: "Task 1",
1054
+ description: "A task description",
1055
+ isCompleted: false,
1056
+ clickedActions: [],
1057
+ completeConditions: [],
1058
+ onlyShowTaskConditions: []
1059
+ }
1060
+ ]
1061
+ };
1062
+ const result = duplicateChecklistData(data);
1063
+ expect(result.items[0].name).toBe("Task 1");
1064
+ expect(result.items[0].description).toBe("A task description");
1065
+ expect(result.items[0].isCompleted).toBe(false);
1066
+ });
1067
+ });
1068
+ describe("duplicateLauncherData", () => {
1069
+ test("should return data as-is for null", () => {
1070
+ const result = duplicateLauncherData(null);
1071
+ expect(result).toBeNull();
1072
+ });
1073
+ test("should return data as-is for undefined", () => {
1074
+ const result = duplicateLauncherData(void 0);
1075
+ expect(result).toBeUndefined();
1076
+ });
1077
+ test("should return data as-is for non-object", () => {
1078
+ const result = duplicateLauncherData("string");
1079
+ expect(result).toBe("string");
1080
+ });
1081
+ test("should return data as-is for number", () => {
1082
+ const result = duplicateLauncherData(123);
1083
+ expect(result).toBe(123);
1084
+ });
1085
+ test("should regenerate behavior.actions IDs", () => {
1086
+ var _a;
1087
+ const data = {
1088
+ behavior: {
1089
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
1090
+ }
1091
+ };
1092
+ const result = duplicateLauncherData(data);
1093
+ expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
1094
+ });
1095
+ test("should handle behavior without actions", () => {
1096
+ var _a, _b;
1097
+ const data = {
1098
+ behavior: {
1099
+ behaviorType: "click"
1100
+ }
1101
+ };
1102
+ const result = duplicateLauncherData(data);
1103
+ expect((_a = result.behavior) == null ? void 0 : _a.behaviorType).toBe("click");
1104
+ expect((_b = result.behavior) == null ? void 0 : _b.actions).toBeUndefined();
1105
+ });
1106
+ test("should handle behavior with non-array actions", () => {
1107
+ var _a;
1108
+ const data = {
1109
+ behavior: {
1110
+ actions: "not-an-array"
1111
+ }
1112
+ };
1113
+ const result = duplicateLauncherData(data);
1114
+ expect((_a = result.behavior) == null ? void 0 : _a.actions).toBe("not-an-array");
1115
+ });
1116
+ test("should process tooltip.content with question elements", () => {
1117
+ var _a, _b;
1118
+ const questionElement = {
1119
+ type: import_types4.ContentEditorElementType.NPS,
1120
+ data: { name: "NPS Question", cvid: "old-cvid" }
1121
+ };
1122
+ const data = {
1123
+ tooltip: {
1124
+ content: [
1125
+ {
1126
+ type: "root",
1127
+ children: [
1128
+ {
1129
+ type: "column",
1130
+ children: [
1131
+ {
1132
+ type: "element",
1133
+ element: questionElement
1134
+ }
1135
+ ]
1136
+ }
1137
+ ]
1138
+ }
1139
+ ]
1140
+ }
1141
+ };
1142
+ const result = duplicateLauncherData(data);
1143
+ const processedElement = (_b = (_a = result.tooltip) == null ? void 0 : _a.content) == null ? void 0 : _b[0].children[0].children[0].element;
1144
+ expect(processedElement.data.cvid).toBe("mock-cuid");
1145
+ });
1146
+ test("should handle data without behavior", () => {
1147
+ var _a;
1148
+ const data = {
1149
+ tooltip: {
1150
+ content: []
1151
+ }
1152
+ };
1153
+ const result = duplicateLauncherData(data);
1154
+ expect(result.behavior).toBeUndefined();
1155
+ expect((_a = result.tooltip) == null ? void 0 : _a.content).toEqual([]);
1156
+ });
1157
+ test("should handle data without tooltip", () => {
1158
+ var _a;
1159
+ const data = {
1160
+ behavior: {
1161
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
1162
+ }
1163
+ };
1164
+ const result = duplicateLauncherData(data);
1165
+ expect(result.tooltip).toBeUndefined();
1166
+ expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
1167
+ });
1168
+ test("should handle both behavior and tooltip", () => {
1169
+ var _a, _b, _c;
1170
+ const questionElement = {
1171
+ type: import_types4.ContentEditorElementType.NPS,
1172
+ data: { name: "NPS Question", cvid: "old-cvid" }
1173
+ };
1174
+ const data = {
1175
+ behavior: {
1176
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
1177
+ },
1178
+ tooltip: {
1179
+ content: [
1180
+ {
1181
+ type: "root",
1182
+ children: [
1183
+ {
1184
+ type: "column",
1185
+ children: [
1186
+ {
1187
+ type: "element",
1188
+ element: questionElement
1189
+ }
1190
+ ]
1191
+ }
1192
+ ]
1193
+ }
1194
+ ]
1195
+ }
1196
+ };
1197
+ const result = duplicateLauncherData(data);
1198
+ expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
1199
+ const processedElement = (_c = (_b = result.tooltip) == null ? void 0 : _b.content) == null ? void 0 : _c[0].children[0].children[0].element;
1200
+ expect(processedElement.data.cvid).toBe("mock-cuid");
1201
+ });
1202
+ test("should preserve other data properties", () => {
1203
+ const data = {
1204
+ customProperty: "value",
1205
+ behavior: {
1206
+ actions: []
1207
+ }
1208
+ };
1209
+ const result = duplicateLauncherData(data);
1210
+ expect(result.customProperty).toBe("value");
1211
+ });
882
1212
  });
883
1213
  describe("duplicateConfig", () => {
884
1214
  test("should return config as-is for null", () => {
@@ -913,6 +1243,57 @@ describe("duplicateConfig", () => {
913
1243
  expect(result.autoStartRules).toBeUndefined();
914
1244
  expect(result.hideRules).toBeUndefined();
915
1245
  });
1246
+ test("should handle config with both autoStartRules and hideRules", () => {
1247
+ var _a, _b;
1248
+ const config = {
1249
+ autoStartRules: [{ id: "auto-rule-1", type: "test", operators: "and", data: {} }],
1250
+ hideRules: [{ id: "hide-rule-1", type: "test", operators: "and", data: {} }]
1251
+ };
1252
+ const result = duplicateConfig(config);
1253
+ expect((_a = result.autoStartRules) == null ? void 0 : _a[0].id).toBe("regenerated-auto-rule-1");
1254
+ expect((_b = result.hideRules) == null ? void 0 : _b[0].id).toBe("regenerated-hide-rule-1");
1255
+ });
1256
+ test("should handle config with empty rules arrays", () => {
1257
+ const config = {
1258
+ autoStartRules: [],
1259
+ hideRules: []
1260
+ };
1261
+ const result = duplicateConfig(config);
1262
+ expect(result.autoStartRules).toEqual([]);
1263
+ expect(result.hideRules).toEqual([]);
1264
+ });
1265
+ test("should preserve other config properties", () => {
1266
+ const config = {
1267
+ autoStartRules: [{ id: "rule-1", type: "test", operators: "and", data: {} }],
1268
+ frequency: "once",
1269
+ dismissible: true,
1270
+ priority: 100
1271
+ };
1272
+ const result = duplicateConfig(config);
1273
+ expect(result.frequency).toBe("once");
1274
+ expect(result.dismissible).toBe(true);
1275
+ expect(result.priority).toBe(100);
1276
+ });
1277
+ test("should handle config with multiple rules in arrays", () => {
1278
+ var _a, _b, _c, _d;
1279
+ const config = {
1280
+ autoStartRules: [
1281
+ { id: "rule-1", type: "test1", operators: "and", data: {} },
1282
+ { id: "rule-2", type: "test2", operators: "or", data: {} }
1283
+ ],
1284
+ hideRules: [
1285
+ { id: "rule-3", type: "test3", operators: "and", data: {} },
1286
+ { id: "rule-4", type: "test4", operators: "or", data: {} }
1287
+ ]
1288
+ };
1289
+ const result = duplicateConfig(config);
1290
+ expect(result.autoStartRules).toHaveLength(2);
1291
+ expect(result.hideRules).toHaveLength(2);
1292
+ expect((_a = result.autoStartRules) == null ? void 0 : _a[0].id).toBe("regenerated-rule-1");
1293
+ expect((_b = result.autoStartRules) == null ? void 0 : _b[1].id).toBe("regenerated-rule-2");
1294
+ expect((_c = result.hideRules) == null ? void 0 : _c[0].id).toBe("regenerated-rule-3");
1295
+ expect((_d = result.hideRules) == null ? void 0 : _d[1].id).toBe("regenerated-rule-4");
1296
+ });
916
1297
  });
917
1298
  describe("duplicateData", () => {
918
1299
  test("should process checklist data for CHECKLIST content type", () => {
@@ -929,106 +1310,198 @@ describe("duplicateData", () => {
929
1310
  const result = duplicateData(data, import_types4.ContentDataType.CHECKLIST);
930
1311
  expect(result.items[0].id).toBe("mock-uuid");
931
1312
  });
932
- test("should return data as-is for non-CHECKLIST content type", () => {
1313
+ test("should process launcher data for LAUNCHER content type", () => {
1314
+ var _a;
1315
+ const data = {
1316
+ behavior: {
1317
+ actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
1318
+ }
1319
+ };
1320
+ const result = duplicateData(data, import_types4.ContentDataType.LAUNCHER);
1321
+ expect((_a = result.behavior) == null ? void 0 : _a.actions[0].id).toBe("regenerated-action-1");
1322
+ });
1323
+ test("should return data as-is for FLOW content type", () => {
933
1324
  const data = { someData: "value" };
934
1325
  const result = duplicateData(data, "flow");
935
1326
  expect(result).toEqual(data);
936
1327
  });
1328
+ test("should return data as-is for unknown content type", () => {
1329
+ const data = { someData: "value" };
1330
+ const result = duplicateData(data, "unknown-type");
1331
+ expect(result).toEqual(data);
1332
+ });
1333
+ test("should return null data as-is", () => {
1334
+ const result = duplicateData(null, import_types4.ContentDataType.CHECKLIST);
1335
+ expect(result).toBeNull();
1336
+ });
1337
+ test("should return undefined data as-is", () => {
1338
+ const result = duplicateData(void 0, import_types4.ContentDataType.LAUNCHER);
1339
+ expect(result).toBeUndefined();
1340
+ });
937
1341
  });
938
- describe("duplicateStepWithRename", () => {
939
- test("should duplicate the step with new name", () => {
940
- const originalStep = {
941
- id: "step-1",
942
- cvid: "cvid-1",
943
- name: "Original Step",
1342
+ describe("duplicateStep", () => {
1343
+ test("should remove id, createdAt, updatedAt, versionId fields but preserve cvid", () => {
1344
+ const step = {
1345
+ id: "step-id",
1346
+ cvid: "step-cvid",
1347
+ name: "Test Step",
944
1348
  sequence: 0,
945
- trigger: [],
1349
+ createdAt: /* @__PURE__ */ new Date("2024-01-01"),
1350
+ updatedAt: /* @__PURE__ */ new Date("2024-01-02"),
1351
+ versionId: "version-id",
946
1352
  data: [],
947
- target: void 0,
948
- createdAt: /* @__PURE__ */ new Date(),
949
- updatedAt: /* @__PURE__ */ new Date()
1353
+ trigger: [],
1354
+ target: void 0
950
1355
  };
951
- const result = duplicateStepWithRename(originalStep, 1);
952
- expect(result.name).toBe("Original Step (copy)");
953
- expect(result.sequence).toBe(1);
1356
+ const result = duplicateStep(step);
954
1357
  expect(result).not.toHaveProperty("id");
955
- expect(result).not.toHaveProperty("cvid");
1358
+ expect(result).toHaveProperty("cvid");
1359
+ expect(result.cvid).toBe("step-cvid");
956
1360
  expect(result).not.toHaveProperty("createdAt");
957
1361
  expect(result).not.toHaveProperty("updatedAt");
1362
+ expect(result).not.toHaveProperty("versionId");
1363
+ });
1364
+ test("should preserve name and sequence", () => {
1365
+ const step = {
1366
+ id: "step-id",
1367
+ cvid: "step-cvid",
1368
+ name: "Test Step",
1369
+ sequence: 5,
1370
+ data: [],
1371
+ trigger: [],
1372
+ target: void 0
1373
+ };
1374
+ const result = duplicateStep(step);
1375
+ expect(result.name).toBe("Test Step");
1376
+ expect(result.sequence).toBe(5);
958
1377
  });
959
- test("should generate unique name when existing names provided", () => {
960
- const originalStep = {
961
- id: "step-1",
962
- cvid: "cvid-1",
963
- name: "Step",
1378
+ test("should process data field with question elements", () => {
1379
+ var _a;
1380
+ const questionElement = {
1381
+ type: import_types4.ContentEditorElementType.NPS,
1382
+ data: { name: "NPS Question", cvid: "old-cvid" }
1383
+ };
1384
+ const step = {
1385
+ id: "step-id",
1386
+ cvid: "step-cvid",
1387
+ name: "Test Step",
964
1388
  sequence: 0,
1389
+ data: [
1390
+ {
1391
+ type: "root",
1392
+ children: [
1393
+ {
1394
+ type: "column",
1395
+ children: [
1396
+ {
1397
+ type: "element",
1398
+ element: questionElement
1399
+ }
1400
+ ]
1401
+ }
1402
+ ]
1403
+ }
1404
+ ],
965
1405
  trigger: [],
966
- data: [],
967
1406
  target: void 0
968
1407
  };
969
- const result = duplicateStepWithRename(originalStep, 1, ["Step (copy)"]);
970
- expect(result.name).toBe("Step (copy 2)");
1408
+ const result = duplicateStep(step);
1409
+ const processedElement = (_a = result.data) == null ? void 0 : _a[0].children[0].children[0].element;
1410
+ expect(processedElement.data.cvid).toBe("mock-cuid");
971
1411
  });
972
- test("should process triggers in step duplicate", () => {
973
- var _a;
974
- const originalStep = {
975
- id: "step-1",
976
- cvid: "cvid-1",
977
- name: "Step",
1412
+ test("should process trigger field", () => {
1413
+ var _a, _b, _c;
1414
+ const step = {
1415
+ id: "step-id",
1416
+ cvid: "step-cvid",
1417
+ name: "Test Step",
978
1418
  sequence: 0,
1419
+ data: [],
979
1420
  trigger: [
980
1421
  {
981
1422
  id: "trigger-1",
982
1423
  actions: [{ id: "action-1", type: "test", operators: "and", data: {} }],
983
- conditions: []
1424
+ conditions: [{ id: "condition-1", type: "test", operators: "and", data: {} }]
984
1425
  }
985
1426
  ],
986
- data: [],
987
1427
  target: void 0
988
1428
  };
989
- const result = duplicateStepWithRename(originalStep, 1);
1429
+ const result = duplicateStep(step);
990
1430
  expect((_a = result.trigger) == null ? void 0 : _a[0].id).toBe("mock-cuid");
991
- });
992
- test("should process target in step duplicate", () => {
993
- var _a, _b;
994
- const originalStep = {
995
- id: "step-1",
996
- cvid: "cvid-1",
997
- name: "Step",
1431
+ expect((_b = result.trigger) == null ? void 0 : _b[0].actions[0].id).toBe("regenerated-action-1");
1432
+ expect((_c = result.trigger) == null ? void 0 : _c[0].conditions[0].id).toBe("regenerated-condition-1");
1433
+ });
1434
+ test("should process target field with actions", () => {
1435
+ var _a, _b, _c;
1436
+ const step = {
1437
+ id: "step-id",
1438
+ cvid: "step-cvid",
1439
+ name: "Test Step",
998
1440
  sequence: 0,
999
- trigger: [],
1000
1441
  data: [],
1442
+ trigger: [],
1001
1443
  target: {
1444
+ selector: ".test",
1002
1445
  actions: [{ id: "action-1", type: "test", operators: "and", data: {} }]
1003
1446
  }
1004
1447
  };
1005
- const result = duplicateStepWithRename(originalStep, 1);
1448
+ const result = duplicateStep(step);
1006
1449
  expect((_b = (_a = result.target) == null ? void 0 : _a.actions) == null ? void 0 : _b[0].id).toBe("regenerated-action-1");
1450
+ expect((_c = result.target) == null ? void 0 : _c.selector).toBe(".test");
1007
1451
  });
1008
- test("should handle step without trigger", () => {
1009
- const originalStep = {
1010
- id: "step-1",
1011
- cvid: "cvid-1",
1012
- name: "Step",
1452
+ test("should return empty array for undefined data", () => {
1453
+ const step = {
1454
+ id: "step-id",
1455
+ cvid: "step-cvid",
1456
+ name: "Test Step",
1457
+ sequence: 0,
1458
+ data: void 0,
1459
+ trigger: [],
1460
+ target: void 0
1461
+ };
1462
+ const result = duplicateStep(step);
1463
+ expect(result.data).toEqual([]);
1464
+ });
1465
+ test("should return empty array for undefined trigger", () => {
1466
+ const step = {
1467
+ id: "step-id",
1468
+ cvid: "step-cvid",
1469
+ name: "Test Step",
1013
1470
  sequence: 0,
1014
- trigger: void 0,
1015
1471
  data: [],
1472
+ trigger: void 0,
1016
1473
  target: void 0
1017
1474
  };
1018
- const result = duplicateStepWithRename(originalStep, 1);
1475
+ const result = duplicateStep(step);
1019
1476
  expect(result.trigger).toEqual([]);
1020
1477
  });
1021
- test("should handle step without data", () => {
1022
- const originalStep = {
1023
- id: "step-1",
1024
- cvid: "cvid-1",
1025
- name: "Step",
1478
+ test("should return undefined for undefined target", () => {
1479
+ const step = {
1480
+ id: "step-id",
1481
+ cvid: "step-cvid",
1482
+ name: "Test Step",
1026
1483
  sequence: 0,
1484
+ data: [],
1027
1485
  trigger: [],
1028
- data: void 0,
1029
1486
  target: void 0
1030
1487
  };
1031
- const result = duplicateStepWithRename(originalStep, 1);
1032
- expect(result.data).toEqual([]);
1488
+ const result = duplicateStep(step);
1489
+ expect(result.target).toBeUndefined();
1490
+ });
1491
+ test("should preserve custom properties", () => {
1492
+ const step = {
1493
+ id: "step-id",
1494
+ cvid: "step-cvid",
1495
+ name: "Test Step",
1496
+ sequence: 0,
1497
+ data: [],
1498
+ trigger: [],
1499
+ target: void 0,
1500
+ customField: "custom-value",
1501
+ anotherField: 123
1502
+ };
1503
+ const result = duplicateStep(step);
1504
+ expect(result.customField).toBe("custom-value");
1505
+ expect(result.anotherField).toBe(123);
1033
1506
  });
1034
1507
  });