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
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "homepage",
|
|
3
|
-
"label": "Homepage",
|
|
4
|
-
"status": true,
|
|
5
|
-
"repeatable": false,
|
|
6
|
-
"json": {
|
|
7
|
-
"Main": {
|
|
8
|
-
"rt222": {
|
|
9
|
-
"type": "StructuredText",
|
|
10
|
-
"config": {
|
|
11
|
-
"label": "rt",
|
|
12
|
-
"placeholder": "",
|
|
13
|
-
"allowTargetBlank": true,
|
|
14
|
-
"multi": "paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"group11": {
|
|
18
|
-
"type": "Group",
|
|
19
|
-
"config": {
|
|
20
|
-
"type": "Group",
|
|
21
|
-
"fields": {
|
|
22
|
-
"aaa2": {
|
|
23
|
-
"type": "Image",
|
|
24
|
-
"config": {
|
|
25
|
-
"label": "",
|
|
26
|
-
"constraint": {},
|
|
27
|
-
"thumbnails": []
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"aaa3": {
|
|
31
|
-
"type": "StructuredText",
|
|
32
|
-
"config": {
|
|
33
|
-
"label": "",
|
|
34
|
-
"placeholder": "",
|
|
35
|
-
"allowTargetBlank": true,
|
|
36
|
-
"single": "paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"sss4": {
|
|
40
|
-
"type": "Image",
|
|
41
|
-
"config": {
|
|
42
|
-
"label": "",
|
|
43
|
-
"constraint": {},
|
|
44
|
-
"thumbnails": []
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"text": {
|
|
48
|
-
"type": "Text",
|
|
49
|
-
"config": {
|
|
50
|
-
"label": "",
|
|
51
|
-
"placeholder": ""
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
"group9": {
|
|
58
|
-
"type": "Group",
|
|
59
|
-
"config": {
|
|
60
|
-
"fields": {
|
|
61
|
-
"txt": {
|
|
62
|
-
"type": "Text",
|
|
63
|
-
"config": {
|
|
64
|
-
"label": "",
|
|
65
|
-
"placeholder": ""
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
"text": {
|
|
69
|
-
"type": "Text",
|
|
70
|
-
"config": {
|
|
71
|
-
"label": "",
|
|
72
|
-
"placeholder": ""
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"img": {
|
|
76
|
-
"type": "Image",
|
|
77
|
-
"config": {
|
|
78
|
-
"label": "",
|
|
79
|
-
"constraint": {},
|
|
80
|
-
"thumbnails": []
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"sdf": {
|
|
87
|
-
"type": "Image",
|
|
88
|
-
"config": {
|
|
89
|
-
"label": "",
|
|
90
|
-
"constraint": {},
|
|
91
|
-
"thumbnails": []
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
"body": {
|
|
95
|
-
"type": "Slices",
|
|
96
|
-
"fieldset": "Slice Zone",
|
|
97
|
-
"config": {
|
|
98
|
-
"choices": {
|
|
99
|
-
"with_mocks": {
|
|
100
|
-
"type": "SharedSlice"
|
|
101
|
-
},
|
|
102
|
-
"cards_carousel": {
|
|
103
|
-
"type": "SharedSlice"
|
|
104
|
-
},
|
|
105
|
-
"images_slider": {
|
|
106
|
-
"type": "SharedSlice"
|
|
107
|
-
},
|
|
108
|
-
"feature_testimonials": {
|
|
109
|
-
"type": "SharedSlice"
|
|
110
|
-
},
|
|
111
|
-
"alternate_grid": {
|
|
112
|
-
"type": "SharedSlice"
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { CustomTypes } from "@lib/models/common/CustomType";
|
|
3
|
-
import jsonModel from "./__fixtures__/model.json";
|
|
4
|
-
import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
5
|
-
import {
|
|
6
|
-
addFieldCreator,
|
|
7
|
-
createSliceZoneCreator,
|
|
8
|
-
createTabCreator,
|
|
9
|
-
selectedCustomTypeReducer,
|
|
10
|
-
deleteFieldCreator,
|
|
11
|
-
initCustomTypeStoreCreator,
|
|
12
|
-
reorderFieldCreator,
|
|
13
|
-
replaceFieldCreator,
|
|
14
|
-
updateTabCreator,
|
|
15
|
-
cleanupCustomTypeStoreCreator,
|
|
16
|
-
} from "@src/modules/selectedCustomType";
|
|
17
|
-
import { SelectedCustomTypeStoreType } from "@src/modules/selectedCustomType/types";
|
|
18
|
-
import * as widgets from "@models/common/widgets/withGroup";
|
|
19
|
-
import equal from "fast-deep-equal";
|
|
20
|
-
|
|
21
|
-
const customTypeAsArray = CustomTypes.toSM(jsonModel as unknown as CustomType);
|
|
22
|
-
|
|
23
|
-
const dummyCustomTypesState: SelectedCustomTypeStoreType = {
|
|
24
|
-
model: customTypeAsArray,
|
|
25
|
-
initialModel: customTypeAsArray,
|
|
26
|
-
// @ts-expect-error TS(2322) FIXME: Type 'null' is not assignable to type '({ id: stri... Remove this comment to see the full error message
|
|
27
|
-
remoteModel: null,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
describe("[Selected Custom type module]", () => {
|
|
31
|
-
describe("[Reducer]", () => {
|
|
32
|
-
it("should return the initial state if no action", () => {
|
|
33
|
-
// @ts-expect-error TS(2345) FIXME: Argument of type '{}' is not assignable to paramet... Remove this comment to see the full error message
|
|
34
|
-
expect(selectedCustomTypeReducer(dummyCustomTypesState, {})).toEqual(
|
|
35
|
-
dummyCustomTypesState,
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should return the initial state if no matching action", () => {
|
|
40
|
-
expect(
|
|
41
|
-
// @ts-expect-error TS(2322) FIXME: Type '"NO.MATCH"' is not assignable to type '"CUST... Remove this comment to see the full error message
|
|
42
|
-
selectedCustomTypeReducer(dummyCustomTypesState, { type: "NO.MATCH" }),
|
|
43
|
-
).toEqual(dummyCustomTypesState);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should reset the custom type state given CUSTOM_TYPE/CLEANUP action", () => {
|
|
47
|
-
expect(
|
|
48
|
-
selectedCustomTypeReducer(
|
|
49
|
-
dummyCustomTypesState,
|
|
50
|
-
cleanupCustomTypeStoreCreator(),
|
|
51
|
-
),
|
|
52
|
-
).toEqual(null);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should update the custom type state given CUSTOM_TYPE/INIT action", () => {
|
|
56
|
-
expect(
|
|
57
|
-
selectedCustomTypeReducer(
|
|
58
|
-
dummyCustomTypesState,
|
|
59
|
-
initCustomTypeStoreCreator({
|
|
60
|
-
model: customTypeAsArray,
|
|
61
|
-
remoteModel: undefined,
|
|
62
|
-
}),
|
|
63
|
-
),
|
|
64
|
-
).toEqual({
|
|
65
|
-
model: customTypeAsArray,
|
|
66
|
-
initialModel: customTypeAsArray,
|
|
67
|
-
remoteModel: undefined,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
it("should update the custom type state given CUSTOM_TYPE/CREATE_TAB action", () => {
|
|
71
|
-
const newTabId = "Tab1";
|
|
72
|
-
const previousTabLength = dummyCustomTypesState?.model.tabs.length ?? 0;
|
|
73
|
-
const newState = selectedCustomTypeReducer(
|
|
74
|
-
dummyCustomTypesState,
|
|
75
|
-
createTabCreator({
|
|
76
|
-
tabId: newTabId,
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
80
|
-
const tabs = newState.model.tabs;
|
|
81
|
-
expect(tabs.length).toEqual(previousTabLength + 1);
|
|
82
|
-
expect(tabs[tabs.length - 1].key).toBe(newTabId);
|
|
83
|
-
|
|
84
|
-
/** Don't create a second tab with same key */
|
|
85
|
-
const newState2 = selectedCustomTypeReducer(
|
|
86
|
-
dummyCustomTypesState,
|
|
87
|
-
createTabCreator({
|
|
88
|
-
tabId: newTabId,
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
92
|
-
const tabs2 = newState2.model.tabs;
|
|
93
|
-
expect(tabs2.length).toBe(tabs.length);
|
|
94
|
-
});
|
|
95
|
-
it("should update the custom type state given CUSTOM_TYPE/UPDATE_TAB action if the tab is found", () => {
|
|
96
|
-
const newTabId = "Tab1";
|
|
97
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
98
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
99
|
-
const newState = selectedCustomTypeReducer(
|
|
100
|
-
dummyCustomTypesState,
|
|
101
|
-
updateTabCreator({
|
|
102
|
-
newTabId,
|
|
103
|
-
tabId: initialTab.key,
|
|
104
|
-
}),
|
|
105
|
-
);
|
|
106
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
107
|
-
const tabs = newState.model.tabs[0];
|
|
108
|
-
expect(tabs.key).toBe(newTabId);
|
|
109
|
-
});
|
|
110
|
-
it("should not update the custom type state given CUSTOM_TYPE/UPDATE_TAB action if the tab is not found", () => {
|
|
111
|
-
const newTabId = "Tab1";
|
|
112
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
113
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
114
|
-
const unknownTabId = `some___${initialTab.key}`;
|
|
115
|
-
const newState = selectedCustomTypeReducer(
|
|
116
|
-
dummyCustomTypesState,
|
|
117
|
-
updateTabCreator({
|
|
118
|
-
newTabId,
|
|
119
|
-
tabId: unknownTabId,
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
124
|
-
const tabs = newState.model.tabs[0];
|
|
125
|
-
expect(tabs.key).toBe(initialTab.key);
|
|
126
|
-
|
|
127
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
128
|
-
expect(!!newState.model.tabs.find((e) => e.key === unknownTabId)).toBe(
|
|
129
|
-
false,
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
it("should add a field into a custom type given CUSTOM_TYPE/ADD_FIELD action", () => {
|
|
133
|
-
const fieldId = "fieldId";
|
|
134
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
135
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
136
|
-
const newState = selectedCustomTypeReducer(
|
|
137
|
-
dummyCustomTypesState,
|
|
138
|
-
addFieldCreator({
|
|
139
|
-
tabId: initialTab.key,
|
|
140
|
-
fieldId,
|
|
141
|
-
field: widgets.Boolean.create(fieldId),
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
146
|
-
const tabValue = newState.model.tabs[0].value;
|
|
147
|
-
expect(tabValue.length).toEqual(initialTab.value.length + 1);
|
|
148
|
-
expect(tabValue[tabValue.length - 1].key).toEqual(fieldId);
|
|
149
|
-
});
|
|
150
|
-
it("should remove a field into a custom type given CUSTOM_TYPE/DELETE_FIELD action", () => {
|
|
151
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
152
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
153
|
-
const newState = selectedCustomTypeReducer(
|
|
154
|
-
dummyCustomTypesState,
|
|
155
|
-
deleteFieldCreator({
|
|
156
|
-
tabId: initialTab.key,
|
|
157
|
-
fieldId: initialTab.value[0].key,
|
|
158
|
-
}),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
162
|
-
expect(newState.model.tabs[0].value.length).toEqual(
|
|
163
|
-
initialTab.value.length - 1,
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
it("should reorder fields into a custom type given CUSTOM_TYPE/REORDER_FIELD action", () => {
|
|
167
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
168
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
169
|
-
const fieldIdA = initialTab.value[0].key;
|
|
170
|
-
const fieldIdB = initialTab.value[1].key;
|
|
171
|
-
const fieldIdC = initialTab.value[2].key;
|
|
172
|
-
const newState = selectedCustomTypeReducer(
|
|
173
|
-
dummyCustomTypesState,
|
|
174
|
-
reorderFieldCreator({
|
|
175
|
-
tabId: initialTab.key,
|
|
176
|
-
start: 0,
|
|
177
|
-
end: 1,
|
|
178
|
-
}),
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
182
|
-
expect(newState.model.tabs[0].value[0].key).toEqual(fieldIdB);
|
|
183
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
184
|
-
expect(newState.model.tabs[0].value[1].key).toEqual(fieldIdA);
|
|
185
|
-
|
|
186
|
-
const newState2 = selectedCustomTypeReducer(
|
|
187
|
-
newState,
|
|
188
|
-
reorderFieldCreator({
|
|
189
|
-
tabId: initialTab.key,
|
|
190
|
-
start: 0,
|
|
191
|
-
end: 1,
|
|
192
|
-
}),
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
196
|
-
expect(newState2.model.tabs[0].value[0].key).toEqual(fieldIdA);
|
|
197
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
198
|
-
expect(newState2.model.tabs[0].value[1].key).toEqual(fieldIdB);
|
|
199
|
-
|
|
200
|
-
const newState3 = selectedCustomTypeReducer(
|
|
201
|
-
newState2,
|
|
202
|
-
reorderFieldCreator({
|
|
203
|
-
tabId: initialTab.key,
|
|
204
|
-
start: 0,
|
|
205
|
-
end: 2,
|
|
206
|
-
}),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
210
|
-
expect(newState3.model.tabs[0].value[0].key).toEqual(fieldIdB);
|
|
211
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
212
|
-
expect(newState3.model.tabs[0].value[1].key).toEqual(fieldIdC);
|
|
213
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
214
|
-
expect(newState3.model.tabs[0].value[2].key).toEqual(fieldIdA);
|
|
215
|
-
|
|
216
|
-
const newState4 = selectedCustomTypeReducer(
|
|
217
|
-
newState3,
|
|
218
|
-
reorderFieldCreator({
|
|
219
|
-
tabId: initialTab.key,
|
|
220
|
-
start: 2,
|
|
221
|
-
end: 0,
|
|
222
|
-
}),
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
226
|
-
expect(newState4.model.tabs[0].value[0].key).toEqual(fieldIdA);
|
|
227
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
228
|
-
expect(newState4.model.tabs[0].value[1].key).toEqual(fieldIdB);
|
|
229
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
230
|
-
expect(newState4.model.tabs[0].value[2].key).toEqual(fieldIdC);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
it("should create a empty slicezone into a custom type given CUSTOM_TYPE/CREATE_SLICE_ZONE action", () => {
|
|
234
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
235
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
236
|
-
const newState = selectedCustomTypeReducer(
|
|
237
|
-
dummyCustomTypesState,
|
|
238
|
-
createSliceZoneCreator({
|
|
239
|
-
tabId: initialTab.key,
|
|
240
|
-
}),
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
244
|
-
const newTabState = newState.model.tabs[0];
|
|
245
|
-
expect(newTabState.sliceZone).not.toEqual(null);
|
|
246
|
-
// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
|
|
247
|
-
expect(newTabState.sliceZone.value.length).toEqual(0);
|
|
248
|
-
// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
|
|
249
|
-
expect(newTabState.sliceZone.key).toEqual("slices");
|
|
250
|
-
});
|
|
251
|
-
it("should update the field id into a custom type given CUSTOM_TYPE/REPLACE_FIELD action", () => {
|
|
252
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
253
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
254
|
-
const field = initialTab.value[0];
|
|
255
|
-
|
|
256
|
-
const newState = selectedCustomTypeReducer(
|
|
257
|
-
dummyCustomTypesState,
|
|
258
|
-
replaceFieldCreator({
|
|
259
|
-
tabId: initialTab.key,
|
|
260
|
-
previousFieldId: field.key,
|
|
261
|
-
newFieldId: "newKey",
|
|
262
|
-
value: field.value,
|
|
263
|
-
}),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
267
|
-
expect(equal(newState.model.tabs[0].value, initialTab.value)).toEqual(
|
|
268
|
-
false,
|
|
269
|
-
);
|
|
270
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
271
|
-
expect(equal(newState.model.tabs[0].value[0].value, field.value)).toEqual(
|
|
272
|
-
true,
|
|
273
|
-
);
|
|
274
|
-
});
|
|
275
|
-
it("should not update the field into a custom type given CUSTOM_TYPE/REPLACE_FIELD action if the field is the same", () => {
|
|
276
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
277
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
278
|
-
const field = initialTab.value[0];
|
|
279
|
-
|
|
280
|
-
const newState = selectedCustomTypeReducer(
|
|
281
|
-
dummyCustomTypesState,
|
|
282
|
-
replaceFieldCreator({
|
|
283
|
-
tabId: initialTab.key,
|
|
284
|
-
previousFieldId: field.key,
|
|
285
|
-
newFieldId: field.key,
|
|
286
|
-
value: field.value,
|
|
287
|
-
}),
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
291
|
-
expect(equal(newState.model.tabs[0].value, initialTab.value)).toEqual(true);
|
|
292
|
-
});
|
|
293
|
-
it("should update the field content into a custom type given CUSTOM_TYPE/REPLACE_FIELD action", () => {
|
|
294
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
295
|
-
const initialTab = dummyCustomTypesState.model.tabs[0];
|
|
296
|
-
const field = initialTab.value[0];
|
|
297
|
-
// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
|
|
298
|
-
const newPlaceholder = `differ-from-${field.value.config.placeholder}`;
|
|
299
|
-
|
|
300
|
-
const newState = selectedCustomTypeReducer(
|
|
301
|
-
dummyCustomTypesState,
|
|
302
|
-
replaceFieldCreator({
|
|
303
|
-
tabId: initialTab.key,
|
|
304
|
-
previousFieldId: field.key,
|
|
305
|
-
newFieldId: field.key,
|
|
306
|
-
value: {
|
|
307
|
-
...field.value,
|
|
308
|
-
config: {
|
|
309
|
-
...field.value.config,
|
|
310
|
-
// @ts-expect-error TS(2322) FIXME: Type '{ placeholder: string; } | { placeholder: st... Remove this comment to see the full error message
|
|
311
|
-
placeholder: newPlaceholder,
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
}),
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
// @ts-expect-error TS(2531) FIXME: Object is possibly 'null'.
|
|
318
|
-
expect(newState.model.tabs[0].value[0].value.config.placeholder).toEqual(
|
|
319
|
-
newPlaceholder,
|
|
320
|
-
);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import { testSaga } from "redux-saga-test-plan";
|
|
3
|
-
import { Analytics } from "@segment/analytics-node";
|
|
4
|
-
|
|
5
|
-
import { saveCustomType } from "@src/apiClient";
|
|
6
|
-
import { saveCustomTypeSaga } from "@src/modules/selectedCustomType/sagas";
|
|
7
|
-
import { openToasterCreator, ToasterType } from "@src/modules/toaster";
|
|
8
|
-
import {
|
|
9
|
-
saveCustomTypeCreator,
|
|
10
|
-
selectCurrentCustomType,
|
|
11
|
-
} from "@src/modules/selectedCustomType";
|
|
12
|
-
import { CustomTypeSM } from "@lib/models/common/CustomType";
|
|
13
|
-
|
|
14
|
-
const customTypeModel: CustomTypeSM = {
|
|
15
|
-
id: "about",
|
|
16
|
-
label: "My Cool About Page",
|
|
17
|
-
repeatable: false,
|
|
18
|
-
status: true,
|
|
19
|
-
format: "custom",
|
|
20
|
-
tabs: [
|
|
21
|
-
{
|
|
22
|
-
key: "Main",
|
|
23
|
-
value: [
|
|
24
|
-
{
|
|
25
|
-
key: "title",
|
|
26
|
-
value: {
|
|
27
|
-
type: "StructuredText",
|
|
28
|
-
config: {
|
|
29
|
-
label: "",
|
|
30
|
-
placeholder: "",
|
|
31
|
-
allowTargetBlank: true,
|
|
32
|
-
single:
|
|
33
|
-
"paragraph,preformatted,heading1,heading2,heading3,heading4,heading5,heading6,strong,em,hyperlink,image,embed,list-item,o-list-item,rtl",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
sliceZone: {
|
|
39
|
-
key: "MainSliceZone",
|
|
40
|
-
value: [],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
describe("[Selected Custom type sagas]", () => {
|
|
47
|
-
describe("[saveCustomTypeSaga]", () => {
|
|
48
|
-
it("should call the api and dispatch the good actions on success", async () => {
|
|
49
|
-
const saga = testSaga(saveCustomTypeSaga);
|
|
50
|
-
|
|
51
|
-
saga.next().select(selectCurrentCustomType);
|
|
52
|
-
saga.next(customTypeModel).call(saveCustomType, customTypeModel);
|
|
53
|
-
|
|
54
|
-
saga
|
|
55
|
-
.next({ errors: [] })
|
|
56
|
-
.put(saveCustomTypeCreator.success({ customType: customTypeModel }));
|
|
57
|
-
|
|
58
|
-
saga
|
|
59
|
-
.next()
|
|
60
|
-
.inspect(
|
|
61
|
-
(action: {
|
|
62
|
-
payload: { action: { type: string; payload: { type: string } } };
|
|
63
|
-
}) => {
|
|
64
|
-
expect(action.payload.action.type).toBe("TOASTER/OPEN");
|
|
65
|
-
expect(action.payload.action.payload.type).toBe(
|
|
66
|
-
ToasterType.SUCCESS,
|
|
67
|
-
);
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
saga.next().isDone();
|
|
72
|
-
|
|
73
|
-
// Wait for network request to be performed
|
|
74
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
75
|
-
expect(Analytics.prototype.track).toHaveBeenCalledOnce();
|
|
76
|
-
});
|
|
77
|
-
it("should open a error toaster on internal error", () => {
|
|
78
|
-
const saga = testSaga(saveCustomTypeSaga).next();
|
|
79
|
-
|
|
80
|
-
saga.throw(new Error()).put(
|
|
81
|
-
openToasterCreator({
|
|
82
|
-
content: "Internal Error: Custom type not saved",
|
|
83
|
-
type: ToasterType.ERROR,
|
|
84
|
-
}),
|
|
85
|
-
);
|
|
86
|
-
saga.next().isDone();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from "vitest";
|
|
2
|
-
import jsonModel from "./__fixtures__/model.json";
|
|
3
|
-
import { isSelectedCustomTypeTouched } from "@src/modules/selectedCustomType";
|
|
4
|
-
import { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
5
|
-
import { CustomTypes } from "@lib/models/common/CustomType";
|
|
6
|
-
|
|
7
|
-
const model = CustomTypes.toSM(jsonModel as unknown as CustomType);
|
|
8
|
-
|
|
9
|
-
describe("[Selected Custom type selectors]", () => {
|
|
10
|
-
describe("[isSelectedCustomTypeTouched]", () => {
|
|
11
|
-
test("it computes correctly the state of the modifications 1/4", () => {
|
|
12
|
-
const customTypeStatus = isSelectedCustomTypeTouched({
|
|
13
|
-
selectedCustomType: {
|
|
14
|
-
model,
|
|
15
|
-
// @ts-expect-error TS(2322) FIXME: Type 'null' is not assignable to type '{ id: strin... Remove this comment to see the full error message
|
|
16
|
-
initialModel: null,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
expect(customTypeStatus).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
test("it computes correctly the state of the modifications 2/4", () => {
|
|
23
|
-
const customTypeStatus = isSelectedCustomTypeTouched({
|
|
24
|
-
// @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
|
|
25
|
-
selectedCustomType: {
|
|
26
|
-
model,
|
|
27
|
-
initialModel: model,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
expect(customTypeStatus).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
test("it computes correctly the state of the modifications 3/4", () => {
|
|
34
|
-
const customTypeStatus = isSelectedCustomTypeTouched({
|
|
35
|
-
// @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
|
|
36
|
-
selectedCustomType: {
|
|
37
|
-
model,
|
|
38
|
-
initialModel: { ...model, label: `differ-from-${model.label}` },
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
expect(customTypeStatus).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
test("it computes correctly the state of the modifications 4/4", () => {
|
|
44
|
-
const customTypeStatus = isSelectedCustomTypeTouched({
|
|
45
|
-
selectedCustomType: {
|
|
46
|
-
model,
|
|
47
|
-
// @ts-expect-error TS(2740) FIXME: Type '{}' is missing the following properties from... Remove this comment to see the full error message
|
|
48
|
-
initialModel: { ...model, tabs: {} },
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
expect(customTypeStatus).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|