slice-machine-ui 1.22.2 → 1.22.3-alpha.chore-introduce-css-modules.1

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.
Files changed (168) hide show
  1. package/.depcheckrc +4 -1
  2. package/.eslintignore +1 -0
  3. package/components/DeleteVariationModal/index.tsx +12 -11
  4. package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
  5. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
  6. package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
  7. package/components/ItemHeader/index.tsx +1 -0
  8. package/components/ListItem/index.tsx +5 -2
  9. package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
  10. package/components/ScreenshotChangesModal/index.tsx +3 -0
  11. package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
  12. package/components/Simulator/index.tsx +9 -3
  13. package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
  14. package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
  15. package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
  16. package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
  17. package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
  18. package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
  19. package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
  20. package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
  21. package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
  22. package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
  23. package/lib/builders/SliceBuilder/index.tsx +10 -96
  24. package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
  25. package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
  26. package/lib/builders/common/Zone/Card/index.jsx +2 -0
  27. package/lib/builders/common/Zone/index.jsx +3 -1
  28. package/lib/models/common/ComponentUI.ts +0 -14
  29. package/lib/models/common/CustomType/sliceZone.ts +0 -29
  30. package/lib/models/common/CustomType/tab.ts +10 -142
  31. package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
  32. package/out/404.html +1 -1
  33. package/out/_next/static/QLcban0JdGEoFu6NgapR9/_buildManifest.js +1 -0
  34. package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
  35. package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
  36. package/out/_next/static/chunks/18539003-7b2711e6c51d6fac.js +97 -0
  37. package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
  38. package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
  39. package/out/_next/static/chunks/286-ed90373e9a469944.js +1 -0
  40. package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
  41. package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
  42. package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
  43. package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
  44. package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
  45. package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
  46. package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
  47. package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
  48. package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
  49. package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
  50. package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
  51. package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
  52. package/out/_next/static/chunks/pages/_app-3bb7f58b43c87166.js +430 -0
  53. package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
  54. package/out/_next/static/chunks/pages/{changes-52c9d917808d1461.js → changes-1cf9e7888029f113.js} +1 -1
  55. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
  56. package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
  57. package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
  58. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
  59. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
  60. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-73dd999915509965.js +1 -0
  61. package/out/_next/static/chunks/pages/slices-7b09cb5130c63bb3.js +1 -0
  62. package/out/_next/static/css/37153180c3b0dd66.css +1 -0
  63. package/out/_next/static/css/538ecf581b0e7c11.css +1 -0
  64. package/out/_next/static/css/{5da5d3cd7a87c3cf.css → 72465cc1225f28a2.css} +1 -1
  65. package/out/_next/static/css/{77abb01eee0e43a7.css → b22c0750c14cc089.css} +1 -1
  66. package/out/_next/static/css/f8eb526e10bc2441.css +1 -0
  67. package/out/changelog.html +1 -1
  68. package/out/changes.html +1 -1
  69. package/out/custom-types/[customTypeId].html +1 -1
  70. package/out/custom-types.html +1 -1
  71. package/out/index.html +1 -1
  72. package/out/labs.html +1 -1
  73. package/out/page-types/[pageTypeId].html +1 -1
  74. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  75. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  76. package/out/slices.html +1 -1
  77. package/package.json +21 -11
  78. package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
  79. package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
  80. package/src/apiClient.ts +7 -6
  81. package/src/components/CodeBlock/CodeBlock.tsx +1 -0
  82. package/src/components/Kbd/Kbd.module.css +10 -0
  83. package/src/components/Kbd/Kbd.module.css.d.ts +5 -0
  84. package/src/components/Kbd/Kbd.tsx +1 -1
  85. package/src/components/Window/Window.tsx +7 -1
  86. package/src/domain/__tests__/customType.test.ts +785 -0
  87. package/src/domain/customType.ts +519 -6
  88. package/src/domain/slice.ts +166 -1
  89. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
  90. package/src/features/autoSave/useAutoSave.tsx +177 -0
  91. package/src/features/customTypes/EditDropdown.tsx +3 -0
  92. package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
  93. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
  94. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
  95. package/src/features/customTypes/customTypesMessages.ts +4 -0
  96. package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
  97. package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
  98. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
  99. package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
  100. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
  101. package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
  102. package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
  103. package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
  104. package/src/hooks/useCurrentSlice.tsx +4 -16
  105. package/src/hooks/useScreenshotChangesModal.ts +1 -0
  106. package/src/hooks/useServerState.ts +1 -58
  107. package/src/modules/availableCustomTypes/index.ts +8 -3
  108. package/src/modules/simulator/index.ts +0 -2
  109. package/src/modules/slices/index.ts +32 -25
  110. package/src/modules/slices/selector.ts +30 -0
  111. package/src/modules/useSliceMachineActions.ts +20 -270
  112. package/src/redux/reducer.ts +0 -4
  113. package/src/redux/saga.ts +0 -6
  114. package/src/redux/type.ts +0 -4
  115. package/stylelint.config.js +17 -0
  116. package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
  117. package/test/src/modules/simulator.test.ts +0 -2
  118. package/lib/models/common/CustomType/group.ts +0 -80
  119. package/lib/models/common/Variation.ts +0 -100
  120. package/out/_next/static/3vLhj_JZ10e4rwC2sTZNQ/_buildManifest.js +0 -1
  121. package/out/_next/static/chunks/18539003-4460ccbfe3109578.js +0 -97
  122. package/out/_next/static/chunks/482-49264466566eac99.js +0 -1
  123. package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
  124. package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
  125. package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
  126. package/out/_next/static/chunks/904-fe1af089657fb0cc.js +0 -1
  127. package/out/_next/static/chunks/958-3d829456f4f5632c.js +0 -1
  128. package/out/_next/static/chunks/pages/_app-f88a66f6532a8e87.js +0 -458
  129. package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
  130. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
  131. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
  132. package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
  133. package/out/_next/static/css/1bbf650dfd37ce69.css +0 -1
  134. package/out/_next/static/css/7d650bca12dc4061.css +0 -1
  135. package/out/_next/static/css/cb33580e45d01b59.css +0 -1
  136. package/postcss.config.js +0 -2
  137. package/src/components/Kbd/Kbd.css.ts +0 -16
  138. package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
  139. package/src/layouts/WithSlice.tsx +0 -26
  140. package/src/modules/screenshots/actions.ts +0 -21
  141. package/src/modules/screenshots/sagas.ts +0 -70
  142. package/src/modules/selectedCustomType/actions.ts +0 -147
  143. package/src/modules/selectedCustomType/index.ts +0 -11
  144. package/src/modules/selectedCustomType/reducer.ts +0 -287
  145. package/src/modules/selectedCustomType/sagas.ts +0 -72
  146. package/src/modules/selectedCustomType/selectors.ts +0 -33
  147. package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
  148. package/src/modules/selectedCustomType/types.ts +0 -9
  149. package/src/modules/selectedSlice/actions.ts +0 -106
  150. package/src/modules/selectedSlice/reducer.ts +0 -175
  151. package/src/modules/selectedSlice/sagas.ts +0 -72
  152. package/src/modules/selectedSlice/selectors.ts +0 -55
  153. package/src/modules/selectedSlice/types.ts +0 -3
  154. package/src/modules/toaster/utils.tsx +0 -23
  155. package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
  156. package/test/pages/custom-types.test.tsx +0 -625
  157. package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
  158. package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
  159. package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
  160. package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
  161. package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
  162. package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
  163. package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
  164. package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
  165. package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
  166. package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
  167. package/test/src/modules/toaster/utils.test.ts +0 -50
  168. /package/out/_next/static/{3vLhj_JZ10e4rwC2sTZNQ → QLcban0JdGEoFu6NgapR9}/_ssgManifest.js +0 -0
@@ -0,0 +1,785 @@
1
+ import { describe, expect } from "vitest";
2
+
3
+ import {
4
+ CustomType,
5
+ DynamicSection,
6
+ Group,
7
+ } from "@prismicio/types-internal/lib/customtypes";
8
+
9
+ import * as CustomTypeModel from "../customType";
10
+
11
+ describe("CustomTypeModel test suite", () => {
12
+ const mainSection: DynamicSection = {
13
+ uid: {
14
+ config: {
15
+ label: "MainSectionField",
16
+ },
17
+ type: "UID",
18
+ },
19
+ booleanField: {
20
+ config: {
21
+ label: "BooleanField",
22
+ },
23
+ type: "Boolean",
24
+ },
25
+ groupField: {
26
+ type: "Group",
27
+ config: {
28
+ label: "MyGroupField",
29
+ fields: {
30
+ groupFieldBooleanField: {
31
+ config: {
32
+ label: "GroupFieldBooleanField",
33
+ },
34
+ type: "Boolean",
35
+ },
36
+ groupFieldTextField: {
37
+ config: {
38
+ label: "GroupFieldTextField",
39
+ },
40
+ type: "Text",
41
+ },
42
+ },
43
+ },
44
+ },
45
+ slices: {
46
+ type: "Slices",
47
+ fieldset: "Slice Zone",
48
+ config: {
49
+ choices: {
50
+ hero_banner: {
51
+ type: "SharedSlice",
52
+ },
53
+ promo_section_image_tiles: {
54
+ type: "SharedSlice",
55
+ },
56
+ },
57
+ },
58
+ },
59
+ };
60
+ const anotherSection: DynamicSection = {
61
+ uid: {
62
+ config: {
63
+ label: "AnotherSectionField",
64
+ },
65
+ type: "UID",
66
+ },
67
+ };
68
+ const mockCustomType: CustomType = {
69
+ format: "custom",
70
+ id: "id",
71
+ json: {
72
+ mainSection,
73
+ anotherSection,
74
+ },
75
+ label: "lama",
76
+ repeatable: true,
77
+ status: true,
78
+ };
79
+
80
+ it("getFormat should return the format 'custom' of the given custom type", () => {
81
+ expect(CustomTypeModel.getFormat(mockCustomType)).toEqual("custom");
82
+ });
83
+
84
+ it("getFormat should return the format 'page' of the given custom type", () => {
85
+ expect(
86
+ CustomTypeModel.getFormat({
87
+ ...mockCustomType,
88
+ format: "page",
89
+ }),
90
+ ).toEqual("page");
91
+ });
92
+
93
+ it("getSectionEntries should return the sections entries", () => {
94
+ expect(CustomTypeModel.getSectionEntries(mockCustomType)).toEqual([
95
+ ["mainSection", mainSection],
96
+ ["anotherSection", anotherSection],
97
+ ]);
98
+ });
99
+
100
+ it("getSectionEntries should return an empty array if there are no sections", () => {
101
+ expect(
102
+ CustomTypeModel.getSectionEntries({
103
+ ...mockCustomType,
104
+ json: {},
105
+ }),
106
+ ).toEqual([]);
107
+ });
108
+
109
+ it("getMainSectionEntry should return the first section even if not named Main", () => {
110
+ expect(CustomTypeModel.getMainSectionEntry(mockCustomType)).toEqual([
111
+ "mainSection",
112
+ mainSection,
113
+ ]);
114
+ });
115
+
116
+ it("getMainSectionEntry should return undefined if there is are sections", () => {
117
+ expect(
118
+ CustomTypeModel.getMainSectionEntry({
119
+ ...mockCustomType,
120
+ json: {},
121
+ }),
122
+ ).toEqual(undefined);
123
+ });
124
+
125
+ it("getSection should return the section matching the key", () => {
126
+ expect(
127
+ CustomTypeModel.getSection(mockCustomType, "anotherSection"),
128
+ ).toEqual(anotherSection);
129
+ });
130
+
131
+ it("getSection should return undefined if there are no sections", () => {
132
+ expect(
133
+ CustomTypeModel.getSection(
134
+ {
135
+ ...mockCustomType,
136
+ json: {},
137
+ },
138
+ "mainSection",
139
+ ),
140
+ ).toEqual(undefined);
141
+ });
142
+
143
+ it("getSectionSliceZoneEntry should return the slice zone of the given section", () => {
144
+ expect(
145
+ CustomTypeModel.getSectionSliceZoneEntry(mockCustomType, "mainSection"),
146
+ ).toEqual([
147
+ "slices",
148
+ {
149
+ type: "Slices",
150
+ fieldset: "Slice Zone",
151
+ config: {
152
+ choices: {
153
+ hero_banner: {
154
+ type: "SharedSlice",
155
+ },
156
+ promo_section_image_tiles: {
157
+ type: "SharedSlice",
158
+ },
159
+ },
160
+ },
161
+ },
162
+ ]);
163
+ });
164
+
165
+ it("getSectionSliceZoneConfig should return the config of the given section", () => {
166
+ expect(
167
+ CustomTypeModel.getSectionSliceZoneConfig(mockCustomType, "mainSection"),
168
+ ).toEqual({
169
+ choices: {
170
+ hero_banner: {
171
+ type: "SharedSlice",
172
+ },
173
+ promo_section_image_tiles: {
174
+ type: "SharedSlice",
175
+ },
176
+ },
177
+ });
178
+ });
179
+
180
+ it("getSectionSliceZoneConfig should return undefined if there are no sections", () => {
181
+ expect(
182
+ CustomTypeModel.getSectionSliceZoneConfig(
183
+ {
184
+ ...mockCustomType,
185
+ json: {},
186
+ },
187
+ "mainSection",
188
+ ),
189
+ ).toEqual(undefined);
190
+ });
191
+
192
+ it("findNextSectionSliceZoneKey should return 'slices'", () => {
193
+ expect(
194
+ CustomTypeModel.findNextSectionSliceZoneKey(
195
+ {
196
+ ...mockCustomType,
197
+ json: {
198
+ anotherSection: {},
199
+ },
200
+ },
201
+ "anotherSection",
202
+ ),
203
+ ).toEqual("slices");
204
+ });
205
+
206
+ it("findNextSectionSliceZoneKey should return 'slices1'", () => {
207
+ expect(
208
+ CustomTypeModel.findNextSectionSliceZoneKey(
209
+ mockCustomType,
210
+ "anotherSection",
211
+ ),
212
+ ).toEqual("slices1");
213
+ });
214
+
215
+ it("findNextSectionSliceZoneKey should return 'slices2'", () => {
216
+ expect(
217
+ CustomTypeModel.findNextSectionSliceZoneKey(
218
+ {
219
+ ...mockCustomType,
220
+ json: {
221
+ mainSection,
222
+ SecondSection: {
223
+ slices1: {
224
+ type: "Slices",
225
+ },
226
+ },
227
+ anotherSection,
228
+ },
229
+ },
230
+ "anotherSection",
231
+ ),
232
+ ).toEqual("slices2");
233
+ });
234
+
235
+ it("findNextSectionSliceZoneKey should return 'slices3'", () => {
236
+ expect(
237
+ CustomTypeModel.findNextSectionSliceZoneKey(
238
+ {
239
+ ...mockCustomType,
240
+ json: {
241
+ mainSection,
242
+ SecondSection: {
243
+ slices2: {
244
+ type: "Slices",
245
+ },
246
+ },
247
+ anotherSection,
248
+ },
249
+ },
250
+ "anotherSection",
251
+ ),
252
+ ).toEqual("slices3");
253
+ });
254
+
255
+ it("createSectionSliceZone should return the given custom type with a slice zone for given section", () => {
256
+ expect(
257
+ CustomTypeModel.createSectionSliceZone(mockCustomType, "anotherSection"),
258
+ ).toEqual({
259
+ ...mockCustomType,
260
+ json: {
261
+ ...mockCustomType.json,
262
+ anotherSection: {
263
+ ...anotherSection,
264
+ slices1: {
265
+ type: "Slices",
266
+ fieldset: "Slice Zone",
267
+ },
268
+ },
269
+ },
270
+ });
271
+ });
272
+
273
+ it("createSectionSliceZone should return the same custom type if slice zone already exist for given section", () => {
274
+ expect(
275
+ CustomTypeModel.createSectionSliceZone(mockCustomType, "mainSection"),
276
+ ).toEqual(mockCustomType);
277
+ });
278
+
279
+ it("deleteSectionSliceZone should return the custom type without the slice zone deleted", () => {
280
+ expect(
281
+ CustomTypeModel.deleteSectionSliceZone(mockCustomType, "mainSection"),
282
+ ).toEqual({
283
+ ...mockCustomType,
284
+ json: {
285
+ mainSection: {
286
+ uid: mainSection.uid,
287
+ booleanField: mainSection.booleanField,
288
+ groupField: mainSection.groupField,
289
+ },
290
+ anotherSection,
291
+ },
292
+ });
293
+ });
294
+
295
+ it("deleteSliceZoneSlice should return the custom type without the slice deleted", () => {
296
+ expect(
297
+ CustomTypeModel.deleteSliceZoneSlice({
298
+ customType: mockCustomType,
299
+ sectionId: "mainSection",
300
+ sliceId: "hero_banner",
301
+ }),
302
+ ).toEqual({
303
+ ...mockCustomType,
304
+ json: {
305
+ mainSection: {
306
+ ...mainSection,
307
+ slices: {
308
+ ...mainSection.slices,
309
+ config: {
310
+ ...mainSection.slices.config,
311
+ choices: {
312
+ promo_section_image_tiles: {
313
+ type: "SharedSlice",
314
+ },
315
+ },
316
+ },
317
+ },
318
+ },
319
+ anotherSection,
320
+ },
321
+ });
322
+ });
323
+
324
+ it("convertToPageType should convert the given custom type", () => {
325
+ expect(CustomTypeModel.convertToPageType(mockCustomType)).toEqual({
326
+ ...mockCustomType,
327
+ format: "page",
328
+ });
329
+ });
330
+
331
+ it("convertToPageType should convert the given custom type with a slice zone for Main section when it doesn't exist", () => {
332
+ expect(
333
+ CustomTypeModel.convertToPageType({
334
+ ...mockCustomType,
335
+ json: {
336
+ mainSection: {},
337
+ anotherSection,
338
+ },
339
+ }),
340
+ ).toEqual({
341
+ ...mockCustomType,
342
+ json: {
343
+ mainSection: {
344
+ slices: {
345
+ type: "Slices",
346
+ fieldset: "Slice Zone",
347
+ },
348
+ },
349
+ anotherSection,
350
+ },
351
+ format: "page",
352
+ });
353
+ });
354
+
355
+ it("createSection should return the given custom type with the new section", () => {
356
+ expect(CustomTypeModel.createSection(mockCustomType, "newSection")).toEqual(
357
+ {
358
+ ...mockCustomType,
359
+ json: {
360
+ ...mockCustomType.json,
361
+ newSection: {},
362
+ },
363
+ },
364
+ );
365
+ });
366
+
367
+ it("deleteSection should return the given custom type without the section", () => {
368
+ expect(
369
+ CustomTypeModel.deleteSection(mockCustomType, "anotherSection"),
370
+ ).toEqual({
371
+ ...mockCustomType,
372
+ json: {
373
+ mainSection,
374
+ },
375
+ });
376
+ });
377
+
378
+ it("renameSection should return the given custom type with the section renamed", () => {
379
+ expect(
380
+ CustomTypeModel.renameSection(
381
+ mockCustomType,
382
+ "anotherSection",
383
+ "newSection",
384
+ ),
385
+ ).toEqual({
386
+ ...mockCustomType,
387
+ json: {
388
+ mainSection,
389
+ newSection: anotherSection,
390
+ },
391
+ });
392
+ });
393
+
394
+ it("addField should return the given custom type with the field added to the section", () => {
395
+ expect(
396
+ CustomTypeModel.addField({
397
+ customType: mockCustomType,
398
+ sectionId: "mainSection",
399
+ newFieldId: "newField",
400
+ newField: {
401
+ config: {
402
+ label: "NewField",
403
+ },
404
+ type: "UID",
405
+ },
406
+ }),
407
+ ).toEqual({
408
+ ...mockCustomType,
409
+ json: {
410
+ ...mockCustomType.json,
411
+ mainSection: {
412
+ ...mainSection,
413
+ newField: {
414
+ config: {
415
+ label: "NewField",
416
+ },
417
+ type: "UID",
418
+ },
419
+ },
420
+ },
421
+ });
422
+ });
423
+
424
+ it("deleteField should return the given custom type without the field", () => {
425
+ expect(
426
+ CustomTypeModel.deleteField({
427
+ customType: mockCustomType,
428
+ sectionId: "mainSection",
429
+ fieldId: "booleanField",
430
+ }),
431
+ ).toEqual({
432
+ ...mockCustomType,
433
+ json: {
434
+ ...mockCustomType.json,
435
+ mainSection: {
436
+ uid: mainSection.uid,
437
+ groupField: mainSection.groupField,
438
+ slices: mainSection.slices,
439
+ },
440
+ },
441
+ });
442
+ });
443
+
444
+ it("updateField should return the given custom type with the field updated", () => {
445
+ expect(
446
+ CustomTypeModel.updateField({
447
+ customType: mockCustomType,
448
+ sectionId: "mainSection",
449
+ previousFieldId: "booleanField",
450
+ newFieldId: "newId",
451
+ newField: {
452
+ config: {
453
+ label: "newLabel",
454
+ },
455
+ type: "Boolean",
456
+ },
457
+ }),
458
+ ).toEqual({
459
+ ...mockCustomType,
460
+ json: {
461
+ ...mockCustomType.json,
462
+ mainSection: {
463
+ uid: mainSection.uid,
464
+ newId: {
465
+ config: {
466
+ label: "newLabel",
467
+ },
468
+ type: "Boolean",
469
+ },
470
+ groupField: mainSection.groupField,
471
+ slices: mainSection.slices,
472
+ },
473
+ },
474
+ });
475
+ });
476
+
477
+ it("reorderField should return the given custom type with the field reordered", () => {
478
+ expect(
479
+ JSON.stringify(
480
+ CustomTypeModel.reorderField({
481
+ customType: mockCustomType,
482
+ sectionId: "mainSection",
483
+ sourceIndex: 0,
484
+ destinationIndex: 1,
485
+ }),
486
+ ),
487
+ ).toEqual(
488
+ JSON.stringify({
489
+ ...mockCustomType,
490
+ json: {
491
+ ...mockCustomType.json,
492
+ mainSection: {
493
+ booleanField: mainSection.booleanField,
494
+ uid: mainSection.uid,
495
+ groupField: mainSection.groupField,
496
+ slices: mainSection.slices,
497
+ },
498
+ },
499
+ }),
500
+ );
501
+ });
502
+
503
+ it("addGroupField should return the given custom type with the group field added", () => {
504
+ expect(
505
+ CustomTypeModel.addGroupField({
506
+ customType: mockCustomType,
507
+ sectionId: "mainSection",
508
+ groupFieldId: "groupField",
509
+ newFieldId: "newFieldId",
510
+ newField: {
511
+ config: {
512
+ label: "NewField",
513
+ },
514
+ type: "Boolean",
515
+ },
516
+ }),
517
+ ).toEqual({
518
+ ...mockCustomType,
519
+ json: {
520
+ ...mockCustomType.json,
521
+ mainSection: {
522
+ ...mainSection,
523
+ groupField: {
524
+ ...mainSection.groupField,
525
+ config: {
526
+ ...mainSection.groupField.config,
527
+ fields: {
528
+ ...(mainSection.groupField as Group).config?.fields,
529
+ newFieldId: {
530
+ config: {
531
+ label: "NewField",
532
+ },
533
+ type: "Boolean",
534
+ },
535
+ },
536
+ },
537
+ },
538
+ },
539
+ },
540
+ });
541
+ });
542
+
543
+ it("deleteGroupField should return the given custom type without the group field", () => {
544
+ expect(
545
+ CustomTypeModel.deleteGroupField({
546
+ customType: mockCustomType,
547
+ sectionId: "mainSection",
548
+ groupFieldId: "groupField",
549
+ fieldId: "groupFieldBooleanField",
550
+ }),
551
+ ).toEqual({
552
+ ...mockCustomType,
553
+ json: {
554
+ ...mockCustomType.json,
555
+ mainSection: {
556
+ ...mainSection,
557
+ groupField: {
558
+ ...mainSection.groupField,
559
+ config: {
560
+ ...mainSection.groupField.config,
561
+ fields: {
562
+ groupFieldTextField: (mainSection.groupField as Group).config
563
+ ?.fields?.groupFieldTextField,
564
+ },
565
+ },
566
+ },
567
+ },
568
+ },
569
+ });
570
+ });
571
+
572
+ it("updateGroupField should return the given custom type with the group field updated", () => {
573
+ expect(
574
+ CustomTypeModel.updateGroupField({
575
+ customType: mockCustomType,
576
+ sectionId: "mainSection",
577
+ groupFieldId: "groupField",
578
+ previousFieldId: "groupFieldBooleanField",
579
+ newFieldId: "newId",
580
+ newField: {
581
+ config: {
582
+ label: "newLabel",
583
+ },
584
+ type: "Boolean",
585
+ },
586
+ }),
587
+ ).toEqual({
588
+ ...mockCustomType,
589
+ json: {
590
+ ...mockCustomType.json,
591
+ mainSection: {
592
+ ...mainSection,
593
+ groupField: {
594
+ ...mainSection.groupField,
595
+ config: {
596
+ ...mainSection.groupField.config,
597
+ fields: {
598
+ newId: {
599
+ config: {
600
+ label: "newLabel",
601
+ },
602
+ type: "Boolean",
603
+ },
604
+ groupFieldTextField: (mainSection.groupField as Group).config
605
+ ?.fields?.groupFieldTextField,
606
+ },
607
+ },
608
+ },
609
+ },
610
+ },
611
+ });
612
+ });
613
+
614
+ it("reorderGroupField should return the given custom type with the group field reordered", () => {
615
+ expect(
616
+ JSON.stringify(
617
+ CustomTypeModel.reorderGroupField({
618
+ customType: mockCustomType,
619
+ sectionId: "mainSection",
620
+ groupFieldId: "groupField",
621
+ sourceIndex: 0,
622
+ destinationIndex: 1,
623
+ }),
624
+ ),
625
+ ).toEqual(
626
+ JSON.stringify({
627
+ ...mockCustomType,
628
+ json: {
629
+ ...mockCustomType.json,
630
+ mainSection: {
631
+ ...mainSection,
632
+ groupField: {
633
+ ...mainSection.groupField,
634
+ config: {
635
+ ...mainSection.groupField.config,
636
+ fields: {
637
+ groupFieldTextField: (mainSection.groupField as Group).config
638
+ ?.fields?.groupFieldTextField,
639
+ groupFieldBooleanField: (mainSection.groupField as Group)
640
+ .config?.fields?.groupFieldBooleanField,
641
+ },
642
+ },
643
+ },
644
+ },
645
+ },
646
+ }),
647
+ );
648
+ });
649
+
650
+ it("updateSection should return the given custom type with the section updated", () => {
651
+ expect(
652
+ CustomTypeModel.updateSection({
653
+ customType: mockCustomType,
654
+ sectionId: "anotherSection",
655
+ updatedSection: {
656
+ uid: {
657
+ config: {
658
+ label: "AnotherSectionFieldUpdated",
659
+ },
660
+ type: "UID",
661
+ },
662
+ },
663
+ }),
664
+ ).toEqual({
665
+ ...mockCustomType,
666
+ json: {
667
+ mainSection,
668
+ anotherSection: {
669
+ uid: {
670
+ config: {
671
+ label: "AnotherSectionFieldUpdated",
672
+ },
673
+ type: "UID",
674
+ },
675
+ },
676
+ },
677
+ });
678
+ });
679
+
680
+ it("updateFields should return the updated fields", () => {
681
+ expect(
682
+ CustomTypeModel.updateFields({
683
+ fields: {
684
+ booleanField: {
685
+ config: {
686
+ label: "BooleanFieldUpdated",
687
+ },
688
+ type: "Boolean",
689
+ },
690
+ },
691
+ previousFieldId: "booleanField",
692
+ newFieldId: "newField",
693
+ newField: {
694
+ config: {
695
+ label: "NewField",
696
+ },
697
+ type: "UID",
698
+ },
699
+ }),
700
+ ).toEqual({
701
+ newField: {
702
+ config: {
703
+ label: "NewField",
704
+ },
705
+ type: "UID",
706
+ },
707
+ });
708
+ });
709
+
710
+ it("reorderFields should return the reordered fields", () => {
711
+ expect(
712
+ JSON.stringify(
713
+ CustomTypeModel.reorderFields({
714
+ fields: {
715
+ booleanField: {
716
+ config: {
717
+ label: "BooleanField",
718
+ },
719
+ type: "Boolean",
720
+ },
721
+ textField: {
722
+ config: {
723
+ label: "TextField",
724
+ },
725
+ type: "Text",
726
+ },
727
+ },
728
+ sourceIndex: 0,
729
+ destinationIndex: 1,
730
+ }),
731
+ ),
732
+ ).toEqual(
733
+ JSON.stringify({
734
+ textField: {
735
+ config: {
736
+ label: "TextField",
737
+ },
738
+ type: "Text",
739
+ },
740
+ booleanField: {
741
+ config: {
742
+ label: "BooleanField",
743
+ },
744
+ type: "Boolean",
745
+ },
746
+ }),
747
+ );
748
+ });
749
+
750
+ it("getGroupField should return the group field matching the key", () => {
751
+ expect(
752
+ CustomTypeModel.getGroupField({
753
+ customType: mockCustomType,
754
+ sectionId: "mainSection",
755
+ groupFieldId: "groupField",
756
+ }),
757
+ ).toEqual(mainSection.groupField);
758
+ });
759
+
760
+ it("updateGroupFields should return the updated group fields", () => {
761
+ expect(
762
+ CustomTypeModel.updateGroupFields(mainSection.groupField as Group, {
763
+ groupFieldBooleanField: {
764
+ config: {
765
+ label: "GroupFieldBooleanField",
766
+ },
767
+ type: "Boolean",
768
+ },
769
+ }),
770
+ ).toEqual({
771
+ ...mainSection.groupField,
772
+ config: {
773
+ ...mainSection.groupField.config,
774
+ fields: {
775
+ groupFieldBooleanField: {
776
+ config: {
777
+ label: "GroupFieldBooleanField",
778
+ },
779
+ type: "Boolean",
780
+ },
781
+ },
782
+ },
783
+ });
784
+ });
785
+ });