slice-machine-ui 1.22.3-beta.1 → 1.22.3-beta.3
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/components/DeleteVariationModal/index.tsx +12 -11
- package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
- package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
- package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
- package/components/ItemHeader/index.tsx +1 -0
- package/components/ListItem/index.tsx +5 -2
- package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
- package/components/ScreenshotChangesModal/index.tsx +3 -0
- package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
- package/components/Simulator/index.tsx +9 -3
- package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
- package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
- package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
- package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
- package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
- package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
- package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
- package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
- package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
- package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
- package/lib/builders/SliceBuilder/index.tsx +10 -96
- package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
- package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
- package/lib/builders/common/Zone/Card/index.jsx +2 -0
- package/lib/builders/common/Zone/index.jsx +3 -1
- package/lib/models/common/ComponentUI.ts +0 -14
- package/lib/models/common/CustomType/sliceZone.ts +0 -29
- package/lib/models/common/CustomType/tab.ts +10 -142
- package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
- package/out/404.html +1 -1
- package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
- package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
- package/out/_next/static/chunks/18539003-7b2711e6c51d6fac.js +97 -0
- package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
- package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
- package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
- package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
- package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
- package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
- package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
- package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
- package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
- package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
- package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
- package/out/_next/static/chunks/787-727e3aef5d2a10a8.js +1 -0
- package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
- package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
- package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
- package/out/_next/static/chunks/pages/_app-20876abeebe0fda7.js +430 -0
- package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
- package/out/_next/static/chunks/pages/changes-6f62ae7b6243a1c7.js +1 -0
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
- package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
- package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-e89e2e6f772a3454.js +1 -0
- package/out/_next/static/chunks/pages/slices-9628f8aa54968d6a.js +1 -0
- package/out/_next/static/css/{1bbf650dfd37ce69.css → 1aa04669758c24f4.css} +1 -1
- package/out/_next/static/j_voPTrYzsuLCERqtl3Hn/_buildManifest.js +1 -0
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +6 -6
- package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
- package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
- package/src/apiClient.ts +7 -6
- package/src/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/components/Window/Window.tsx +7 -1
- package/src/domain/__tests__/customType.test.ts +785 -0
- package/src/domain/customType.ts +519 -6
- package/src/domain/slice.ts +166 -1
- package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
- package/src/features/autoSave/useAutoSave.tsx +177 -0
- package/src/features/customTypes/EditDropdown.tsx +3 -0
- package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
- package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
- package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
- package/src/features/customTypes/customTypesMessages.ts +4 -0
- package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
- package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
- package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
- package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
- package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
- package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
- package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
- package/src/hooks/useCurrentSlice.tsx +4 -16
- package/src/hooks/useScreenshotChangesModal.ts +1 -0
- package/src/hooks/useServerState.ts +1 -58
- package/src/modules/availableCustomTypes/index.ts +8 -3
- package/src/modules/simulator/index.ts +0 -2
- package/src/modules/slices/index.ts +32 -25
- package/src/modules/slices/selector.ts +30 -0
- package/src/modules/useSliceMachineActions.ts +20 -270
- package/src/redux/reducer.ts +0 -4
- package/src/redux/saga.ts +0 -6
- package/src/redux/type.ts +0 -4
- package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
- package/test/src/modules/simulator.test.ts +0 -2
- package/lib/models/common/CustomType/group.ts +0 -80
- package/lib/models/common/Variation.ts +0 -100
- package/out/_next/static/ZrWICkLApT4ZATA_akn-2/_buildManifest.js +0 -1
- package/out/_next/static/chunks/18539003-4460ccbfe3109578.js +0 -97
- package/out/_next/static/chunks/482-34cee2a2071c235f.js +0 -1
- package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
- package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
- package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
- package/out/_next/static/chunks/904-519dbf0f7e8c6243.js +0 -1
- package/out/_next/static/chunks/958-8aca174b80cb0c35.js +0 -1
- package/out/_next/static/chunks/pages/_app-132564608e9a9502.js +0 -458
- package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
- package/out/_next/static/chunks/pages/changes-52c9d917808d1461.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
- package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
- package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
- package/src/layouts/WithSlice.tsx +0 -26
- package/src/modules/screenshots/actions.ts +0 -21
- package/src/modules/screenshots/sagas.ts +0 -70
- package/src/modules/selectedCustomType/actions.ts +0 -147
- package/src/modules/selectedCustomType/index.ts +0 -11
- package/src/modules/selectedCustomType/reducer.ts +0 -287
- package/src/modules/selectedCustomType/sagas.ts +0 -72
- package/src/modules/selectedCustomType/selectors.ts +0 -33
- package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
- package/src/modules/selectedCustomType/types.ts +0 -9
- package/src/modules/selectedSlice/actions.ts +0 -106
- package/src/modules/selectedSlice/reducer.ts +0 -175
- package/src/modules/selectedSlice/sagas.ts +0 -72
- package/src/modules/selectedSlice/selectors.ts +0 -55
- package/src/modules/selectedSlice/types.ts +0 -3
- package/src/modules/toaster/utils.tsx +0 -23
- package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
- package/test/pages/custom-types.test.tsx +0 -625
- package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
- package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
- package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
- package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
- package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
- package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
- package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
- package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
- package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
- package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
- package/test/src/modules/toaster/utils.test.ts +0 -50
- /package/out/_next/static/{ZrWICkLApT4ZATA_akn-2 → j_voPTrYzsuLCERqtl3Hn}/_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
|
+
});
|